代码拉取完成,页面将自动刷新
package cvm
import (
"time"
"gitee.com/vak80/cmdb/apps/machine"
resouce "gitee.com/vak80/cmdb/apps/resource"
"gitee.com/vak80/cmdb/utils"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
)
func NewCVMOperator(conn *cvm.Client) *CVMOperator {
return &CVMOperator{
client: conn,
log: zap.L().Named("CVM"),
}
}
type CVMOperator struct {
client *cvm.Client
log logger.Logger
}
func (o *CVMOperator) transferSet(items []*cvm.Instance) *machine.HostSet {
set := machine.NewHostSet()
for i := range items {
set.Add(o.transferOne(items[i]))
}
return set
}
func (o *CVMOperator) transferOne(ins *cvm.Instance) *machine.Host {
h := machine.NewDefaultHost()
h.Base.Vendor = resouce.Vendor_TENCENT
h.Base.Region = o.client.GetRegion()
h.Base.Zone = utils.PtrStrV(ins.Placement.Zone)
h.Base.CreateAt = o.parseTime(utils.PtrStrV(ins.CreatedTime))
h.Base.Id = utils.PtrStrV(ins.InstanceId)
h.Information.ExpireAt = o.parseTime(utils.PtrStrV(ins.ExpiredTime))
h.Information.Type = utils.PtrStrV(ins.InstanceType)
h.Information.Name = utils.PtrStrV(ins.InstanceName)
h.Information.Status = utils.PtrStrV(ins.InstanceState)
h.Information.Tags = transferTags(ins.Tags)
h.Information.PublicIp = utils.SlicePtrStrv(ins.PublicIpAddresses)
h.Information.PrivateIp = utils.SlicePtrStrv(ins.PrivateIpAddresses)
h.Information.PayType = utils.PtrStrV(ins.InstanceChargeType)
h.Describe.Cpu = utils.PtrInt64(ins.CPU)
h.Describe.Memory = utils.PtrInt64(ins.Memory)
h.Describe.OsName = utils.PtrStrV(ins.OsName)
h.Describe.ImageId = utils.PtrStrV(ins.ImageId)
if ins.InternetAccessible != nil {
h.Describe.InternetMaxBandwidthOut = utils.PtrInt64(ins.InternetAccessible.InternetMaxBandwidthOut)
}
h.Describe.KeyPairName = utils.SlicePtrStrv(ins.LoginSettings.KeyIds)
h.Describe.SecurityGroups = utils.SlicePtrStrv(ins.SecurityGroupIds)
return h
}
func (o *CVMOperator) parseTime(t string) int64 {
if t == "" {
return 0
}
ts, err := time.Parse("2006-01-02T15:04:05Z", t)
if err != nil {
o.log.Errorf("parse time error %s", t, err)
return 0
}
return ts.UnixNano()
}
func transferTags(tags []*cvm.Tag) (ret []*resouce.Tag) {
for _, i := range tags {
for _, j := range ret {
j.Key = utils.PtrStrV(i.Key)
j.Value = utils.PtrStrV(i.Value)
}
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。