Add the survival_time field
This commit is contained in:
parent
410dad4477
commit
0310562b31
|
@ -7,6 +7,7 @@ import (
|
||||||
"gitlink.org.cn/JointCloud/pcm-openstack/internal/common"
|
"gitlink.org.cn/JointCloud/pcm-openstack/internal/common"
|
||||||
"gitlink.org.cn/JointCloud/pcm-openstack/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-openstack/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-openstack/openstack"
|
"gitlink.org.cn/JointCloud/pcm-openstack/openstack"
|
||||||
|
"time"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -132,6 +133,7 @@ type ServersDetailed struct {
|
||||||
Id string `json:"Id"`
|
Id string `json:"Id"`
|
||||||
Name string `json:"Name"`
|
Name string `json:"Name"`
|
||||||
Key_name string `json:"Key_name"`
|
Key_name string `json:"Key_name"`
|
||||||
|
Survival_time int32 `json:"Survival_time"`
|
||||||
// 其他字段...
|
// 其他字段...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +161,7 @@ func (l *ListServersDetailedLogic) ListServersDetailed(in *openstack.ListServers
|
||||||
fmt.Println("错误结果1", "aaaaaaaaaaaa")
|
fmt.Println("错误结果1", "aaaaaaaaaaaa")
|
||||||
var newList []interface{}
|
var newList []interface{}
|
||||||
fmt.Println("错误结果2", "bbbbbbbbbb")
|
fmt.Println("错误结果2", "bbbbbbbbbb")
|
||||||
|
var days int32
|
||||||
for _, server := range response.Servers {
|
for _, server := range response.Servers {
|
||||||
fmt.Println("错误结果3", response.Servers)
|
fmt.Println("错误结果3", response.Servers)
|
||||||
if len(server.Addresses) > 0 {
|
if len(server.Addresses) > 0 {
|
||||||
|
@ -168,6 +171,36 @@ func (l *ListServersDetailedLogic) ListServersDetailed(in *openstack.ListServers
|
||||||
fmt.Println("错误结果5", addr.Addr)
|
fmt.Println("错误结果5", addr.Addr)
|
||||||
ip := addr.Addr
|
ip := addr.Addr
|
||||||
fmt.Println("addr:", addr.Addr)
|
fmt.Println("addr:", addr.Addr)
|
||||||
|
//computing time
|
||||||
|
now := time.Now()
|
||||||
|
// 获取当前时间的Unix时间戳(秒)
|
||||||
|
unixTimestampSeconds := now.Unix()
|
||||||
|
fmt.Println("Unix时间戳(秒):", unixTimestampSeconds)
|
||||||
|
|
||||||
|
// 解析ISO 8601格式的字符串为time.Time对象
|
||||||
|
t, err := time.Parse(time.RFC3339, server.Created)
|
||||||
|
if err != nil {
|
||||||
|
panic(err) // 如果解析出错,这里使用panic来演示,实际应用中应做适当的错误处理
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取Unix时间戳(秒)
|
||||||
|
unixTimestampSecondsCreated := t.Unix()
|
||||||
|
fmt.Println("Unix时间戳(秒):", unixTimestampSecondsCreated)
|
||||||
|
|
||||||
|
timestamp1 := int64(unixTimestampSecondsCreated)
|
||||||
|
timestamp2 := int64(unixTimestampSeconds)
|
||||||
|
|
||||||
|
// 将时间戳转换为time.Time对象
|
||||||
|
time1 := time.Unix(timestamp1, 0)
|
||||||
|
time2 := time.Unix(timestamp2, 0)
|
||||||
|
|
||||||
|
// 计算时间差
|
||||||
|
diff := time2.Sub(time1)
|
||||||
|
|
||||||
|
// 将时间差转换为天数
|
||||||
|
days := int(diff.Hours() / 24)
|
||||||
|
|
||||||
|
fmt.Println("相差天数:", days)
|
||||||
// 假设我们想要提取任务状态(task_state)和状态(status)
|
// 假设我们想要提取任务状态(task_state)和状态(status)
|
||||||
newList = append(newList, map[string]interface{}{
|
newList = append(newList, map[string]interface{}{
|
||||||
"OSTaskState": server.OSTaskState,
|
"OSTaskState": server.OSTaskState,
|
||||||
|
@ -183,6 +216,7 @@ func (l *ListServersDetailedLogic) ListServersDetailed(in *openstack.ListServers
|
||||||
"Id": server.Id,
|
"Id": server.Id,
|
||||||
"Name": server.Name,
|
"Name": server.Name,
|
||||||
"Key_name": server.Key_name,
|
"Key_name": server.Key_name,
|
||||||
|
"Survival_time": days,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,11 +232,12 @@ func (l *ListServersDetailedLogic) ListServersDetailed(in *openstack.ListServers
|
||||||
"Updated": server.Updated,
|
"Updated": server.Updated,
|
||||||
"HostId": server.HostId,
|
"HostId": server.HostId,
|
||||||
//"Ip": ip,
|
//"Ip": ip,
|
||||||
"Image": server.Image.Id,
|
"Image": server.Image.Id,
|
||||||
"Flavor": server.Flavor.Id,
|
"Flavor": server.Flavor.Id,
|
||||||
"Id": server.Id,
|
"Id": server.Id,
|
||||||
"Name": server.Name,
|
"Name": server.Name,
|
||||||
"Key_name": server.Key_name,
|
"Key_name": server.Key_name,
|
||||||
|
"Survival_time": days,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -127,6 +127,7 @@ message ListServersDetailedResp {
|
||||||
string Id =11;
|
string Id =11;
|
||||||
string Name =12;
|
string Name =12;
|
||||||
string Key_name =13;
|
string Key_name =13;
|
||||||
|
int32 Survival_time =14;
|
||||||
}
|
}
|
||||||
|
|
||||||
repeated ServersDetailed servers = 1; // @gotags: copier:"ServersDetailed"
|
repeated ServersDetailed servers = 1; // @gotags: copier:"ServersDetailed"
|
||||||
|
|
Loading…
Reference in New Issue