mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-28 19:45:07 +08:00
featue(host): structure guest description
Structure guest description and fix typo with json method. Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
@@ -91,6 +91,7 @@ type GuestnetworkJsonDesc struct {
|
||||
Masklen int8 `json:"masklen"`
|
||||
Driver string `json:"driver"`
|
||||
NumQueues int `json:"num_queues"`
|
||||
Vectors *int `json:"vectors"`
|
||||
Vlan int `json:"vlan"`
|
||||
Bw int `json:"bw"`
|
||||
Mtu int `json:"mtu"`
|
||||
@@ -106,6 +107,9 @@ type GuestnetworkJsonDesc struct {
|
||||
MappedIpAddr string `json:"mapped_ip_addr"`
|
||||
} `json:"vpc"`
|
||||
|
||||
UpscriptPath string `json:"upscript_path"`
|
||||
DownscriptPath string `json:"downscript_path"`
|
||||
|
||||
Networkaddresses jsonutils.JSONObject `json:"networkaddresses"`
|
||||
|
||||
Bridge string `json:"bridge"`
|
||||
|
||||
@@ -57,6 +57,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/compute/baremetal"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestfs"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestfs/sshpart"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -2878,16 +2879,21 @@ func (s *SBaremetalServer) deployFs(tool *disktool.SSHPartitionTool, term *ssh.C
|
||||
if strings.ToLower(rootfs.GetOs()) == "windows" {
|
||||
return nil, fmt.Errorf("Unsupported OS: %s", rootfs.GetOs())
|
||||
}
|
||||
desc, err := deployapi.GuestDescToDeployDesc(s.desc)
|
||||
guestDesc := new(desc.SGuestDesc)
|
||||
err = s.desc.Unmarshal(guestDesc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed unmarsh guest desc")
|
||||
}
|
||||
deployDesc := deployapi.GuestDescToDeployDesc(guestDesc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "To deploy desc fail")
|
||||
}
|
||||
desc, err = s.reIndexDescNics(term, desc)
|
||||
deployDesc, err = s.reIndexDescNics(term, deployDesc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reIndexDescNics")
|
||||
}
|
||||
|
||||
return guestfs.DeployGuestFs(rootfs, desc, deployInfo)
|
||||
return guestfs.DeployGuestFs(rootfs, deployDesc, deployInfo)
|
||||
}
|
||||
|
||||
func (s *SBaremetalServer) reIndexDescNics(term *ssh.Client, desc *deployapi.GuestDesc) (*deployapi.GuestDesc, error) {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package desc
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
)
|
||||
|
||||
type SGuestPorjectDesc struct {
|
||||
Tenant string
|
||||
TenantId string
|
||||
DomainId string
|
||||
ProjectDomain string
|
||||
}
|
||||
|
||||
type SGuestRegionDesc struct {
|
||||
Zone string
|
||||
Domain string
|
||||
HostId string
|
||||
Hostname string
|
||||
}
|
||||
|
||||
type SGuestControlDesc struct {
|
||||
IsDaemon bool
|
||||
IsMaster bool
|
||||
IsSlave bool
|
||||
|
||||
ScalingGroupId string
|
||||
EncryptKeyId string
|
||||
}
|
||||
|
||||
type SGuestHardwareDesc struct {
|
||||
Cpu int64
|
||||
Mem int64
|
||||
Machine string
|
||||
Bios string
|
||||
Vga string
|
||||
Vdi string
|
||||
BootOrder string
|
||||
|
||||
Cdrom *api.GuestcdromJsonDesc
|
||||
Disks []*api.GuestdiskJsonDesc
|
||||
Nics []*api.GuestnetworkJsonDesc
|
||||
NicsStandby []*api.GuestnetworkJsonDesc
|
||||
IsolatedDevices []*api.IsolatedDeviceJsonDesc
|
||||
}
|
||||
|
||||
type SGuestDesc struct {
|
||||
SGuestPorjectDesc
|
||||
SGuestRegionDesc
|
||||
SGuestControlDesc
|
||||
SGuestHardwareDesc
|
||||
|
||||
Name string
|
||||
Uuid string
|
||||
OsName string
|
||||
Pubkey string
|
||||
Keypair string
|
||||
Secgroup string
|
||||
Flavor string
|
||||
UserData string
|
||||
Metadata map[string]string
|
||||
ExtraOptions map[string]jsonutils.JSONObject
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package desc // import "yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
@@ -82,15 +82,15 @@ func (m *SGuestManager) GuestCreateFromEsxi(
|
||||
log.Infof("Connection disks %v", connections.String())
|
||||
|
||||
var ret = jsonutils.NewDict()
|
||||
disksDesc, _ := guest.Desc.GetArray("disks")
|
||||
disksDesc := guest.Desc.Disks
|
||||
for i := 0; i < len(disksDesc); i++ {
|
||||
storageId, _ := disksDesc[i].GetString("storage_id")
|
||||
storageId := disksDesc[i].StorageId
|
||||
if storage := storageman.GetManager().GetStorage(storageId); storage == nil {
|
||||
err = errors.Wrapf(err, "get storage %s", storageId)
|
||||
break
|
||||
} else {
|
||||
var diskInfo jsonutils.JSONObject
|
||||
diskId, _ := disksDesc[i].GetString("disk_id")
|
||||
diskId := disksDesc[i].DiskId
|
||||
iDisk := storage.CreateDisk(diskId)
|
||||
diskInfo, err = iDisk.CreateRaw(ctx, 0, "qcow2", "", nil, "", connections.Disks[i].DiskPath)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
hostapi "yunion.io/x/onecloud/pkg/apis/host"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -316,10 +317,12 @@ func guestDestPrepareMigrateInternal(ctx context.Context, userCred mcclient.Toke
|
||||
if !guestman.GetGuestManager().CanMigrate(sid) {
|
||||
return httperrors.NewBadRequestError("Guest exist")
|
||||
}
|
||||
desc, err := body.Get("desc")
|
||||
var guestDesc = new(desc.SGuestDesc)
|
||||
err := body.Unmarshal(guestDesc, "desc")
|
||||
if err != nil {
|
||||
return httperrors.NewMissingParameterError("desc")
|
||||
return httperrors.NewBadRequestError("Failed unmarshal guest desc %s", err)
|
||||
}
|
||||
|
||||
qemuVersion, err := body.GetString("qemu_version")
|
||||
if err != nil {
|
||||
return httperrors.NewMissingParameterError("qemu_version")
|
||||
@@ -335,7 +338,7 @@ func guestDestPrepareMigrateInternal(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
var params = &guestman.SDestPrepareMigrate{}
|
||||
params.Sid = sid
|
||||
params.Desc = desc
|
||||
params.Desc = guestDesc
|
||||
params.QemuVersion = qemuVersion
|
||||
params.LiveMigrate = liveMigrate
|
||||
params.SourceQemuCmdline = qemuCmdline
|
||||
@@ -382,13 +385,13 @@ func guestDestPrepareMigrateInternal(ctx context.Context, userCred mcclient.Toke
|
||||
} else {
|
||||
params.DisksBackingFile = disksBack
|
||||
}
|
||||
disks, err := desc.GetArray("disks")
|
||||
disks := guestDesc.Disks
|
||||
if err != nil {
|
||||
return httperrors.NewInputParameterError("Get desc disks error")
|
||||
} else {
|
||||
targetStorageIds := []string{}
|
||||
for i := 0; i < len(disks); i++ {
|
||||
targetStorageId, _ := disks[i].GetString("target_storage_id")
|
||||
targetStorageId := disks[i].TargetStorageId
|
||||
if len(targetStorageId) == 0 {
|
||||
return httperrors.NewMissingParameterError("target_storage_id")
|
||||
}
|
||||
@@ -468,15 +471,17 @@ func guestDriveMirror(ctx context.Context, userCred mcclient.TokenCredential, si
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("backup_nbd_server_uri")
|
||||
}
|
||||
desc, err := body.Get("desc")
|
||||
var guestDesc = new(desc.SGuestDesc)
|
||||
err = body.Unmarshal(guestDesc, "desc")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("desc")
|
||||
return nil, httperrors.NewInputParameterError("failed unmarshal desc %s", err)
|
||||
}
|
||||
|
||||
hostutils.DelayTaskWithoutReqctx(ctx, guestman.GetGuestManager().StartDriveMirror,
|
||||
&guestman.SDriverMirror{
|
||||
Sid: sid,
|
||||
NbdServerUri: backupNbdServerUri,
|
||||
Desc: desc,
|
||||
Desc: guestDesc,
|
||||
})
|
||||
return nil, nil
|
||||
}
|
||||
@@ -520,12 +525,10 @@ func guestReloadDiskSnapshot(ctx context.Context, userCred mcclient.TokenCredent
|
||||
}
|
||||
|
||||
var disk storageman.IDisk
|
||||
disks, _ := guest.Desc.GetArray("disks")
|
||||
disks := guest.Desc.Disks
|
||||
for _, d := range disks {
|
||||
id, _ := d.GetString("disk_id")
|
||||
if diskId == id {
|
||||
diskPath, _ := d.GetString("path")
|
||||
disk, _ = storageman.GetManager().GetDiskByPath(diskPath)
|
||||
if diskId == d.DiskId {
|
||||
disk, _ = storageman.GetManager().GetDiskByPath(d.Path)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -556,11 +559,10 @@ func guestSnapshot(ctx context.Context, userCred mcclient.TokenCredential, sid s
|
||||
log.Infof("guest info: %s", jsonutils.Marshal(guest))
|
||||
|
||||
var disk storageman.IDisk
|
||||
disks, _ := guest.Desc.GetArray("disks")
|
||||
disks := guest.Desc.Disks
|
||||
for _, d := range disks {
|
||||
id, _ := d.GetString("disk_id")
|
||||
if diskId == id {
|
||||
diskPath, _ := d.GetString("path")
|
||||
if diskId == d.DiskId {
|
||||
diskPath := d.Path
|
||||
disk, err = storageman.GetManager().GetDiskByPath(diskPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", diskPath)
|
||||
@@ -596,14 +598,12 @@ func guestDeleteSnapshot(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
}
|
||||
|
||||
var disk storageman.IDisk
|
||||
disks, _ := guest.Desc.GetArray("disks")
|
||||
disks := guest.Desc.Disks
|
||||
for _, d := range disks {
|
||||
id, _ := d.GetString("disk_id")
|
||||
if diskId == id {
|
||||
diskPath, _ := d.GetString("path")
|
||||
disk, err = storageman.GetManager().GetDiskByPath(diskPath)
|
||||
if diskId == d.DiskId {
|
||||
disk, err = storageman.GetManager().GetDiskByPath(d.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", diskPath)
|
||||
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", d.Path)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -98,13 +99,10 @@ func guestCreateFromLibvirt(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
return nil, err
|
||||
}
|
||||
|
||||
iGuestDesc, err := body.Get("desc")
|
||||
var guestDesc = new(desc.SGuestDesc)
|
||||
err = body.Unmarshal(guestDesc, "desc")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("desc")
|
||||
}
|
||||
guestDesc, ok := iGuestDesc.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, httperrors.NewInputParameterError("desc is not dict")
|
||||
return nil, httperrors.NewBadRequestError("Guest desc unmarshal failed %s", err)
|
||||
}
|
||||
|
||||
iDisksPath, err := body.Get("disks_path")
|
||||
@@ -137,13 +135,10 @@ func guestCreateFromEsxi(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
iGuestDesc, err := body.Get("desc")
|
||||
var guestDesc = new(desc.SGuestDesc)
|
||||
err = body.Unmarshal(guestDesc, "desc")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewMissingParameterError("desc")
|
||||
}
|
||||
guestDesc, ok := iGuestDesc.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return nil, httperrors.NewInputParameterError("desc is not dict")
|
||||
return nil, httperrors.NewBadRequestError("Guest desc unmarshal failed %s", err)
|
||||
}
|
||||
var disksAccessInfo = guestman.SEsxiAccessInfo{}
|
||||
err = body.Unmarshal(&disksAccessInfo, "esxi_access_info")
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
hostapi "yunion.io/x/onecloud/pkg/apis/host"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/esxi/vcenter"
|
||||
@@ -56,7 +57,7 @@ type SDestPrepareMigrate struct {
|
||||
LiveMigrate bool
|
||||
RebaseDisks bool
|
||||
|
||||
Desc jsonutils.JSONObject
|
||||
Desc *desc.SGuestDesc
|
||||
DisksBackingFile jsonutils.JSONObject
|
||||
SrcSnapshots jsonutils.JSONObject
|
||||
|
||||
@@ -77,7 +78,7 @@ type SLiveMigrate struct {
|
||||
type SDriverMirror struct {
|
||||
Sid string
|
||||
NbdServerUri string
|
||||
Desc jsonutils.JSONObject
|
||||
Desc *desc.SGuestDesc
|
||||
}
|
||||
|
||||
type SGuestHotplugCpuMem struct {
|
||||
@@ -140,7 +141,7 @@ type SLibvirtDomainImportConfig struct {
|
||||
type SGuestCreateFromLibvirt struct {
|
||||
Sid string
|
||||
MonitorPath string
|
||||
GuestDesc *jsonutils.JSONDict
|
||||
GuestDesc *desc.SGuestDesc
|
||||
DisksPath *jsonutils.JSONDict
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ type SGuestIoThrottle struct {
|
||||
|
||||
type SGuestCreateFromEsxi struct {
|
||||
Sid string
|
||||
GuestDesc *jsonutils.JSONDict
|
||||
GuestDesc *desc.SGuestDesc
|
||||
EsxiAccessInfo SEsxiAccessInfo
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,10 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
hostapi "yunion.io/x/onecloud/pkg/apis/host"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
fwd "yunion.io/x/onecloud/pkg/hostman/guestman/forwarder"
|
||||
fwdpb "yunion.io/x/onecloud/pkg/hostman/guestman/forwarder/api"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/types"
|
||||
@@ -322,10 +324,9 @@ func (m *SGuestManager) LoadServer(sid string) {
|
||||
return
|
||||
}
|
||||
|
||||
if jsonutils.QueryBoolean(guest.Desc, "need_sync_stream_disks", false) {
|
||||
if guest.NeedSyncStreamDisks {
|
||||
go guest.sendStreamDisksComplete(context.Background())
|
||||
}
|
||||
|
||||
m.CandidateServers[sid] = guest
|
||||
}
|
||||
|
||||
@@ -342,12 +343,14 @@ func (m *SGuestManager) ShutdownServers() {
|
||||
})
|
||||
}
|
||||
|
||||
func (m *SGuestManager) GetGuestNicDesc(mac, ip, port, bridge string, isCandidate bool) (jsonutils.JSONObject, jsonutils.JSONObject) {
|
||||
func (m *SGuestManager) GetGuestNicDesc(
|
||||
mac, ip, port, bridge string, isCandidate bool,
|
||||
) (*desc.SGuestDesc, *api.GuestnetworkJsonDesc) {
|
||||
if isCandidate {
|
||||
return m.getGuestNicDescInCandidate(mac, ip, port, bridge)
|
||||
}
|
||||
var nic jsonutils.JSONObject
|
||||
var guestDesc jsonutils.JSONObject
|
||||
var nic *api.GuestnetworkJsonDesc
|
||||
var guestDesc *desc.SGuestDesc
|
||||
m.Servers.Range(func(k interface{}, v interface{}) bool {
|
||||
guest := v.(*SKVMGuestInstance)
|
||||
if guest.IsLoaded() {
|
||||
@@ -362,7 +365,9 @@ func (m *SGuestManager) GetGuestNicDesc(mac, ip, port, bridge string, isCandidat
|
||||
return guestDesc, nic
|
||||
}
|
||||
|
||||
func (m *SGuestManager) getGuestNicDescInCandidate(mac, ip, port, bridge string) (jsonutils.JSONObject, jsonutils.JSONObject) {
|
||||
func (m *SGuestManager) getGuestNicDescInCandidate(
|
||||
mac, ip, port, bridge string,
|
||||
) (*desc.SGuestDesc, *api.GuestnetworkJsonDesc) {
|
||||
for _, guest := range m.CandidateServers {
|
||||
if guest.IsLoaded() {
|
||||
nic := guest.GetNicDescMatch(mac, ip, port, bridge)
|
||||
@@ -441,7 +446,7 @@ func (m *SGuestManager) OpenForward(ctx context.Context, sid string, req *hostap
|
||||
return nil, httperrors.NewBadRequestError("no vpc nic")
|
||||
}
|
||||
|
||||
netId, _ := nic.GetString("net_id")
|
||||
netId := nic.NetId
|
||||
if netId == "" {
|
||||
return nil, httperrors.NewBadRequestError("no network id")
|
||||
}
|
||||
@@ -449,7 +454,7 @@ func (m *SGuestManager) OpenForward(ctx context.Context, sid string, req *hostap
|
||||
if req.Addr != "" {
|
||||
ip = req.Addr
|
||||
} else {
|
||||
ip, _ := nic.GetString("ip")
|
||||
ip := nic.Ip
|
||||
if ip == "" {
|
||||
return nil, httperrors.NewBadRequestError("no vpc ip")
|
||||
}
|
||||
@@ -492,7 +497,7 @@ func (m *SGuestManager) CloseForward(ctx context.Context, sid string, req *hosta
|
||||
return nil, httperrors.NewBadRequestError("no vpc nic")
|
||||
}
|
||||
|
||||
netId, _ := nic.GetString("net_id")
|
||||
netId := nic.NetId
|
||||
if netId == "" {
|
||||
return nil, httperrors.NewBadRequestError("no network id")
|
||||
}
|
||||
@@ -533,7 +538,7 @@ func (m *SGuestManager) ListForward(ctx context.Context, sid string, req *hostap
|
||||
return nil, httperrors.NewBadRequestError("no vpc nic")
|
||||
}
|
||||
|
||||
netId, _ := nic.GetString("net_id")
|
||||
netId := nic.NetId
|
||||
if netId == "" {
|
||||
return nil, httperrors.NewBadRequestError("no network id")
|
||||
}
|
||||
@@ -576,16 +581,22 @@ func (m *SGuestManager) GuestCreate(ctx context.Context, params interface{}) (js
|
||||
}
|
||||
|
||||
var guest *SKVMGuestInstance
|
||||
err := func() error {
|
||||
e := func() error {
|
||||
m.ServersLock.Lock()
|
||||
defer m.ServersLock.Unlock()
|
||||
if _, ok := m.GetServer(deployParams.Sid); ok {
|
||||
return httperrors.NewBadRequestError("Guest %s exists", deployParams.Sid)
|
||||
}
|
||||
guest = NewKVMGuestInstance(deployParams.Sid, m)
|
||||
desc, _ := deployParams.Body.Get("desc")
|
||||
if desc != nil {
|
||||
err := guest.PrepareDir()
|
||||
|
||||
if deployParams.Body.Contains("desc") {
|
||||
var desc = new(desc.SGuestDesc)
|
||||
err := deployParams.Body.Unmarshal(desc, "desc")
|
||||
if err != nil {
|
||||
return httperrors.NewBadRequestError("Guest desc unmarshal failed %s", err)
|
||||
}
|
||||
|
||||
err = guest.PrepareDir()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "guest prepare dir")
|
||||
}
|
||||
@@ -594,11 +605,12 @@ func (m *SGuestManager) GuestCreate(ctx context.Context, params interface{}) (js
|
||||
return errors.Wrap(err, "save desc")
|
||||
}
|
||||
}
|
||||
|
||||
m.SaveServer(deployParams.Sid, guest)
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "prepare guest")
|
||||
if e != nil {
|
||||
return nil, errors.Wrap(e, "prepare guest")
|
||||
}
|
||||
return m.startDeploy(ctx, deployParams, guest)
|
||||
}
|
||||
@@ -639,9 +651,13 @@ func (m *SGuestManager) GuestDeploy(ctx context.Context, params interface{}) (js
|
||||
|
||||
guest, ok := m.GetServer(deployParams.Sid)
|
||||
if ok {
|
||||
desc, _ := deployParams.Body.Get("desc")
|
||||
if desc != nil {
|
||||
guest.SaveDesc(desc)
|
||||
if deployParams.Body.Contains("desc") {
|
||||
var guestDesc = new(desc.SGuestDesc)
|
||||
err := deployParams.Body.Unmarshal(guestDesc, "desc")
|
||||
if err != nil {
|
||||
return nil, httperrors.NewBadRequestError("Failed unmarshal guest desc %s", err)
|
||||
}
|
||||
guest.SaveDesc(guestDesc)
|
||||
}
|
||||
return m.startDeploy(ctx, deployParams, guest)
|
||||
} else {
|
||||
@@ -725,8 +741,9 @@ func (m *SGuestManager) Delete(sid string) (*SKVMGuestInstance, error) {
|
||||
|
||||
func (m *SGuestManager) GuestStart(ctx context.Context, userCred mcclient.TokenCredential, sid string, body jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if guest, ok := m.GetServer(sid); ok {
|
||||
if desc, err := body.Get("desc"); err == nil {
|
||||
guest.SaveDesc(desc)
|
||||
guestDesc := new(desc.SGuestDesc)
|
||||
if err := body.Unmarshal(guestDesc, "desc"); err == nil {
|
||||
guest.SaveDesc(guestDesc)
|
||||
}
|
||||
if guest.IsStopped() {
|
||||
data := struct {
|
||||
@@ -771,9 +788,13 @@ func (m *SGuestManager) GuestSync(ctx context.Context, params interface{}) (json
|
||||
}
|
||||
guest, _ := m.GetServer(syncParams.Sid)
|
||||
if syncParams.Body.Contains("desc") {
|
||||
desc, _ := syncParams.Body.Get("desc")
|
||||
guestDesc := new(desc.SGuestDesc)
|
||||
if err := syncParams.Body.Unmarshal(guestDesc, "desc"); err != nil {
|
||||
return nil, errors.Wrap(err, "unmarshal guest desc")
|
||||
}
|
||||
|
||||
fwOnly := jsonutils.QueryBoolean(syncParams.Body, "fw_only", false)
|
||||
return guest.SyncConfig(ctx, desc, fwOnly)
|
||||
return guest.SyncConfig(ctx, guestDesc, fwOnly)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -836,7 +857,7 @@ func (m *SGuestManager) DestPrepareMigrate(ctx context.Context, params interface
|
||||
return nil, err
|
||||
}
|
||||
|
||||
disks, _ := migParams.Desc.GetArray("disks")
|
||||
disks := migParams.Desc.Disks
|
||||
if len(migParams.TargetStorageIds) > 0 {
|
||||
var encInfo *apis.SEncryptInfo
|
||||
if guest.isEncrypted() {
|
||||
@@ -1199,7 +1220,7 @@ func (m *SGuestManager) GetHost() hostutils.IHost {
|
||||
}
|
||||
|
||||
func (m *SGuestManager) RequestVerifyDirtyServer(s *SKVMGuestInstance) {
|
||||
hostId, _ := s.Desc.GetString("host_id")
|
||||
hostId := s.Desc.HostId
|
||||
var body = jsonutils.NewDict()
|
||||
body.Set("guest_id", jsonutils.NewString(s.Id))
|
||||
body.Set("host_id", jsonutils.NewString(hostId))
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
hostapi "yunion.io/x/onecloud/pkg/apis/host"
|
||||
"yunion.io/x/onecloud/pkg/appctx"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/qemu"
|
||||
@@ -216,15 +217,15 @@ func (t *SGuestSyncConfigTaskExecutor) runNextTaskCallback(err ...error) {
|
||||
|
||||
type SGuestDiskSyncTask struct {
|
||||
guest *SKVMGuestInstance
|
||||
delDisks []jsonutils.JSONObject
|
||||
addDisks []jsonutils.JSONObject
|
||||
delDisks []*api.GuestdiskJsonDesc
|
||||
addDisks []*api.GuestdiskJsonDesc
|
||||
cdrom *string
|
||||
|
||||
callback func(...error)
|
||||
checkeDrivers []string
|
||||
}
|
||||
|
||||
func NewGuestDiskSyncTask(guest *SKVMGuestInstance, delDisks, addDisks []jsonutils.JSONObject, cdrom *string) *SGuestDiskSyncTask {
|
||||
func NewGuestDiskSyncTask(guest *SKVMGuestInstance, delDisks, addDisks []*api.GuestdiskJsonDesc, cdrom *string) *SGuestDiskSyncTask {
|
||||
return &SGuestDiskSyncTask{guest, delDisks, addDisks, cdrom, nil, nil}
|
||||
}
|
||||
|
||||
@@ -288,9 +289,8 @@ func (d *SGuestDiskSyncTask) OnChangeCdromContentSucc(results string) {
|
||||
d.syncDisksConf()
|
||||
}
|
||||
|
||||
func (d *SGuestDiskSyncTask) removeDisk(disk jsonutils.JSONObject) {
|
||||
index, _ := disk.Int("index")
|
||||
devId := fmt.Sprintf("drive_%d", index)
|
||||
func (d *SGuestDiskSyncTask) removeDisk(disk *api.GuestdiskJsonDesc) {
|
||||
devId := fmt.Sprintf("drive_%d", disk.Index)
|
||||
d.guest.Monitor.DriveDel(devId,
|
||||
func(results string) { d.onRemoveDriveSucc(devId, results) })
|
||||
}
|
||||
@@ -303,13 +303,12 @@ func (d *SGuestDiskSyncTask) onRemoveDiskSucc(results string) {
|
||||
d.syncDisksConf()
|
||||
}
|
||||
|
||||
func (d *SGuestDiskSyncTask) checkDiskDriver(disk jsonutils.JSONObject) {
|
||||
func (d *SGuestDiskSyncTask) checkDiskDriver(disk *api.GuestdiskJsonDesc) {
|
||||
if d.checkeDrivers == nil {
|
||||
d.checkeDrivers = make([]string, 0)
|
||||
}
|
||||
driver, _ := disk.GetString("driver")
|
||||
log.Debugf("sync disk driver: %s", driver)
|
||||
if driver == DISK_DRIVER_SCSI {
|
||||
log.Debugf("sync disk driver: %s", disk.Driver)
|
||||
if disk.Driver == DISK_DRIVER_SCSI {
|
||||
if utils.IsInStringArray(DISK_DRIVER_SCSI, d.checkeDrivers) {
|
||||
d.startAddDisk(disk)
|
||||
} else {
|
||||
@@ -321,7 +320,7 @@ func (d *SGuestDiskSyncTask) checkDiskDriver(disk jsonutils.JSONObject) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SGuestDiskSyncTask) checkScsiDriver(ret string, disk jsonutils.JSONObject) {
|
||||
func (d *SGuestDiskSyncTask) checkScsiDriver(ret string, disk *api.GuestdiskJsonDesc) {
|
||||
if strings.Contains(ret, "SCSI controller") {
|
||||
d.checkeDrivers = append(d.checkeDrivers, DISK_DRIVER_SCSI)
|
||||
d.startAddDisk(disk)
|
||||
@@ -335,23 +334,22 @@ func (d *SGuestDiskSyncTask) checkScsiDriver(ret string, disk jsonutils.JSONObje
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SGuestDiskSyncTask) addDisk(disk jsonutils.JSONObject) {
|
||||
func (d *SGuestDiskSyncTask) addDisk(disk *api.GuestdiskJsonDesc) {
|
||||
d.checkDiskDriver(disk)
|
||||
}
|
||||
|
||||
func (d *SGuestDiskSyncTask) startAddDisk(disk jsonutils.JSONObject) {
|
||||
diskPath, _ := disk.GetString("path")
|
||||
iDisk, _ := storageman.GetManager().GetDiskByPath(diskPath)
|
||||
func (d *SGuestDiskSyncTask) startAddDisk(disk *api.GuestdiskJsonDesc) {
|
||||
iDisk, _ := storageman.GetManager().GetDiskByPath(disk.Path)
|
||||
if iDisk == nil {
|
||||
d.syncDisksConf()
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
diskIndex, _ = disk.Int("index")
|
||||
aio, _ = disk.GetString("aio_mode")
|
||||
diskDirver, _ = disk.GetString("driver")
|
||||
cacheMode, _ = disk.GetString("cache_mode")
|
||||
diskIndex = disk.Index
|
||||
aio = disk.AioMode
|
||||
diskDirver = disk.Driver
|
||||
cacheMode = disk.CacheMode
|
||||
)
|
||||
|
||||
var params = map[string]string{
|
||||
@@ -384,11 +382,11 @@ func (d *SGuestDiskSyncTask) startAddDisk(disk jsonutils.JSONObject) {
|
||||
d.guest.Monitor.DriveAdd(bus, params, func(result string) { d.onAddDiskSucc(disk, result) })
|
||||
}
|
||||
|
||||
func (d *SGuestDiskSyncTask) onAddDiskSucc(disk jsonutils.JSONObject, results string) {
|
||||
func (d *SGuestDiskSyncTask) onAddDiskSucc(disk *api.GuestdiskJsonDesc, results string) {
|
||||
var (
|
||||
diskIndex, _ = disk.Int("index")
|
||||
diskDirver, _ = disk.GetString("driver")
|
||||
dev = qemu.GetDiskDeviceModel(diskDirver)
|
||||
diskIndex = disk.Index
|
||||
diskDirver = disk.Driver
|
||||
dev = qemu.GetDiskDeviceModel(diskDirver)
|
||||
)
|
||||
|
||||
var params = map[string]interface{}{
|
||||
@@ -414,8 +412,8 @@ func (d *SGuestDiskSyncTask) onAddDeviceSucc(results string) {
|
||||
|
||||
type SGuestNetworkSyncTask struct {
|
||||
guest *SKVMGuestInstance
|
||||
delNics []jsonutils.JSONObject
|
||||
addNics []jsonutils.JSONObject
|
||||
delNics []*api.GuestnetworkJsonDesc
|
||||
addNics []*api.GuestnetworkJsonDesc
|
||||
errors []error
|
||||
|
||||
callback func(...error)
|
||||
@@ -440,8 +438,7 @@ func (n *SGuestNetworkSyncTask) syncNetworkConf() {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) removeNic(nic jsonutils.JSONObject) {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
func (n *SGuestNetworkSyncTask) removeNic(nic *api.GuestnetworkJsonDesc) {
|
||||
callback := func(res string) {
|
||||
if len(res) > 0 && !strings.Contains(res, "not found") {
|
||||
log.Errorf("netdev del failed %s", res)
|
||||
@@ -451,10 +448,10 @@ func (n *SGuestNetworkSyncTask) removeNic(nic jsonutils.JSONObject) {
|
||||
n.onNetdevDel(nic)
|
||||
}
|
||||
}
|
||||
n.guest.Monitor.NetdevDel(ifname, callback)
|
||||
n.guest.Monitor.NetdevDel(nic.Ifname, callback)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) onNetdevDel(nic jsonutils.JSONObject) {
|
||||
func (n *SGuestNetworkSyncTask) onNetdevDel(nic *api.GuestnetworkJsonDesc) {
|
||||
downScript := n.guest.getNicDownScriptPath(nic)
|
||||
output, err := procutils.NewCommand("sh", downScript).Output()
|
||||
if err != nil {
|
||||
@@ -464,7 +461,7 @@ func (n *SGuestNetworkSyncTask) onNetdevDel(nic jsonutils.JSONObject) {
|
||||
n.delNicDevice(nic)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) delNicDevice(nic jsonutils.JSONObject) {
|
||||
func (n *SGuestNetworkSyncTask) delNicDevice(nic *api.GuestnetworkJsonDesc) {
|
||||
callback := func(res string) {
|
||||
if len(res) > 0 {
|
||||
log.Errorf("network device del failed %s", res)
|
||||
@@ -473,11 +470,10 @@ func (n *SGuestNetworkSyncTask) delNicDevice(nic jsonutils.JSONObject) {
|
||||
n.syncNetworkConf()
|
||||
}
|
||||
}
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
n.guest.Monitor.DeviceDel(fmt.Sprintf("netdev-%s", ifname), callback)
|
||||
n.guest.Monitor.DeviceDel(fmt.Sprintf("netdev-%s", nic.Ifname), callback)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) addNic(nic jsonutils.JSONObject) {
|
||||
func (n *SGuestNetworkSyncTask) addNic(nic *api.GuestnetworkJsonDesc) {
|
||||
if err := n.guest.generateNicScripts(nic); err != nil {
|
||||
log.Errorln(err)
|
||||
n.errors = append(n.errors, err)
|
||||
@@ -486,9 +482,8 @@ func (n *SGuestNetworkSyncTask) addNic(nic jsonutils.JSONObject) {
|
||||
}
|
||||
upscript := n.guest.getNicUpScriptPath(nic)
|
||||
downscript := n.guest.getNicDownScriptPath(nic)
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
params := map[string]string{
|
||||
"ifname": ifname, "script": upscript, "downscript": downscript,
|
||||
"ifname": nic.Ifname, "script": upscript, "downscript": downscript,
|
||||
"vhost": "on", "vhostforce": "off",
|
||||
}
|
||||
netType := "tap"
|
||||
@@ -503,21 +498,17 @@ func (n *SGuestNetworkSyncTask) addNic(nic jsonutils.JSONObject) {
|
||||
}
|
||||
}
|
||||
|
||||
n.guest.Monitor.NetdevAdd(ifname, netType, params, callback)
|
||||
n.guest.Monitor.NetdevAdd(nic.Ifname, netType, params, callback)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) onNetdevAdd(nic jsonutils.JSONObject) {
|
||||
index, _ := nic.Int("index")
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
mac, _ := nic.GetString("mac")
|
||||
driver, _ := nic.GetString("driver")
|
||||
dev := n.guest.getNicDeviceModel(driver)
|
||||
addr := n.guest.getNicAddr(int(index))
|
||||
func (n *SGuestNetworkSyncTask) onNetdevAdd(nic *api.GuestnetworkJsonDesc) {
|
||||
dev := n.guest.getNicDeviceModel(nic.Driver)
|
||||
addr := n.guest.getNicAddr(int(nic.Index))
|
||||
params := map[string]interface{}{
|
||||
"id": fmt.Sprintf("netdev-%s", ifname),
|
||||
"netdev": ifname,
|
||||
"id": fmt.Sprintf("netdev-%s", nic.Ifname),
|
||||
"netdev": nic.Ifname,
|
||||
"addr": fmt.Sprintf("0x%x", addr),
|
||||
"mac": mac,
|
||||
"mac": nic.Mac,
|
||||
"bus": "pci.0",
|
||||
}
|
||||
callback := func(res string) {
|
||||
@@ -532,11 +523,13 @@ func (n *SGuestNetworkSyncTask) onNetdevAdd(nic jsonutils.JSONObject) {
|
||||
n.guest.Monitor.DeviceAdd(dev, params, callback)
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) onDeviceAdd(nic jsonutils.JSONObject) {
|
||||
func (n *SGuestNetworkSyncTask) onDeviceAdd(nic *api.GuestnetworkJsonDesc) {
|
||||
n.syncNetworkConf()
|
||||
}
|
||||
|
||||
func NewGuestNetworkSyncTask(guest *SKVMGuestInstance, delNics, addNics []jsonutils.JSONObject) *SGuestNetworkSyncTask {
|
||||
func NewGuestNetworkSyncTask(
|
||||
guest *SKVMGuestInstance, delNics, addNics []*api.GuestnetworkJsonDesc,
|
||||
) *SGuestNetworkSyncTask {
|
||||
return &SGuestNetworkSyncTask{guest, delNics, addNics, make([]error, 0), nil}
|
||||
}
|
||||
|
||||
@@ -546,14 +539,14 @@ func NewGuestNetworkSyncTask(guest *SKVMGuestInstance, delNics, addNics []jsonut
|
||||
|
||||
type SGuestIsolatedDeviceSyncTask struct {
|
||||
guest *SKVMGuestInstance
|
||||
delDevs []jsonutils.JSONObject
|
||||
addDevs []jsonutils.JSONObject
|
||||
delDevs []*api.IsolatedDeviceJsonDesc
|
||||
addDevs []*api.IsolatedDeviceJsonDesc
|
||||
errors []error
|
||||
|
||||
callback func(...error)
|
||||
}
|
||||
|
||||
func NewGuestIsolatedDeviceSyncTask(guest *SKVMGuestInstance, delDevs, addDevs []jsonutils.JSONObject) *SGuestIsolatedDeviceSyncTask {
|
||||
func NewGuestIsolatedDeviceSyncTask(guest *SKVMGuestInstance, delDevs, addDevs []*api.IsolatedDeviceJsonDesc) *SGuestIsolatedDeviceSyncTask {
|
||||
return &SGuestIsolatedDeviceSyncTask{guest, delDevs, addDevs, make([]error, 0), nil}
|
||||
}
|
||||
|
||||
@@ -576,7 +569,7 @@ func (t *SGuestIsolatedDeviceSyncTask) syncDevice() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *SGuestIsolatedDeviceSyncTask) removeDevice(dev jsonutils.JSONObject) {
|
||||
func (t *SGuestIsolatedDeviceSyncTask) removeDevice(dev *api.IsolatedDeviceJsonDesc) {
|
||||
cb := func(res string) {
|
||||
if len(res) > 0 {
|
||||
t.errors = append(t.errors, fmt.Errorf("device del failed: %s", res))
|
||||
@@ -584,20 +577,9 @@ func (t *SGuestIsolatedDeviceSyncTask) removeDevice(dev jsonutils.JSONObject) {
|
||||
t.syncDevice()
|
||||
}
|
||||
|
||||
vendorDevId, err := dev.GetString("vendor_device_id")
|
||||
if err != nil {
|
||||
cb(err.Error())
|
||||
return
|
||||
}
|
||||
addr, err := dev.GetString("addr")
|
||||
if err != nil {
|
||||
cb(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
devObj := hostinfo.Instance().IsolatedDeviceMan.GetDeviceByIdent(vendorDevId, addr)
|
||||
devObj := hostinfo.Instance().IsolatedDeviceMan.GetDeviceByIdent(dev.VendorDeviceId, dev.Addr)
|
||||
if devObj == nil {
|
||||
cb(fmt.Sprintf("Not found host isolated_device by %s %s", vendorDevId, addr))
|
||||
cb(fmt.Sprintf("Not found host isolated_device by %s %s", dev.VendorDeviceId, dev.Addr))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -610,7 +592,7 @@ func (t *SGuestIsolatedDeviceSyncTask) removeDevice(dev jsonutils.JSONObject) {
|
||||
t.delDeviceCallBack(opts, 0, cb)
|
||||
}
|
||||
|
||||
func (t *SGuestIsolatedDeviceSyncTask) addDevice(dev jsonutils.JSONObject) {
|
||||
func (t *SGuestIsolatedDeviceSyncTask) addDevice(dev *api.IsolatedDeviceJsonDesc) {
|
||||
cb := func(res string) {
|
||||
if len(res) > 0 {
|
||||
t.errors = append(t.errors, fmt.Errorf("device add failed: %s", res))
|
||||
@@ -618,20 +600,9 @@ func (t *SGuestIsolatedDeviceSyncTask) addDevice(dev jsonutils.JSONObject) {
|
||||
t.syncDevice()
|
||||
}
|
||||
|
||||
vendorDevId, err := dev.GetString("vendor_device_id")
|
||||
if err != nil {
|
||||
cb(err.Error())
|
||||
return
|
||||
}
|
||||
addr, err := dev.GetString("addr")
|
||||
if err != nil {
|
||||
cb(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
devObj := hostinfo.Instance().IsolatedDeviceMan.GetDeviceByIdent(vendorDevId, addr)
|
||||
devObj := hostinfo.Instance().IsolatedDeviceMan.GetDeviceByIdent(dev.VendorDeviceId, dev.Addr)
|
||||
if devObj == nil {
|
||||
cb(fmt.Sprintf("Not found host isolated_device by %s %s", vendorDevId, addr))
|
||||
cb(fmt.Sprintf("Not found host isolated_device by %s %s", dev.VendorDeviceId, dev.Addr))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -698,7 +669,7 @@ func NewGuestLiveMigrateTask(
|
||||
ctx context.Context, guest *SKVMGuestInstance, params *SLiveMigrate,
|
||||
) *SGuestLiveMigrateTask {
|
||||
task := &SGuestLiveMigrateTask{SKVMGuestInstance: guest, ctx: ctx, params: params}
|
||||
task.migrateTask = task
|
||||
task.MigrateTask = task
|
||||
return task
|
||||
}
|
||||
|
||||
@@ -720,7 +691,7 @@ func (s *SGuestLiveMigrateTask) startRamMigrateTimeout() {
|
||||
// timeout has been set
|
||||
return
|
||||
}
|
||||
memMb, _ := s.Desc.Int("mem")
|
||||
memMb := s.Desc.Mem
|
||||
migSeconds := int(memMb) / options.HostOptions.MigrateExpectRate
|
||||
if migSeconds < options.HostOptions.MinMigrateTimeoutSeconds {
|
||||
migSeconds = options.HostOptions.MinMigrateTimeoutSeconds
|
||||
@@ -837,7 +808,7 @@ func (s *SGuestLiveMigrateTask) onMigrateStartPostcopy(res string) {
|
||||
}
|
||||
|
||||
func (s *SGuestLiveMigrateTask) migrateComplete() {
|
||||
s.migrateTask = nil
|
||||
s.MigrateTask = nil
|
||||
if s.c != nil {
|
||||
close(s.c)
|
||||
s.c = nil
|
||||
@@ -849,7 +820,7 @@ func (s *SGuestLiveMigrateTask) migrateComplete() {
|
||||
|
||||
func (s *SGuestLiveMigrateTask) migrateFailed(msg string) {
|
||||
cleanup := func() {
|
||||
s.migrateTask = nil
|
||||
s.MigrateTask = nil
|
||||
if s.c != nil {
|
||||
close(s.c)
|
||||
s.c = nil
|
||||
@@ -954,7 +925,7 @@ func (s *SGuestResumeTask) onConfirmRunning(status string) {
|
||||
} else if status == "postmigrate" {
|
||||
s.resumeGuest()
|
||||
} else {
|
||||
memMb, _ := s.Desc.Int("mem")
|
||||
memMb := s.Desc.Mem
|
||||
migSeconds := int(memMb) / options.HostOptions.MigrateExpectRate
|
||||
if migSeconds < options.HostOptions.MinMigrateTimeoutSeconds {
|
||||
migSeconds = options.HostOptions.MinMigrateTimeoutSeconds
|
||||
@@ -1519,8 +1490,7 @@ func (s *SDriveMirrorTask) startMirror(res string) {
|
||||
blockReplication = true
|
||||
log.Infof("mirror block replication supported")
|
||||
}
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
if s.index < len(disks) {
|
||||
if s.index < len(s.Desc.Disks) {
|
||||
target := fmt.Sprintf("%s:exportname=drive_%d", s.nbdUri, s.index)
|
||||
s.Monitor.DriveMirror(s.startMirror, fmt.Sprintf("drive_%d", s.index),
|
||||
target, s.syncMode, "", true, blockReplication)
|
||||
@@ -1876,10 +1846,9 @@ func NewGuestStorageCloneDiskTask(ctx context.Context, guest *SKVMGuestInstance,
|
||||
|
||||
func (t *SGuestStorageCloneDiskTask) Start(guestRunning bool) {
|
||||
var diskIndex = -1
|
||||
disks, _ := t.Desc.GetArray("disks")
|
||||
disks := t.Desc.Disks
|
||||
for diskIndex = 0; diskIndex < len(disks); diskIndex++ {
|
||||
diskId, _ := disks[diskIndex].GetString("disk_id")
|
||||
if diskId == t.params.SourceDisk.GetId() {
|
||||
if disks[diskIndex].DiskId == t.params.SourceDisk.GetId() {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -1954,10 +1923,9 @@ func NewGuestLiveChangeDiskTask(ctx context.Context, guest *SKVMGuestInstance, p
|
||||
}
|
||||
|
||||
var diskIndex = -1
|
||||
disks, _ := guest.Desc.GetArray("disks")
|
||||
disks := guest.Desc.Disks
|
||||
for diskIndex = 0; diskIndex < len(disks); diskIndex++ {
|
||||
diskId, _ := disks[diskIndex].GetString("disk_id")
|
||||
if diskId == params.SourceDisk.GetId() {
|
||||
if disks[diskIndex].DiskId == params.SourceDisk.GetId() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,34 +45,29 @@ func (m *SGuestManager) GuestCreateFromLibvirt(
|
||||
if !ok {
|
||||
return nil, hostutils.ParamsError
|
||||
}
|
||||
disks, err := createConfig.GuestDesc.GetArray("disks")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
disks := createConfig.GuestDesc.Disks
|
||||
|
||||
disksPath := jsonutils.NewDict()
|
||||
for _, disk := range disks {
|
||||
diskId, _ := disk.GetString("disk_id")
|
||||
diskPath, err := createConfig.DisksPath.GetString(diskId)
|
||||
diskPath, err := createConfig.DisksPath.GetString(disk.DiskId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Disks path missing disk %s", diskId)
|
||||
return nil, fmt.Errorf("Disks path missing disk %s", disk.DiskId)
|
||||
}
|
||||
storageId, _ := disk.GetString("storage_id")
|
||||
storage := storageman.GetManager().GetStorage(storageId)
|
||||
storage := storageman.GetManager().GetStorage(disk.StorageId)
|
||||
if storage == nil {
|
||||
return nil, fmt.Errorf("Host has no stroage %s", storageId)
|
||||
return nil, fmt.Errorf("Host has no stroage %s", disk.StorageId)
|
||||
}
|
||||
iDisk := storage.CreateDisk(diskId)
|
||||
iDisk := storage.CreateDisk(disk.DiskId)
|
||||
|
||||
// use symbol link replace mv, more security
|
||||
output, err := procutils.NewCommand("ln", "-s", diskPath, iDisk.GetPath()).Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Symbol link disk from %s to %s error %s", diskPath, iDisk.GetPath(), output)
|
||||
}
|
||||
disksPath.Set(diskId, jsonutils.NewString(iDisk.GetPath()))
|
||||
disksPath.Set(disk.DiskId, jsonutils.NewString(iDisk.GetPath()))
|
||||
}
|
||||
guest, _ := m.GetServer(createConfig.Sid)
|
||||
if err = guest.SaveDesc(createConfig.GuestDesc); err != nil {
|
||||
if err := guest.SaveDesc(createConfig.GuestDesc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
+219
-261
@@ -40,6 +40,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/appctx"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostinfo"
|
||||
@@ -73,30 +74,42 @@ const (
|
||||
MAX_TRY = 3
|
||||
)
|
||||
|
||||
type SKVMGuestInstance struct {
|
||||
Id string
|
||||
|
||||
// TODO: add struct cgroup info
|
||||
cgroupPid int
|
||||
cgroupName string
|
||||
type SKVMInstanceRuntime struct {
|
||||
QemuVersion string
|
||||
VncPassword string
|
||||
|
||||
Desc *jsonutils.JSONDict
|
||||
Monitor monitor.Monitor
|
||||
manager *SGuestManager
|
||||
startupTask *SGuestResumeTask
|
||||
migrateTask *SGuestLiveMigrateTask
|
||||
stopping bool
|
||||
syncMeta *jsonutils.JSONDict
|
||||
blockJobTigger map[string]chan struct{}
|
||||
LiveMigrateDestPort *int
|
||||
LiveMigrateUseTls bool
|
||||
|
||||
SyncMeta *jsonutils.JSONDict
|
||||
|
||||
cgroupPid int
|
||||
cgroupName string
|
||||
|
||||
stopping bool
|
||||
NeedSyncStreamDisks bool
|
||||
blockJobTigger map[string]chan struct{}
|
||||
|
||||
StartupTask *SGuestResumeTask
|
||||
MigrateTask *SGuestLiveMigrateTask
|
||||
}
|
||||
|
||||
type SKVMGuestInstance struct {
|
||||
SKVMInstanceRuntime
|
||||
|
||||
Id string
|
||||
Desc *desc.SGuestDesc
|
||||
Monitor monitor.Monitor
|
||||
manager *SGuestManager
|
||||
}
|
||||
|
||||
func NewKVMGuestInstance(id string, manager *SGuestManager) *SKVMGuestInstance {
|
||||
return &SKVMGuestInstance{
|
||||
Id: id,
|
||||
manager: manager,
|
||||
blockJobTigger: make(map[string]chan struct{}),
|
||||
SKVMInstanceRuntime: SKVMInstanceRuntime{
|
||||
blockJobTigger: make(map[string]chan struct{}),
|
||||
},
|
||||
Id: id,
|
||||
manager: manager,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,21 +118,15 @@ func (s *SKVMGuestInstance) IsStopping() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) IsValid() bool {
|
||||
if s.Desc != nil && s.Desc.Contains("uuid") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return s.Desc != nil && s.Desc.Uuid != ""
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetId() string {
|
||||
id, _ := s.Desc.GetString("uuid")
|
||||
return id
|
||||
return s.Desc.Uuid
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetName() string {
|
||||
id, _ := s.Desc.GetString("uuid")
|
||||
name, _ := s.Desc.GetString("name")
|
||||
return fmt.Sprintf("%s(%s)", name, id)
|
||||
return fmt.Sprintf("%s(%s)", s.Desc.Name, s.Desc.Uuid)
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getStateFilePathRootPrefix() string {
|
||||
@@ -167,8 +174,7 @@ func (s *SKVMGuestInstance) getEncryptKeyPath() string {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getEncryptKeyId() string {
|
||||
encKeyId, _ := s.Desc.GetString("encrypt_key_id")
|
||||
return encKeyId
|
||||
return s.Desc.EncryptKeyId
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) isEncrypted() bool {
|
||||
@@ -177,7 +183,7 @@ func (s *SKVMGuestInstance) isEncrypted() bool {
|
||||
|
||||
func (s *SKVMGuestInstance) getEncryptKey(ctx context.Context, userCred mcclient.TokenCredential) (apis.SEncryptInfo, error) {
|
||||
ret := apis.SEncryptInfo{}
|
||||
encKeyId, _ := s.Desc.GetString("encrypt_key_id")
|
||||
encKeyId := s.getEncryptKeyId()
|
||||
if len(encKeyId) > 0 {
|
||||
if userCred == nil {
|
||||
return ret, errors.Wrap(httperrors.ErrUnauthorized, "no credential to fetch encrypt key")
|
||||
@@ -201,15 +207,11 @@ func (s *SKVMGuestInstance) saveEncryptKeyFile(key string) error {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getOriginId() string {
|
||||
originId, _ := s.Desc.GetString("metadata", "__origin_id")
|
||||
if len(originId) == 0 {
|
||||
originId = s.Id
|
||||
}
|
||||
return originId
|
||||
return s.Desc.Metadata["__origin_id"]
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) isImportFromLibvirt() bool {
|
||||
return s.Desc.Contains("metadata", "__origin_id")
|
||||
return s.getOriginId() != ""
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetPid() int {
|
||||
@@ -288,15 +290,17 @@ func (s *SKVMGuestInstance) LoadDesc() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
desc, err := jsonutils.Parse(descStr)
|
||||
|
||||
guestDesc := new(desc.SGuestDesc)
|
||||
descJson, err := jsonutils.Parse(descStr)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "json parse")
|
||||
}
|
||||
dDesc, ok := desc.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return fmt.Errorf("Load and parse desc error")
|
||||
err = descJson.Unmarshal(guestDesc)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unmarshal desc")
|
||||
}
|
||||
s.Desc = dDesc
|
||||
s.Desc = guestDesc
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -305,14 +309,13 @@ func (s *SKVMGuestInstance) IsDirtyShotdown() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) IsDaemon() bool {
|
||||
return jsonutils.QueryBoolean(s.Desc, "is_daemon", false)
|
||||
return s.Desc.IsDaemon
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) DirtyServerRequestStart() {
|
||||
hostId, _ := s.Desc.GetString("host_id")
|
||||
var body = jsonutils.NewDict()
|
||||
body.Set("guest_id", jsonutils.NewString(s.Id))
|
||||
body.Set("host_id", jsonutils.NewString(hostId))
|
||||
body.Set("host_id", jsonutils.NewString(s.Desc.HostId))
|
||||
_, err := modules.Servers.PerformClassAction(
|
||||
hostutils.GetComputeSession(context.Background()), "dirty-server-start", body)
|
||||
if err != nil {
|
||||
@@ -363,7 +366,7 @@ func (s *SKVMGuestInstance) asyncScriptStart(ctx context.Context, params interfa
|
||||
// is on_async_script_start
|
||||
if isStarted {
|
||||
log.Infof("Async start server %s success!", s.GetName())
|
||||
s.syncMeta = s.CleanImportMetadata()
|
||||
s.SyncMeta = s.CleanImportMetadata()
|
||||
s.StartMonitor(ctx, nil)
|
||||
return nil, nil
|
||||
}
|
||||
@@ -419,10 +422,9 @@ func (s *SKVMGuestInstance) GetStopScriptPath() string {
|
||||
|
||||
func (s *SKVMGuestInstance) ImportServer(pendingDelete bool) {
|
||||
// verify host_id consistency
|
||||
hostId, _ := s.Desc.GetString("host_id")
|
||||
if hostId != hostinfo.Instance().HostId {
|
||||
if s.Desc.HostId != hostinfo.Instance().HostId {
|
||||
// fix host_id
|
||||
s.Desc.Set("host_id", jsonutils.NewString(hostinfo.Instance().HostId))
|
||||
s.Desc.HostId = hostinfo.Instance().HostId
|
||||
s.SaveDesc(s.Desc)
|
||||
}
|
||||
|
||||
@@ -430,9 +432,8 @@ func (s *SKVMGuestInstance) ImportServer(pendingDelete bool) {
|
||||
s.manager.RemoveCandidateServer(s)
|
||||
|
||||
if (s.IsDirtyShotdown() || s.IsDaemon()) && !pendingDelete {
|
||||
log.Infof("Server dirty shotdown or a daemon %s", s.GetName())
|
||||
if jsonutils.QueryBoolean(s.Desc, "is_master", false) ||
|
||||
jsonutils.QueryBoolean(s.Desc, "is_slave", false) {
|
||||
log.Infof("Server dirty shutdown or a daemon %s", s.GetName())
|
||||
if s.Desc.IsMaster || s.Desc.IsSlave {
|
||||
go s.DirtyServerRequestStart()
|
||||
} else {
|
||||
s.StartGuest(context.Background(), nil, jsonutils.NewDict())
|
||||
@@ -528,8 +529,7 @@ func (s *SKVMGuestInstance) onImportGuestMonitorConnected(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetMonitorPath() string {
|
||||
monitorPath, _ := s.Desc.GetString("metadata", "__monitor_path")
|
||||
return monitorPath
|
||||
return s.Desc.Metadata["__monitor_path"]
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) StartMonitorWithImportGuestSocketFile(ctx context.Context, socketFile string, cb func()) {
|
||||
@@ -613,9 +613,9 @@ func (s *SKVMGuestInstance) onReceiveQMPEvent(event *monitor.Event) {
|
||||
case event.Event == `"GUEST_PANICKED"`:
|
||||
s.eventGuestPaniced(event)
|
||||
case event.Event == `"STOP"`:
|
||||
if s.migrateTask != nil {
|
||||
if s.MigrateTask != nil {
|
||||
// migrating complete
|
||||
s.migrateTask.migrateComplete()
|
||||
s.MigrateTask.migrateComplete()
|
||||
}
|
||||
hostutils.UpdateServerProgress(context.Background(), s.Id, 0.0, 0)
|
||||
}
|
||||
@@ -641,14 +641,14 @@ func (s *SKVMGuestInstance) eventBlockJobCompleted(event *monitor.Event) {
|
||||
if !strings.HasPrefix(device, "drive_") {
|
||||
return
|
||||
}
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
log.Infof("mirror job complete disk index %s", device[len("drive_"):])
|
||||
diskIndex, err := strconv.Atoi(device[len("drive_"):])
|
||||
if err != nil || diskIndex < 0 || diskIndex >= len(disks) {
|
||||
log.Errorf("failed get disk from index %d", diskIndex)
|
||||
return
|
||||
}
|
||||
diskId, _ := disks[diskIndex].GetString("disk_id")
|
||||
diskId := disks[diskIndex].DiskId
|
||||
if c, ok := s.blockJobTigger[diskId]; ok {
|
||||
c <- struct{}{}
|
||||
}
|
||||
@@ -704,16 +704,15 @@ func (s *SKVMGuestInstance) eventBlockJobReady(event *monitor.Event) {
|
||||
if !strings.HasPrefix(device, "drive_") {
|
||||
return
|
||||
}
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
log.Infof("mirror job ready disk index %s", device[len("drive_"):])
|
||||
diskIndex, err := strconv.Atoi(device[len("drive_"):])
|
||||
if err != nil || diskIndex < 0 || diskIndex >= len(disks) {
|
||||
log.Errorf("failed get disk from index %d", diskIndex)
|
||||
return
|
||||
}
|
||||
diskId, _ := disks[diskIndex].GetString("disk_id")
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("disk_id", jsonutils.NewString(diskId))
|
||||
params.Set("disk_id", jsonutils.NewString(disks[diskIndex].DiskId))
|
||||
_, err = modules.Servers.PerformAction(
|
||||
hostutils.GetComputeSession(context.Background()),
|
||||
s.GetId(), "block-mirror-ready", params,
|
||||
@@ -775,11 +774,10 @@ func (s *SKVMGuestInstance) setDestMigrateTLS(ctx context.Context, data *jsonuti
|
||||
func (s *SKVMGuestInstance) onGetQemuVersion(ctx context.Context, version string) {
|
||||
s.QemuVersion = version
|
||||
log.Infof("Guest(%s) qemu version %s", s.Id, s.QemuVersion)
|
||||
if s.Desc.Contains("live_migrate_dest_port") && ctx != nil {
|
||||
migratePort, _ := s.Desc.Get("live_migrate_dest_port")
|
||||
if s.LiveMigrateDestPort != nil && ctx != nil {
|
||||
body := jsonutils.NewDict()
|
||||
body.Set("live_migrate_dest_port", migratePort)
|
||||
if jsonutils.QueryBoolean(s.Desc, "live_migrate_use_tls", false) {
|
||||
body.Set("live_migrate_dest_port", jsonutils.NewInt(int64(*s.LiveMigrateDestPort)))
|
||||
if s.LiveMigrateUseTls {
|
||||
s.setDestMigrateTLS(ctx, body)
|
||||
} else {
|
||||
hostutils.TaskComplete(ctx, body)
|
||||
@@ -805,7 +803,7 @@ func (s *SKVMGuestInstance) onMonitorDisConnect(err error) {
|
||||
log.Errorf("Guest %s on Monitor Disconnect reason: %v", s.Id, err)
|
||||
s.CleanStartupTask()
|
||||
s.scriptStop()
|
||||
if !jsonutils.QueryBoolean(s.Desc, "is_slave", false) {
|
||||
if !s.IsSlave() {
|
||||
s.SyncStatus(fmt.Sprintf("monitor disconnect %v", err))
|
||||
}
|
||||
s.clearCgroup(0)
|
||||
@@ -824,11 +822,10 @@ func (s *SKVMGuestInstance) startDiskBackupMirror(ctx context.Context) {
|
||||
}
|
||||
hostutils.UpdateServerStatus(context.Background(), s.GetId(), status, "")
|
||||
} else {
|
||||
metadata, _ := s.Desc.Get("metadata")
|
||||
if metadata == nil || !metadata.Contains("backup_nbd_server_uri") {
|
||||
nbdUri, ok := s.Desc.Metadata["backup_nbd_server_uri"]
|
||||
if !ok {
|
||||
hostutils.TaskFailed(ctx, "Missing dest nbd location")
|
||||
}
|
||||
nbdUri, _ := metadata.GetString("backup_nbd_server_uri")
|
||||
|
||||
onSucc := func() {
|
||||
cb := func(res string) { log.Infof("On backup mirror server(%s) resume start", s.Id) }
|
||||
@@ -867,16 +864,15 @@ func (s *SKVMGuestInstance) clearCgroup(pid int) {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) IsMaster() bool {
|
||||
return jsonutils.QueryBoolean(s.Desc, "is_master", false)
|
||||
return s.Desc.IsMaster
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) IsSlave() bool {
|
||||
return jsonutils.QueryBoolean(s.Desc, "is_slave", false)
|
||||
return s.Desc.IsSlave
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) DiskCount() int {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
return len(disks)
|
||||
return len(s.Desc.Disks)
|
||||
}
|
||||
|
||||
type MirrorJob int
|
||||
@@ -936,14 +932,14 @@ func (s *SKVMGuestInstance) BlockJobsCount() int {
|
||||
|
||||
func (s *SKVMGuestInstance) detachStartupTask() {
|
||||
log.Infof("[%s] detachStartupTask", s.GetId())
|
||||
s.startupTask = nil
|
||||
s.StartupTask = nil
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) CleanStartupTask() {
|
||||
if s.startupTask != nil {
|
||||
if s.StartupTask != nil {
|
||||
log.Infof("[%s] Clean startup task ... stop task ...", s.GetId())
|
||||
s.startupTask.Stop()
|
||||
s.startupTask = nil
|
||||
s.StartupTask.Stop()
|
||||
s.StartupTask = nil
|
||||
} else {
|
||||
log.Infof("[%s] Clean startup task ... no task", s.GetId())
|
||||
}
|
||||
@@ -1000,8 +996,8 @@ func (s *SKVMGuestInstance) saveVncPort(port int) error {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) DoResumeTask(ctx context.Context, isTimeout bool) {
|
||||
s.startupTask = NewGuestResumeTask(ctx, s, isTimeout, false)
|
||||
s.startupTask.Start()
|
||||
s.StartupTask = NewGuestResumeTask(ctx, s, isTimeout, false)
|
||||
s.StartupTask.Start()
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) SyncStatus(reason string) {
|
||||
@@ -1039,34 +1035,29 @@ func (s *SKVMGuestInstance) CheckBlockOrRunning(jobs int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) SaveDesc(desc jsonutils.JSONObject) error {
|
||||
var ok bool
|
||||
s.Desc, ok = desc.(*jsonutils.JSONDict)
|
||||
if !ok {
|
||||
return fmt.Errorf("Unknown desc format, not JSONDict")
|
||||
}
|
||||
{
|
||||
// fill in ovn vpc nic bridge field
|
||||
nics, _ := s.Desc.GetArray("nics")
|
||||
for _, nic := range nics {
|
||||
if !nic.Contains("bridge") {
|
||||
nicjd := nic.(*jsonutils.JSONDict)
|
||||
nicjd.Set("bridge", jsonutils.NewString(getNicBridge(nic)))
|
||||
}
|
||||
func (s *SKVMGuestInstance) SaveDesc(desc *desc.SGuestDesc) error {
|
||||
s.Desc = desc
|
||||
|
||||
// fill in ovn vpc nic bridge field
|
||||
for _, nic := range s.Desc.Nics {
|
||||
if nic.Bridge == "" {
|
||||
nic.Bridge = getNicBridge(nic)
|
||||
}
|
||||
}
|
||||
if err := fileutils2.FilePutContents(s.GetDescFilePath(), desc.String(), false); err != nil {
|
||||
log.Errorln(err)
|
||||
|
||||
if err := fileutils2.FilePutContents(
|
||||
s.GetDescFilePath(), jsonutils.Marshal(s.Desc).String(), false,
|
||||
); err != nil {
|
||||
log.Errorf("save desc failed %s", err)
|
||||
return errors.Wrap(err, "save desc")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetVpcNIC() jsonutils.JSONObject {
|
||||
nics, _ := s.Desc.GetArray("nics")
|
||||
for _, nic := range nics {
|
||||
vpcProvider, _ := nic.GetString("vpc", "provider")
|
||||
if vpcProvider == api.VPC_PROVIDER_OVN {
|
||||
if ip, _ := nic.GetString("ip"); ip != "" {
|
||||
func (s *SKVMGuestInstance) GetVpcNIC() *api.GuestnetworkJsonDesc {
|
||||
for _, nic := range s.Desc.Nics {
|
||||
if nic.Vpc.Provider == api.VPC_PROVIDER_OVN {
|
||||
if nic.Ip != "" {
|
||||
return nic
|
||||
}
|
||||
}
|
||||
@@ -1130,9 +1121,9 @@ func (s *SKVMGuestInstance) DeployFs(ctx context.Context, userCred mcclient.Toke
|
||||
diskInfo.EncryptPassword = ekey.Key
|
||||
diskInfo.EncryptAlg = string(ekey.Alg)
|
||||
}
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
if len(disks) > 0 {
|
||||
diskPath, _ := disks[0].GetString("path")
|
||||
diskPath := disks[0].Path
|
||||
disk, err := storageman.GetManager().GetDiskByPath(diskPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", diskPath)
|
||||
@@ -1209,10 +1200,10 @@ func (s *SKVMGuestInstance) GetCleanFiles() []string {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) delTmpDisks(ctx context.Context, migrated bool) error {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
for _, disk := range disks {
|
||||
if disk.Contains("path") {
|
||||
diskPath, _ := disk.GetString("path")
|
||||
if disk.Path != "" {
|
||||
diskPath := disk.Path
|
||||
d, _ := storageman.GetManager().GetDiskByPath(diskPath)
|
||||
if d != nil && d.GetType() == api.STORAGE_LOCAL && migrated {
|
||||
skipRecycle := true
|
||||
@@ -1238,13 +1229,12 @@ func (s *SKVMGuestInstance) delTmpDisks(ctx context.Context, migrated bool) erro
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) delFlatFiles(ctx context.Context) error {
|
||||
if eid, _ := s.Desc.GetString("metadata", "__server_convert_from_esxi"); len(eid) > 0 {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
if eid, ok := s.Desc.Metadata["__server_convert_from_esxi"]; ok && len(eid) > 0 {
|
||||
disks := s.Desc.Disks
|
||||
connections := new(deployapi.EsxiDisksConnectionInfo)
|
||||
connections.Disks = make([]*deployapi.EsxiDiskInfo, len(disks))
|
||||
for i := 0; i < len(disks); i++ {
|
||||
fpath, _ := disks[i].GetString("esxi_flat_file_path")
|
||||
connections.Disks[i] = &deployapi.EsxiDiskInfo{DiskPath: fpath}
|
||||
connections.Disks[i] = &deployapi.EsxiDiskInfo{DiskPath: disks[i].EsxiFlatFilePath}
|
||||
}
|
||||
_, err := deployclient.GetDeployClient().DisconnectEsxiDisks(ctx, connections)
|
||||
if err != nil {
|
||||
@@ -1321,58 +1311,51 @@ func (s *SKVMGuestInstance) ExecSuspendTask(ctx context.Context) {
|
||||
NewGuestSuspendTask(s, ctx, nil).Start()
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetNicDescMatch(mac, ip, port, bridge string) jsonutils.JSONObject {
|
||||
nics, _ := s.Desc.GetArray("nics")
|
||||
func (s *SKVMGuestInstance) GetNicDescMatch(mac, ip, port, bridge string) *api.GuestnetworkJsonDesc {
|
||||
nics := s.Desc.Nics
|
||||
for _, nic := range nics {
|
||||
nicBridge, _ := nic.GetString("bridge")
|
||||
if bridge == "" && nicBridge != "" && nicBridge == options.HostOptions.OvnIntegrationBridge {
|
||||
if bridge == "" && nic.Bridge != "" && nic.Bridge == options.HostOptions.OvnIntegrationBridge {
|
||||
continue
|
||||
}
|
||||
nicMac, _ := nic.GetString("mac")
|
||||
nicIp, _ := nic.GetString("ip")
|
||||
nicPort, _ := nic.GetString("ifname")
|
||||
if (len(mac) == 0 || netutils2.MacEqual(nicMac, mac)) &&
|
||||
(len(ip) == 0 || nicIp == ip) &&
|
||||
(len(port) == 0 || nicPort == port) &&
|
||||
(len(bridge) == 0 || nicBridge == bridge) {
|
||||
if (len(mac) == 0 || netutils2.MacEqual(nic.Mac, mac)) &&
|
||||
(len(ip) == 0 || nic.Ip == ip) &&
|
||||
(len(port) == 0 || nic.Ifname == port) &&
|
||||
(len(bridge) == 0 || nic.Bridge == bridge) {
|
||||
return nic
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func pathEqual(disk, ndisk jsonutils.JSONObject) bool {
|
||||
if disk.Contains("path") && ndisk.Contains("path") {
|
||||
path1, _ := disk.GetString("path")
|
||||
path2, _ := ndisk.GetString("path")
|
||||
return path1 == path2
|
||||
} else if disk.Contains("url") && ndisk.Contains("url") {
|
||||
path1, _ := disk.GetString("assumed_path")
|
||||
path2, _ := ndisk.GetString("assumed_path")
|
||||
return path1 == path2
|
||||
func pathEqual(disk, ndisk *api.GuestdiskJsonDesc) bool {
|
||||
if disk.Path != "" && ndisk.Path != "" {
|
||||
return disk.Path == ndisk.Path
|
||||
} else if disk.Url != "" && ndisk.Url != "" {
|
||||
//path1 := disk.AssumedPath
|
||||
//path2 := ndisk.AssumedPath
|
||||
//return path1 == path2
|
||||
// not assumed path found
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) compareDescDisks(newDesc jsonutils.JSONObject) ([]jsonutils.JSONObject, []jsonutils.JSONObject) {
|
||||
var delDisks, addDisks = []jsonutils.JSONObject{}, []jsonutils.JSONObject{}
|
||||
newDisks, _ := newDesc.GetArray("disks")
|
||||
func (s *SKVMGuestInstance) compareDescDisks(newDesc *desc.SGuestDesc) ([]*api.GuestdiskJsonDesc, []*api.GuestdiskJsonDesc) {
|
||||
var delDisks, addDisks = make([]*api.GuestdiskJsonDesc, 0), make([]*api.GuestdiskJsonDesc, 0)
|
||||
newDisks := newDesc.Disks
|
||||
for _, disk := range newDisks {
|
||||
driver, _ := disk.GetString("driver")
|
||||
if utils.IsInStringArray(driver, []string{"virtio", "scsi"}) {
|
||||
if utils.IsInStringArray(disk.Driver, []string{"virtio", "scsi"}) {
|
||||
addDisks = append(addDisks, disk)
|
||||
}
|
||||
}
|
||||
oldDisks, _ := s.Desc.GetArray("disks")
|
||||
oldDisks := s.Desc.Disks
|
||||
for _, disk := range oldDisks {
|
||||
driver, _ := disk.GetString("driver")
|
||||
if utils.IsInStringArray(driver, []string{"virtio", "scsi"}) {
|
||||
if utils.IsInStringArray(disk.Driver, []string{"virtio", "scsi"}) {
|
||||
var find = false
|
||||
for idx, ndisk := range addDisks {
|
||||
diskIndex, _ := disk.Int("index")
|
||||
nDiskIndex, _ := ndisk.Int("index")
|
||||
diskIndex := disk.Index
|
||||
nDiskIndex := ndisk.Index
|
||||
if diskIndex == nDiskIndex && pathEqual(disk, ndisk) {
|
||||
addDisks = append(addDisks[:idx], addDisks[idx+1:]...)
|
||||
find = true
|
||||
@@ -1387,18 +1370,19 @@ func (s *SKVMGuestInstance) compareDescDisks(newDesc jsonutils.JSONObject) ([]js
|
||||
return delDisks, addDisks
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) compareDescIsolatedDevices(newDesc jsonutils.JSONObject) ([]jsonutils.JSONObject, []jsonutils.JSONObject) {
|
||||
var delDevs, addDevs = []jsonutils.JSONObject{}, []jsonutils.JSONObject{}
|
||||
newDevs, _ := newDesc.GetArray("isolated_devices")
|
||||
func (s *SKVMGuestInstance) compareDescIsolatedDevices(newDesc *desc.SGuestDesc,
|
||||
) ([]*api.IsolatedDeviceJsonDesc, []*api.IsolatedDeviceJsonDesc) {
|
||||
var delDevs, addDevs = []*api.IsolatedDeviceJsonDesc{}, []*api.IsolatedDeviceJsonDesc{}
|
||||
newDevs := newDesc.IsolatedDevices
|
||||
for _, dev := range newDevs {
|
||||
addDevs = append(addDevs, dev)
|
||||
}
|
||||
oldDevs, _ := s.Desc.GetArray("isolated_devices")
|
||||
oldDevs := s.Desc.IsolatedDevices
|
||||
for _, oldDev := range oldDevs {
|
||||
var find = false
|
||||
oVendorDevId, _ := oldDev.GetString("vendor_device_id")
|
||||
oVendorDevId := oldDev.VendorDeviceId
|
||||
for idx, addDev := range addDevs {
|
||||
nVendorDevId, _ := addDev.GetString("vendor_device_id")
|
||||
nVendorDevId := addDev.VendorDeviceId
|
||||
if oVendorDevId == nVendorDevId {
|
||||
addDevs = append(addDevs[:idx], addDevs[idx+1:]...)
|
||||
find = true
|
||||
@@ -1412,60 +1396,53 @@ func (s *SKVMGuestInstance) compareDescIsolatedDevices(newDesc jsonutils.JSONObj
|
||||
return delDevs, addDevs
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) compareDescCdrom(newDesc jsonutils.JSONObject) *string {
|
||||
if !s.Desc.Contains("cdrom") && !newDesc.Contains("cdrom") {
|
||||
func (s *SKVMGuestInstance) compareDescCdrom(newDesc *desc.SGuestDesc) *string {
|
||||
if s.Desc.Cdrom == nil && newDesc.Cdrom == nil {
|
||||
return nil
|
||||
} else if !s.Desc.Contains("cdrom") && newDesc.Contains("cdrom") {
|
||||
cdrom, _ := newDesc.GetString("cdrom", "path")
|
||||
return &cdrom
|
||||
} else if s.Desc.Contains("cdrom") && !newDesc.Contains("cdrom") {
|
||||
} else if s.Desc.Cdrom == nil && newDesc.Cdrom != nil {
|
||||
return &newDesc.Cdrom.Path
|
||||
} else if s.Desc.Cdrom != nil && newDesc.Cdrom == nil {
|
||||
var res = ""
|
||||
return &res
|
||||
} else {
|
||||
cdrom, _ := s.Desc.GetString("cdrom", "path")
|
||||
ncdrom, _ := newDesc.GetString("cdrom", "path")
|
||||
if cdrom == ncdrom {
|
||||
if s.Desc.Cdrom.Path == newDesc.Cdrom.Path {
|
||||
return nil
|
||||
} else {
|
||||
return &ncdrom
|
||||
return &newDesc.Cdrom.Path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) compareDescNetworks(newDesc jsonutils.JSONObject) ([]jsonutils.JSONObject, []jsonutils.JSONObject, [][]jsonutils.JSONObject) {
|
||||
var isValid = func(net jsonutils.JSONObject) bool {
|
||||
driver, _ := net.GetString("driver")
|
||||
return driver == "virtio"
|
||||
func (s *SKVMGuestInstance) compareDescNetworks(newDesc *desc.SGuestDesc,
|
||||
) ([]*api.GuestnetworkJsonDesc, []*api.GuestnetworkJsonDesc, [][2]*api.GuestnetworkJsonDesc) {
|
||||
var isValid = func(net *api.GuestnetworkJsonDesc) bool {
|
||||
return net.Driver == "virtio"
|
||||
}
|
||||
|
||||
var findNet = func(nets []jsonutils.JSONObject, net jsonutils.JSONObject) int {
|
||||
mac1, _ := net.GetString("mac")
|
||||
var findNet = func(nets []*api.GuestnetworkJsonDesc, net *api.GuestnetworkJsonDesc) int {
|
||||
for i := 0; i < len(nets); i++ {
|
||||
mac2, _ := nets[i].GetString("mac")
|
||||
if mac1 == mac2 {
|
||||
if nets[i].Mac == net.Mac {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
var delNics, addNics = []jsonutils.JSONObject{}, []jsonutils.JSONObject{}
|
||||
var changedNics = [][]jsonutils.JSONObject{}
|
||||
nics, _ := newDesc.GetArray("nics")
|
||||
for _, n := range nics {
|
||||
var delNics, addNics = []*api.GuestnetworkJsonDesc{}, []*api.GuestnetworkJsonDesc{}
|
||||
var changedNics = [][2]*api.GuestnetworkJsonDesc{}
|
||||
for _, n := range newDesc.Nics {
|
||||
if isValid(n) {
|
||||
// assume all nics in new desc are new
|
||||
addNics = append(addNics, n)
|
||||
}
|
||||
}
|
||||
|
||||
nics, _ = s.Desc.GetArray("nics")
|
||||
for _, n := range nics {
|
||||
for _, n := range s.Desc.Nics {
|
||||
if isValid(n) {
|
||||
idx := findNet(addNics, n)
|
||||
if idx >= 0 {
|
||||
// check if bridge changed
|
||||
changedNics = append(changedNics, []jsonutils.JSONObject{
|
||||
changedNics = append(changedNics, [2]*api.GuestnetworkJsonDesc{
|
||||
n, // old
|
||||
addNics[idx], // new
|
||||
})
|
||||
@@ -1480,27 +1457,24 @@ func (s *SKVMGuestInstance) compareDescNetworks(newDesc jsonutils.JSONObject) ([
|
||||
return delNics, addNics, changedNics
|
||||
}
|
||||
|
||||
func getNicBridge(nic jsonutils.JSONObject) string {
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
if len(bridge) == 0 {
|
||||
vpcProvider, _ := nic.GetString("vpc", "provider")
|
||||
if vpcProvider == api.VPC_PROVIDER_OVN {
|
||||
bridge = options.HostOptions.OvnIntegrationBridge
|
||||
}
|
||||
} else if bridge == api.HostTapBridge {
|
||||
bridge = options.HostOptions.TapBridgeName
|
||||
} else if bridge == api.HostVpcBridge {
|
||||
bridge = options.HostOptions.OvnIntegrationBridge
|
||||
func getNicBridge(nic *api.GuestnetworkJsonDesc) string {
|
||||
if nic.Bridge == "" && nic.Vpc.Provider == api.VPC_PROVIDER_OVN {
|
||||
return options.HostOptions.OvnIntegrationBridge
|
||||
} else if nic.Bridge == api.HostTapBridge {
|
||||
return options.HostOptions.TapBridgeName
|
||||
} else if nic.Bridge == api.HostVpcBridge {
|
||||
return options.HostOptions.OvnIntegrationBridge
|
||||
} else {
|
||||
return nic.Bridge
|
||||
}
|
||||
return bridge
|
||||
}
|
||||
|
||||
func onNicChange(oldNic, newNic jsonutils.JSONObject) error {
|
||||
func onNicChange(oldNic, newNic *api.GuestnetworkJsonDesc) error {
|
||||
oldbr := getNicBridge(oldNic)
|
||||
oldifname, _ := oldNic.GetString("ifname")
|
||||
oldifname := oldNic.Ifname
|
||||
newbr := getNicBridge(newNic)
|
||||
newifname, _ := newNic.GetString("ifname")
|
||||
newvlan, _ := newNic.Int("vlan")
|
||||
newifname := newNic.Ifname
|
||||
newvlan := newNic.Vlan
|
||||
if oldbr != newbr {
|
||||
// bridge changed
|
||||
if oldifname == newifname {
|
||||
@@ -1545,9 +1519,13 @@ func onNicChange(oldNic, newNic jsonutils.JSONObject) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) SyncConfig(ctx context.Context, desc jsonutils.JSONObject, fwOnly bool) (jsonutils.JSONObject, error) {
|
||||
var delDisks, addDisks, delNetworks, addNetworks, delDevs, addDevs []jsonutils.JSONObject
|
||||
var changedNetworks [][]jsonutils.JSONObject
|
||||
func (s *SKVMGuestInstance) SyncConfig(
|
||||
ctx context.Context, desc *desc.SGuestDesc, fwOnly bool,
|
||||
) (jsonutils.JSONObject, error) {
|
||||
var delDisks, addDisks []*api.GuestdiskJsonDesc
|
||||
var delNetworks, addNetworks []*api.GuestnetworkJsonDesc
|
||||
var changedNetworks [][2]*api.GuestnetworkJsonDesc
|
||||
var delDevs, addDevs []*api.IsolatedDeviceJsonDesc
|
||||
var cdrom *string
|
||||
|
||||
if !fwOnly && !s.isImportFromLibvirt() {
|
||||
@@ -1580,8 +1558,6 @@ func (s *SKVMGuestInstance) SyncConfig(ctx context.Context, desc jsonutils.JSONO
|
||||
data.Set("vnc_port", jsonutils.NewInt(int64(vncPort)))
|
||||
s.saveScripts(data)
|
||||
|
||||
// if options.enable_openflow_controller: 不写
|
||||
|
||||
if fwOnly {
|
||||
res := jsonutils.NewDict()
|
||||
res.Set("task", jsonutils.NewArray(jsonutils.NewString("secgroupsync")))
|
||||
@@ -1627,23 +1603,19 @@ func (s *SKVMGuestInstance) SyncConfig(ctx context.Context, desc jsonutils.JSONO
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getApptags() []string {
|
||||
var tags []string
|
||||
meta, _ := s.Desc.Get("metadata")
|
||||
if meta != nil && meta.Contains("app_tags") {
|
||||
tagsStr, _ := meta.GetString("app_tags")
|
||||
if tagsStr, ok := s.Desc.Metadata["app_tags"]; ok {
|
||||
if len(tagsStr) > 0 {
|
||||
return strings.Split(tagsStr, ",")
|
||||
}
|
||||
}
|
||||
return tags
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getStorageDeviceId() string {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
if len(disks) > 0 {
|
||||
diskPath, _ := disks[0].GetString("path")
|
||||
if len(diskPath) > 0 {
|
||||
return fileutils2.GetDevId(diskPath)
|
||||
if len(disks[0].Path) > 0 {
|
||||
return fileutils2.GetDevId(disks[0].Path)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
@@ -1654,10 +1626,10 @@ func (s *SKVMGuestInstance) GetCgroupName() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
meta, _ := s.Desc.Get("metadata")
|
||||
if jsonutils.QueryBoolean(meta, "__enable_cgroup_cpuset", false) {
|
||||
if val, _ := s.Desc.Metadata["__enable_cgroup_cpuset"]; val == "true" {
|
||||
return fmt.Sprintf("%s/server_%s_%d", hostconsts.HOST_CGROUP, s.Id, s.cgroupPid)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -1685,16 +1657,15 @@ func (s *SKVMGuestInstance) setCgroupIo() {
|
||||
params["blkio.throttle.read_iops_device"] = options.HostOptions.DefaultReadIopsPerCpu
|
||||
params["blkio.throttle.write_bps_device"] = options.HostOptions.DefaultWriteBpsPerCpu
|
||||
params["blkio.throttle.write_iops_device"] = options.HostOptions.DefaultWriteIopsPerCpu
|
||||
cpu, _ := s.Desc.Int("cpu")
|
||||
cgrouputils.CgroupIoHardlimitSet(
|
||||
strconv.Itoa(s.cgroupPid), s.GetCgroupName(), int(cpu), params, devId,
|
||||
strconv.Itoa(s.cgroupPid), s.GetCgroupName(), int(s.Desc.Cpu), params, devId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) setCgroupCpu() {
|
||||
var (
|
||||
cpu, _ = s.Desc.Int("cpu")
|
||||
cpu = s.Desc.Cpu
|
||||
cpuWeight = 1024
|
||||
)
|
||||
|
||||
@@ -1703,11 +1674,16 @@ func (s *SKVMGuestInstance) setCgroupCpu() {
|
||||
|
||||
func (s *SKVMGuestInstance) setCgroupCPUSet() {
|
||||
var input *api.ServerCPUSetInput
|
||||
if s.Desc.Contains("metadata", api.VM_METADATA_CGROUP_CPUSET) {
|
||||
input = new(api.ServerCPUSetInput)
|
||||
err := s.Desc.Unmarshal(input, "metadata", api.VM_METADATA_CGROUP_CPUSET)
|
||||
if cpuset, ok := s.Desc.Metadata[api.VM_METADATA_CGROUP_CPUSET]; ok {
|
||||
cpusetJson, err := jsonutils.ParseString(cpuset)
|
||||
if err != nil {
|
||||
log.Errorf("Unmarshal %s to ServerCPUSetInput failed: %s", api.VM_METADATA_CGROUP_CPUSET, err)
|
||||
log.Errorf("failed parse server %s cpuset %s: %s", s.Id, cpuset, err)
|
||||
return
|
||||
}
|
||||
input = new(api.ServerCPUSetInput)
|
||||
err = cpusetJson.Unmarshal(input)
|
||||
if err != nil {
|
||||
log.Errorf("failed unmarshal server %s cpuset %s", s.Id, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1717,39 +1693,34 @@ func (s *SKVMGuestInstance) setCgroupCPUSet() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) CreateFromDesc(desc jsonutils.JSONObject) error {
|
||||
func (s *SKVMGuestInstance) CreateFromDesc(desc *desc.SGuestDesc) error {
|
||||
if err := s.PrepareDir(); err != nil {
|
||||
uuid, _ := desc.GetString("uuid")
|
||||
return fmt.Errorf("Failed to create server dir %s", uuid)
|
||||
return fmt.Errorf("Failed to create server dir %s", desc.Uuid)
|
||||
}
|
||||
return s.SaveDesc(desc)
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetNeedMergeBackingFileDiskIndexs() []int {
|
||||
res := make([]int, 0)
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
for _, disk := range disks {
|
||||
if jsonutils.QueryBoolean(disk, "merge_snapshot", false) {
|
||||
diskIdx, _ := disk.Int("index")
|
||||
res = append(res, int(diskIdx))
|
||||
for _, disk := range s.Desc.Disks {
|
||||
if disk.MergeSnapshot {
|
||||
res = append(res, int(disk.Index))
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) streamDisksComplete(ctx context.Context) {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
for i, disk := range disks {
|
||||
diskpath, _ := disk.GetString("path")
|
||||
d, _ := storageman.GetManager().GetDiskByPath(diskpath)
|
||||
disks := s.Desc.Disks
|
||||
for i, _ := range disks {
|
||||
d, _ := storageman.GetManager().GetDiskByPath(disks[i].Path)
|
||||
if d != nil {
|
||||
log.Infof("Disk %s do post create from fuse", d.GetId())
|
||||
d.PostCreateFromImageFuse()
|
||||
}
|
||||
if jsonutils.QueryBoolean(disk, "merge_snapshot", false) {
|
||||
d := disks[i].(*jsonutils.JSONDict)
|
||||
d.Set("merge_snapshot", jsonutils.JSONFalse)
|
||||
s.Desc.Set("need_sync_stream_disks", jsonutils.JSONTrue)
|
||||
if disks[i].MergeSnapshot {
|
||||
disks[i].MergeSnapshot = false
|
||||
s.NeedSyncStreamDisks = true
|
||||
}
|
||||
}
|
||||
if err := s.SaveDesc(s.Desc); err != nil {
|
||||
@@ -1773,7 +1744,8 @@ func (s *SKVMGuestInstance) sendStreamDisksComplete(ctx context.Context) {
|
||||
break
|
||||
}
|
||||
}
|
||||
s.Desc.Remove("need_sync_stream_disks")
|
||||
|
||||
s.NeedSyncStreamDisks = false
|
||||
if err := s.SaveDesc(s.Desc); err != nil {
|
||||
log.Errorf("save guest desc failed %s", err)
|
||||
}
|
||||
@@ -1838,19 +1810,19 @@ func (s *SKVMGuestInstance) OnResumeSyncMetadataInfo() {
|
||||
} else {
|
||||
meta.Set("__qemu_cmdline", jsonutils.NewString(cmdline))
|
||||
}
|
||||
if s.syncMeta != nil {
|
||||
meta.Update(s.syncMeta)
|
||||
if s.SyncMeta != nil {
|
||||
meta.Update(s.SyncMeta)
|
||||
}
|
||||
s.SyncMetadata(meta)
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) doBlockIoThrottle() {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
if len(disks) > 0 {
|
||||
bps, _ := disks[0].Int("bps")
|
||||
iops, _ := disks[0].Int("iops")
|
||||
bps := disks[0].Bps
|
||||
iops := disks[0].Iops
|
||||
if bps > 0 || iops > 0 {
|
||||
s.BlockIoThrottle(context.Background(), bps, iops)
|
||||
s.BlockIoThrottle(context.Background(), int64(bps), int64(iops))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1873,22 +1845,17 @@ func (s *SKVMGuestInstance) onGuestPrelaunch() error {
|
||||
|
||||
func (s *SKVMGuestInstance) CleanImportMetadata() *jsonutils.JSONDict {
|
||||
meta := jsonutils.NewDict()
|
||||
if originId, _ := s.Desc.GetString("metadata", "__origin_id"); len(originId) > 0 {
|
||||
if len(s.Desc.Metadata["__origin_id"]) > 0 {
|
||||
meta.Set("__origin_id", jsonutils.NewString(""))
|
||||
delete(s.Desc.Metadata, "__origin_id")
|
||||
}
|
||||
if monitorPath, _ := s.Desc.GetString("metadata", "__monitor_path"); len(monitorPath) > 0 {
|
||||
if len(s.Desc.Metadata["__monitor_path"]) > 0 {
|
||||
meta.Set("__monitor_path", jsonutils.NewString(""))
|
||||
delete(s.Desc.Metadata, "__monitor_path")
|
||||
}
|
||||
|
||||
if meta.Length() > 0 {
|
||||
// update local metadata record, after monitor started updata region record
|
||||
metadata, err := s.Desc.GetMap("metadata")
|
||||
if err == nil {
|
||||
updateMeta, _ := meta.GetMap()
|
||||
for k, v := range updateMeta {
|
||||
metadata[k] = v
|
||||
}
|
||||
}
|
||||
s.SaveDesc(s.Desc)
|
||||
return meta
|
||||
}
|
||||
@@ -2121,13 +2088,11 @@ func (s *SKVMGuestInstance) ExecMemorySnapshotResetTask(ctx context.Context, inp
|
||||
|
||||
func (s *SKVMGuestInstance) PrepareDisksMigrate(liveMigrage bool) (*jsonutils.JSONDict, error) {
|
||||
disksBackFile := jsonutils.NewDict()
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
for _, disk := range disks {
|
||||
if disk.Contains("path") {
|
||||
diskPath, _ := disk.GetString("path")
|
||||
d, err := storageman.GetManager().GetDiskByPath(diskPath)
|
||||
for _, disk := range s.Desc.Disks {
|
||||
if disk.Path != "" {
|
||||
d, err := storageman.GetManager().GetDiskByPath(disk.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", diskPath)
|
||||
return nil, errors.Wrapf(err, "GetDiskByPath(%s)", disk.Path)
|
||||
}
|
||||
if d.GetType() == api.STORAGE_LOCAL {
|
||||
back, err := d.PrepareMigrate(liveMigrage)
|
||||
@@ -2135,8 +2100,7 @@ func (s *SKVMGuestInstance) PrepareDisksMigrate(liveMigrage bool) (*jsonutils.JS
|
||||
return nil, err
|
||||
}
|
||||
if len(back) > 0 {
|
||||
diskId, _ := disk.GetString("disk_id")
|
||||
disksBackFile.Set(diskId, jsonutils.NewString(back))
|
||||
disksBackFile.Set(disk.DiskId, jsonutils.NewString(back))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2155,12 +2119,11 @@ func (s *SKVMGuestInstance) BlockIoThrottle(ctx context.Context, bps, iops int64
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) IsSharedStorage() bool {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
disks := s.Desc.Disks
|
||||
for i := 0; i < len(disks); i++ {
|
||||
diskPath, _ := disks[i].GetString("path")
|
||||
disk, err := storageman.GetManager().GetDiskByPath(diskPath)
|
||||
disk, err := storageman.GetManager().GetDiskByPath(disks[i].Path)
|
||||
if err != nil {
|
||||
log.Errorf("failed find disk by path %s", diskPath)
|
||||
log.Errorf("failed find disk by path %s", disks[i].Path)
|
||||
return false
|
||||
}
|
||||
if !utils.IsInStringArray(disk.GetType(), api.SHARED_STORAGE) {
|
||||
@@ -2170,7 +2133,7 @@ func (s *SKVMGuestInstance) IsSharedStorage() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) generateDiskSetupScripts(disks []api.GuestdiskJsonDesc) (string, error) {
|
||||
func (s *SKVMGuestInstance) generateDiskSetupScripts(disks []*api.GuestdiskJsonDesc) (string, error) {
|
||||
cmd := " "
|
||||
for i := range disks {
|
||||
diskPath := disks[i].Path
|
||||
@@ -2228,12 +2191,7 @@ func (s *SKVMGuestInstance) CPUSet(ctx context.Context, input *api.ServerCPUSetI
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) CPUSetRemove(ctx context.Context) error {
|
||||
metadata, err := s.Desc.Get("metadata")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get metadata from desc")
|
||||
}
|
||||
metadata.(*jsonutils.JSONDict).Remove(api.VM_METADATA_CGROUP_CPUSET)
|
||||
s.Desc.Set("metadata", metadata)
|
||||
delete(s.Desc.Metadata, api.VM_METADATA_CGROUP_CPUSET)
|
||||
if err := s.SaveDesc(s.Desc); err != nil {
|
||||
return errors.Wrap(err, "save desc after update metadata")
|
||||
}
|
||||
|
||||
@@ -65,31 +65,26 @@ func (s *SKVMGuestInstance) IsKvmSupport() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) IsVdiSpice() bool {
|
||||
vdi, _ := s.Desc.GetString("vdi")
|
||||
return vdi == "spice"
|
||||
return s.Desc.Vdi == "spice"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getOsname() string {
|
||||
osName, err := s.Desc.GetString("metadata", "os_name")
|
||||
if err != nil {
|
||||
return OS_NAME_LINUX
|
||||
if osName, ok := s.Desc.Metadata["os_name"]; ok {
|
||||
return osName
|
||||
}
|
||||
return osName
|
||||
return OS_NAME_LINUX
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) disableUsbKbd() bool {
|
||||
val, _ := s.Desc.GetString("metadata", "disable_usb_kbd")
|
||||
return val == "true"
|
||||
return s.Desc.Metadata["disable_usb_kbd"] == "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getOsDistribution() string {
|
||||
osDis, _ := s.Desc.GetString("metadata", "os_distribution")
|
||||
return osDis
|
||||
return s.Desc.Metadata["os_distribution"]
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getOsVersion() string {
|
||||
osVer, _ := s.Desc.GetString("metadata", "os_version")
|
||||
return osVer
|
||||
return s.Desc.Metadata["os_version"]
|
||||
}
|
||||
|
||||
// is windows prioer to windows server 2003
|
||||
@@ -114,21 +109,20 @@ func (s *SKVMGuestInstance) isWindows10() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) isMemcleanEnabled() bool {
|
||||
val, _ := s.Desc.GetString("metadata", "enable_memclean")
|
||||
return val == "true"
|
||||
return s.Desc.Metadata["enable_memclean"] == "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getMachine() string {
|
||||
machine, err := s.Desc.GetString("machine")
|
||||
if err != nil {
|
||||
machine := s.Desc.Machine
|
||||
if machine == "" {
|
||||
machine = api.VM_MACHINE_TYPE_PC
|
||||
}
|
||||
return machine
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getBios() string {
|
||||
bios, err := s.Desc.GetString("bios")
|
||||
if err != nil {
|
||||
bios := s.Desc.Bios
|
||||
if bios == "" {
|
||||
bios = "bios"
|
||||
}
|
||||
return bios
|
||||
@@ -143,8 +137,8 @@ func (s *SKVMGuestInstance) isVirt() bool {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetVdiProtocol() string {
|
||||
vdi, err := s.Desc.GetString("vdi")
|
||||
if err != nil {
|
||||
vdi := s.Desc.Vdi
|
||||
if vdi == "" {
|
||||
vdi = "vnc"
|
||||
}
|
||||
return vdi
|
||||
@@ -159,35 +153,29 @@ func (s *SKVMGuestInstance) GetPciBus() string {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) disableIsaSerialDev() bool {
|
||||
val, _ := s.Desc.GetString("metadata", "disable_isa_serial")
|
||||
return val == "true"
|
||||
return s.Desc.Metadata["disable_isa_serial"] == "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) disablePvpanicDev() bool {
|
||||
val, _ := s.Desc.GetString("metadata", "disable_pvpanic")
|
||||
return val == "true"
|
||||
return s.Desc.Metadata["disable_pvpanic"] == "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) GetDiskAddr(idx int) int {
|
||||
return qemu.GetDiskAddr(idx, s.IsVdiSpice())
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getNicUpScriptPath(nic jsonutils.JSONObject) string {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
dev := guestManager.GetHost().GetBridgeDev(bridge)
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-up-%s-%s.sh", dev.Bridge(), ifname))
|
||||
func (s *SKVMGuestInstance) getNicUpScriptPath(nic *api.GuestnetworkJsonDesc) string {
|
||||
dev := guestManager.GetHost().GetBridgeDev(nic.Bridge)
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-up-%s-%s.sh", dev.Bridge(), nic.Ifname))
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getNicDownScriptPath(nic jsonutils.JSONObject) string {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
dev := guestManager.GetHost().GetBridgeDev(bridge)
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-down-%s-%s.sh", dev.Bridge(), ifname))
|
||||
func (s *SKVMGuestInstance) getNicDownScriptPath(nic *api.GuestnetworkJsonDesc) string {
|
||||
dev := guestManager.GetHost().GetBridgeDev(nic.Bridge)
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-down-%s-%s.sh", dev.Bridge(), nic.Ifname))
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) generateNicScripts(nic jsonutils.JSONObject) error {
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
func (s *SKVMGuestInstance) generateNicScripts(nic *api.GuestnetworkJsonDesc) error {
|
||||
bridge := nic.Bridge
|
||||
dev := guestManager.GetHost().GetBridgeDev(bridge)
|
||||
if dev == nil {
|
||||
return fmt.Errorf("Can't find bridge %s", bridge)
|
||||
@@ -207,15 +195,12 @@ func (s *SKVMGuestInstance) getNicDeviceModel(name string) string {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getNicAddr(index int) int {
|
||||
disks, _ := s.Desc.GetArray("disks")
|
||||
isolatedDevices, _ := s.Desc.GetArray("isolated_devices")
|
||||
return qemu.GetNicAddr(index, len(disks), len(isolatedDevices), s.IsVdiSpice())
|
||||
return qemu.GetNicAddr(index, len(s.Desc.Disks), len(s.Desc.IsolatedDevices), s.IsVdiSpice())
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) extraOptions() string {
|
||||
cmd := " "
|
||||
extraOptions, _ := s.Desc.GetMap("extra_options")
|
||||
for k, v := range extraOptions {
|
||||
for k, v := range s.Desc.ExtraOptions {
|
||||
switch jsonV := v.(type) {
|
||||
case *jsonutils.JSONArray:
|
||||
for i := 0; i < jsonV.Size(); i++ {
|
||||
@@ -231,28 +216,21 @@ func (s *SKVMGuestInstance) extraOptions() string {
|
||||
|
||||
func (s *SKVMGuestInstance) generateStartScript(data *jsonutils.JSONDict) (string, error) {
|
||||
// initial data
|
||||
var (
|
||||
uuid, _ = s.Desc.GetString("uuid")
|
||||
mem, _ = s.Desc.Int("mem")
|
||||
cpu, _ = s.Desc.Int("cpu")
|
||||
name, _ = s.Desc.GetString("name")
|
||||
nics, _ = s.Desc.GetArray("nics")
|
||||
osname = s.getOsname()
|
||||
input = &qemu.GenerateStartOptionsInput{
|
||||
UUID: uuid,
|
||||
Mem: uint64(mem),
|
||||
Cpu: uint(cpu),
|
||||
Name: name,
|
||||
OsName: osname,
|
||||
Nics: nics,
|
||||
OVNIntegrationBridge: options.HostOptions.OvnIntegrationBridge,
|
||||
HomeDir: s.HomeDir(),
|
||||
HugepagesEnabled: s.manager.host.IsHugepagesEnabled(),
|
||||
EnableMemfd: s.isMemcleanEnabled(),
|
||||
PidFilePath: s.GetPidFilePath(),
|
||||
BIOS: s.getBios(),
|
||||
}
|
||||
)
|
||||
var input = &qemu.GenerateStartOptionsInput{
|
||||
UUID: s.Desc.Uuid,
|
||||
Mem: uint64(s.Desc.Mem),
|
||||
Cpu: uint(s.Desc.Cpu),
|
||||
Name: s.Desc.Name,
|
||||
OsName: s.getOsname(),
|
||||
Nics: s.Desc.Nics,
|
||||
Disks: s.Desc.Disks,
|
||||
OVNIntegrationBridge: options.HostOptions.OvnIntegrationBridge,
|
||||
HomeDir: s.HomeDir(),
|
||||
HugepagesEnabled: s.manager.host.IsHugepagesEnabled(),
|
||||
EnableMemfd: s.isMemcleanEnabled(),
|
||||
PidFilePath: s.GetPidFilePath(),
|
||||
BIOS: s.getBios(),
|
||||
}
|
||||
|
||||
if data.Contains("encrypt_key") {
|
||||
key, _ := data.GetString("encrypt_key")
|
||||
@@ -262,16 +240,11 @@ func (s *SKVMGuestInstance) generateStartScript(data *jsonutils.JSONDict) (strin
|
||||
|
||||
cmd := ""
|
||||
|
||||
// inject disks
|
||||
disks := make([]api.GuestdiskJsonDesc, 0)
|
||||
s.Desc.Unmarshal(&disks, "disks")
|
||||
input.Disks = disks
|
||||
|
||||
// inject machine and bios
|
||||
if input.OsName == OS_NAME_MACOS {
|
||||
s.Desc.Set("machine", jsonutils.NewString(api.VM_MACHINE_TYPE_Q35))
|
||||
s.Desc.Machine = api.VM_MACHINE_TYPE_Q35
|
||||
input.Machine = api.VM_MACHINE_TYPE_Q35
|
||||
s.Desc.Set("bios", jsonutils.NewString(qemu.BIOS_UEFI))
|
||||
s.Desc.Bios = qemu.BIOS_UEFI
|
||||
input.BIOS = qemu.BIOS_UEFI
|
||||
}
|
||||
|
||||
@@ -297,18 +270,16 @@ func (s *SKVMGuestInstance) generateStartScript(data *jsonutils.JSONDict) (strin
|
||||
|
||||
// inject isolatedDevices
|
||||
var devAddrs = []string{}
|
||||
isolatedParams, _ := s.Desc.GetArray("isolated_devices")
|
||||
isolatedParams := s.Desc.IsolatedDevices
|
||||
for _, params := range isolatedParams {
|
||||
devAddr, _ := params.GetString("addr")
|
||||
devAddrs = append(devAddrs, devAddr)
|
||||
devAddrs = append(devAddrs, params.Addr)
|
||||
}
|
||||
isolatedDevsParams := s.manager.GetHost().GetIsolatedDeviceManager().GetQemuParams(devAddrs)
|
||||
input.IsolatedDevicesParams = isolatedDevsParams
|
||||
|
||||
for _, nic := range input.Nics {
|
||||
downscript := s.getNicDownScriptPath(nic)
|
||||
ifname, _ := nic.GetString("ifnam")
|
||||
cmd += fmt.Sprintf("%s %s\n", downscript, ifname)
|
||||
cmd += fmt.Sprintf("%s %s\n", downscript, nic.Ifname)
|
||||
}
|
||||
|
||||
if input.HugepagesEnabled {
|
||||
@@ -422,12 +393,9 @@ function nic_mtu() {
|
||||
input.Machine = s.getMachine()
|
||||
|
||||
// inject bootOrder and cdrom
|
||||
bootOrder, _ := s.Desc.GetString("boot_order")
|
||||
input.BootOrder = bootOrder
|
||||
cdrom, _ := s.Desc.Get("cdrom")
|
||||
if cdrom != nil && cdrom.Contains("path") {
|
||||
cdromPath, _ := cdrom.GetString("path")
|
||||
input.CdromPath = cdromPath
|
||||
input.BootOrder = s.Desc.BootOrder
|
||||
if s.Desc.Cdrom != nil && s.Desc.Cdrom.Path != "" {
|
||||
input.CdromPath = s.Desc.Cdrom.Path
|
||||
}
|
||||
|
||||
// UEFI ovmf file path
|
||||
@@ -444,27 +412,26 @@ function nic_mtu() {
|
||||
|
||||
// inject nic and disks
|
||||
for i := 0; i < len(input.Nics); i++ {
|
||||
nic := nics[i].(*jsonutils.JSONDict)
|
||||
if numQueues, _ := nic.Int("num_queues"); numQueues > 1 {
|
||||
nic.Set("vectors", jsonutils.NewInt(2*numQueues+1))
|
||||
if input.Nics[i].NumQueues > 1 {
|
||||
vectors := input.Nics[i].NumQueues * 2
|
||||
input.Nics[i].Vectors = &vectors
|
||||
}
|
||||
}
|
||||
|
||||
if input.OsName == OS_NAME_MACOS {
|
||||
for i := 0; i < len(input.Disks); i++ {
|
||||
disks[i].Driver = DISK_DRIVER_SATA
|
||||
input.Disks[i].Driver = DISK_DRIVER_SATA
|
||||
}
|
||||
for i := 0; i < len(input.Nics); i++ {
|
||||
nic := nics[i].(*jsonutils.JSONDict)
|
||||
nic.Set("vectors", jsonutils.NewInt(0))
|
||||
nic.Set("driver", jsonutils.NewString("e1000"))
|
||||
vectors := 0
|
||||
input.Nics[i].Vectors = &vectors
|
||||
input.Nics[i].Driver = "e1000"
|
||||
}
|
||||
} else if input.OsName == OS_NAME_ANDROID {
|
||||
if len(input.Nics) > 1 {
|
||||
s.Desc.Set("nics", jsonutils.NewArray(input.Nics[0]))
|
||||
s.Desc.Nics = input.Nics[:1]
|
||||
}
|
||||
nics, _ = s.Desc.GetArray("nics")
|
||||
input.Nics = nics
|
||||
input.Nics = s.Desc.Nics
|
||||
}
|
||||
|
||||
// inject devices
|
||||
@@ -481,7 +448,7 @@ function nic_mtu() {
|
||||
!s.disableUsbKbd() {
|
||||
input.Devices = append(input.Devices, "usb-kbd")
|
||||
}
|
||||
if osname == OS_NAME_ANDROID {
|
||||
if input.OsName == OS_NAME_ANDROID {
|
||||
input.Devices = append(input.Devices, "usb-mouse")
|
||||
} else if !s.isOldWindows() {
|
||||
input.Devices = append(input.Devices, "usb-tablet")
|
||||
@@ -493,8 +460,8 @@ function nic_mtu() {
|
||||
input.SpicePort = uint(5900 + vncPort)
|
||||
input.PCIBus = s.GetPciBus()
|
||||
if input.QemuArch != qemu.Arch_aarch64 {
|
||||
vga, err := s.Desc.GetString("vga")
|
||||
if err != nil {
|
||||
vga := s.Desc.Vga
|
||||
if vga == "" {
|
||||
vga = "std"
|
||||
}
|
||||
input.VGA = vga
|
||||
@@ -505,15 +472,13 @@ function nic_mtu() {
|
||||
input.IsKVMSupport = s.IsKvmSupport()
|
||||
for i := 0; i < len(input.Nics); i++ {
|
||||
if input.OsName == OS_NAME_VMWARE {
|
||||
input.Nics[i].(*jsonutils.JSONDict).Set("driver", jsonutils.NewString("vmxnet3"))
|
||||
input.Nics[i].Driver = "vmxnet3"
|
||||
}
|
||||
if err := s.generateNicScripts(input.Nics[i]); err != nil {
|
||||
return "", errors.Wrapf(err, "generateNicScripts for nic: %s", input.Nics[i])
|
||||
return "", errors.Wrapf(err, "generateNicScripts for nic: %v", input.Nics[i])
|
||||
}
|
||||
upscript := s.getNicUpScriptPath(input.Nics[i])
|
||||
downscript := s.getNicDownScriptPath(input.Nics[i])
|
||||
input.Nics[i].(*jsonutils.JSONDict).Set("upscript_path", jsonutils.NewString(upscript))
|
||||
input.Nics[i].(*jsonutils.JSONDict).Set("downscript_path", jsonutils.NewString(downscript))
|
||||
input.Nics[i].UpscriptPath = s.getNicUpScriptPath(input.Nics[i])
|
||||
input.Nics[i].DownscriptPath = s.getNicDownScriptPath(input.Nics[i])
|
||||
}
|
||||
|
||||
input.ExtraOptions = append(input.ExtraOptions, s.extraOptions())
|
||||
@@ -536,16 +501,16 @@ function nic_mtu() {
|
||||
if jsonutils.QueryBoolean(data, "need_migrate", false) {
|
||||
input.NeedMigrate = true
|
||||
migratePort := s.manager.GetFreePortByBase(LIVE_MIGRATE_PORT_BASE)
|
||||
s.Desc.Set("live_migrate_dest_port", jsonutils.NewInt(int64(migratePort)))
|
||||
s.LiveMigrateDestPort = &migratePort
|
||||
input.LiveMigratePort = uint(migratePort)
|
||||
if jsonutils.QueryBoolean(data, "live_migrate_use_tls", false) {
|
||||
s.LiveMigrateUseTls = true
|
||||
input.LiveMigrateUseTLS = true
|
||||
s.Desc.Set("live_migrate_use_tls", jsonutils.JSONTrue)
|
||||
}
|
||||
} else if jsonutils.QueryBoolean(s.Desc, "is_slave", false) {
|
||||
} else if s.Desc.IsSlave {
|
||||
input.IsSlave = true
|
||||
input.LiveMigratePort = uint(s.manager.GetFreePortByBase(LIVE_MIGRATE_PORT_BASE))
|
||||
} else if jsonutils.QueryBoolean(s.Desc, "is_master", false) {
|
||||
} else if s.Desc.IsMaster {
|
||||
input.IsMaster = true
|
||||
}
|
||||
// cmd += fmt.Sprintf(" -D %s", path.Join(s.HomeDir(), "log"))
|
||||
@@ -644,8 +609,8 @@ func (s *SKVMGuestInstance) unifyMigrateQemuCmdline(cur string, src string) (str
|
||||
|
||||
func (s *SKVMGuestInstance) generateStopScript(data *jsonutils.JSONDict) string {
|
||||
var (
|
||||
uuid, _ = s.Desc.GetString("uuid")
|
||||
nics, _ = s.Desc.GetArray("nics")
|
||||
uuid = s.Desc.Uuid
|
||||
nics = s.Desc.Nics
|
||||
)
|
||||
|
||||
cmd := ""
|
||||
@@ -681,18 +646,16 @@ func (s *SKVMGuestInstance) generateStopScript(data *jsonutils.JSONDict) string
|
||||
cmd += fmt.Sprintf("done\n")
|
||||
|
||||
for _, nic := range nics {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
downscript := s.getNicDownScriptPath(nic)
|
||||
cmd += fmt.Sprintf("%s %s\n", downscript, ifname)
|
||||
cmd += fmt.Sprintf("%s %s\n", downscript, nic.Ifname)
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) presendArpForNic(nic jsonutils.JSONObject) {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
ifi, err := net.InterfaceByName(ifname)
|
||||
func (s *SKVMGuestInstance) presendArpForNic(nic *api.GuestnetworkJsonDesc) {
|
||||
ifi, err := net.InterfaceByName(nic.Ifname)
|
||||
if err != nil {
|
||||
log.Errorf("InterfaceByName error %s", ifname)
|
||||
log.Errorf("InterfaceByName error %s", nic.Ifname)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -704,11 +667,11 @@ func (s *SKVMGuestInstance) presendArpForNic(nic jsonutils.JSONObject) {
|
||||
defer cli.Close()
|
||||
|
||||
var (
|
||||
sSrcMac, _ = nic.GetString("mac")
|
||||
sScrIp, _ = nic.GetString("ip")
|
||||
srcIp = net.ParseIP(sScrIp)
|
||||
dstMac, _ = net.ParseMAC("00:00:00:00:00:00")
|
||||
dstIp = net.ParseIP("255.255.255.255")
|
||||
sSrcMac = nic.Mac
|
||||
sScrIp = nic.Ip
|
||||
srcIp = net.ParseIP(sScrIp)
|
||||
dstMac, _ = net.ParseMAC("00:00:00:00:00:00")
|
||||
dstIp = net.ParseIP("255.255.255.255")
|
||||
)
|
||||
srcMac, err := net.ParseMAC(sSrcMac)
|
||||
if err != nil {
|
||||
@@ -730,8 +693,7 @@ func (s *SKVMGuestInstance) presendArpForNic(nic jsonutils.JSONObject) {
|
||||
func (s *SKVMGuestInstance) StartPresendArp() {
|
||||
go func() {
|
||||
for i := 0; i < 5; i++ {
|
||||
nics, _ := s.Desc.GetArray("nics")
|
||||
for _, nic := range nics {
|
||||
for _, nic := range s.Desc.Nics {
|
||||
s.presendArpForNic(nic)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -778,11 +740,10 @@ func (s *SKVMGuestInstance) WriteMigrateCerts(certs map[string]string) error {
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) startMemCleaner() error {
|
||||
mem, _ := s.Desc.Int("mem")
|
||||
err := procutils.NewRemoteCommandAsFarAsPossible(
|
||||
options.HostOptions.BinaryMemcleanPath,
|
||||
"--pid", strconv.Itoa(s.GetPid()),
|
||||
"--mem-size", strconv.FormatInt(mem*1024*1024, 10),
|
||||
"--mem-size", strconv.FormatInt(s.Desc.Mem*1024*1024, 10),
|
||||
"--log-dir", s.HomeDir(),
|
||||
).Run()
|
||||
if err != nil {
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
@@ -50,9 +49,9 @@ type GenerateStartOptionsInput struct {
|
||||
IsQ35 bool
|
||||
BootOrder string
|
||||
CdromPath string
|
||||
Nics []jsonutils.JSONObject
|
||||
Nics []*api.GuestnetworkJsonDesc
|
||||
OVNIntegrationBridge string
|
||||
Disks []api.GuestdiskJsonDesc
|
||||
Disks []*api.GuestdiskJsonDesc
|
||||
Devices []string
|
||||
Machine string
|
||||
BIOS string
|
||||
@@ -166,6 +165,10 @@ func GenerateStartOptions(
|
||||
opts = append(opts, drvOpt.Device(device))
|
||||
}
|
||||
|
||||
// if input.IsPcie {
|
||||
// opts = append(opts, drvOpt.PciePciBridge(input.PciePciBridgeId))
|
||||
// }
|
||||
|
||||
// vdi spice
|
||||
if input.IsVdiSpice {
|
||||
opts = append(opts, drvOpt.VdiSpice(input.SpicePort, input.PCIBus)...)
|
||||
@@ -253,7 +256,7 @@ func getMonitorOptions(drvOpt QemuOptions, input *Monitor) []string {
|
||||
return opts
|
||||
}
|
||||
|
||||
func generateDisksOptions(drvOpt QemuOptions, disks []api.GuestdiskJsonDesc, pciBus string, isVdiSpice bool, isEncrypt bool) []string {
|
||||
func generateDisksOptions(drvOpt QemuOptions, disks []*api.GuestdiskJsonDesc, pciBus string, isVdiSpice bool, isEncrypt bool) []string {
|
||||
opts := []string{}
|
||||
isArm := drvOpt.IsArm()
|
||||
firstDriver := make(map[string]bool)
|
||||
@@ -285,7 +288,7 @@ func generateDisksOptions(drvOpt QemuOptions, disks []api.GuestdiskJsonDesc, pci
|
||||
return opts
|
||||
}
|
||||
|
||||
func getDiskDriveOption(drvOpt QemuOptions, disk api.GuestdiskJsonDesc, isArm bool, isEncrypt bool) string {
|
||||
func getDiskDriveOption(drvOpt QemuOptions, disk *api.GuestdiskJsonDesc, isArm bool, isEncrypt bool) string {
|
||||
format := disk.Format
|
||||
diskIndex := disk.Index
|
||||
cacheMode := disk.CacheMode
|
||||
@@ -316,7 +319,7 @@ func getDiskDriveOption(drvOpt QemuOptions, disk api.GuestdiskJsonDesc, isArm bo
|
||||
return drvOpt.Drive(opt)
|
||||
}
|
||||
|
||||
func isLocalStorage(disk api.GuestdiskJsonDesc) bool {
|
||||
func isLocalStorage(disk *api.GuestdiskJsonDesc) bool {
|
||||
if disk.StorageType == api.STORAGE_LOCAL || len(disk.StorageType) == 0 {
|
||||
return true
|
||||
} else {
|
||||
@@ -324,7 +327,7 @@ func isLocalStorage(disk api.GuestdiskJsonDesc) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func getDiskDeviceOption(optDrv QemuOptions, disk api.GuestdiskJsonDesc, isArm bool, pciBus string, isVdiSpice bool) string {
|
||||
func getDiskDeviceOption(optDrv QemuOptions, disk *api.GuestdiskJsonDesc, isArm bool, pciBus string, isVdiSpice bool) string {
|
||||
diskIndex := disk.Index
|
||||
diskDriver := disk.Driver
|
||||
numQueues := disk.NumQueues
|
||||
@@ -411,7 +414,7 @@ func generateNicOptions(drvOpt QemuOptions, input *GenerateStartOptionsInput) ([
|
||||
for idx := range nics {
|
||||
netDevOpt, err := getNicNetdevOption(drvOpt, nics[idx], input.IsKVMSupport)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getNicNetdevOption %s", nics[idx])
|
||||
return nil, errors.Wrapf(err, "getNicNetdevOption %v", nics[idx])
|
||||
}
|
||||
opts = append(opts,
|
||||
netDevOpt,
|
||||
@@ -422,50 +425,41 @@ func generateNicOptions(drvOpt QemuOptions, input *GenerateStartOptionsInput) ([
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func getNicNetdevOption(drvOpt QemuOptions, nic jsonutils.JSONObject, isKVMSupport bool) (string, error) {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
if ifname == "" {
|
||||
func getNicNetdevOption(drvOpt QemuOptions, nic *api.GuestnetworkJsonDesc, isKVMSupport bool) (string, error) {
|
||||
if nic.Ifname == "" {
|
||||
return "", errors.Error("ifname is empty")
|
||||
}
|
||||
driver, _ := nic.GetString("driver")
|
||||
upscript, _ := nic.GetString("upscript_path")
|
||||
if upscript == "" {
|
||||
if nic.UpscriptPath == "" {
|
||||
return "", errors.Error("upscript_path is empty")
|
||||
}
|
||||
downscript, _ := nic.GetString("downscript_path")
|
||||
if downscript == "" {
|
||||
if nic.DownscriptPath == "" {
|
||||
return "", errors.Error("downscript_path is empty")
|
||||
}
|
||||
numQueues, _ := nic.Int("num_queues")
|
||||
|
||||
opt := "-netdev type=tap"
|
||||
opt += fmt.Sprintf(",id=%s", ifname)
|
||||
opt += fmt.Sprintf(",ifname=%s", ifname)
|
||||
if driver == "virtio" && isKVMSupport {
|
||||
opt += fmt.Sprintf(",id=%s", nic.Ifname)
|
||||
opt += fmt.Sprintf(",ifname=%s", nic.Ifname)
|
||||
if nic.Driver == "virtio" && isKVMSupport {
|
||||
opt += ",vhost=on,vhostforce=off"
|
||||
if numQueues > 1 {
|
||||
opt += fmt.Sprintf(",queues=%d", numQueues)
|
||||
if nic.NumQueues > 1 {
|
||||
opt += fmt.Sprintf(",queues=%d", nic.NumQueues)
|
||||
}
|
||||
}
|
||||
opt += fmt.Sprintf(",script=%s", upscript)
|
||||
opt += fmt.Sprintf(",downscript=%s", downscript)
|
||||
opt += fmt.Sprintf(",script=%s", nic.UpscriptPath)
|
||||
opt += fmt.Sprintf(",downscript=%s", nic.DownscriptPath)
|
||||
return opt, nil
|
||||
}
|
||||
|
||||
func getNicDeviceOption(drvOpt QemuOptions, nic jsonutils.JSONObject, input *GenerateStartOptionsInput, withAddr bool) string {
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
driver, _ := nic.GetString("driver")
|
||||
mac, _ := nic.GetString("mac")
|
||||
index, _ := nic.Int("index")
|
||||
vectors, _ := nic.Int("vectors")
|
||||
bw, _ := nic.Int("bw")
|
||||
numQueues, _ := nic.Int("num_queues")
|
||||
|
||||
cmd := fmt.Sprintf("-device %s", GetNicDeviceModel(driver))
|
||||
cmd += fmt.Sprintf(",id=netdev-%s", ifname)
|
||||
cmd += fmt.Sprintf(",netdev=%s", ifname)
|
||||
cmd += fmt.Sprintf(",mac=%s", mac)
|
||||
func getNicDeviceOption(
|
||||
drvOpt QemuOptions,
|
||||
nic *api.GuestnetworkJsonDesc,
|
||||
input *GenerateStartOptionsInput,
|
||||
withAddr bool,
|
||||
) string {
|
||||
cmd := fmt.Sprintf("-device %s", GetNicDeviceModel(nic.Driver))
|
||||
cmd += fmt.Sprintf(",id=netdev-%s", nic.Ifname)
|
||||
cmd += fmt.Sprintf(",netdev=%s", nic.Ifname)
|
||||
cmd += fmt.Sprintf(",mac=%s", nic.Mac)
|
||||
|
||||
if withAddr {
|
||||
disksLen := len(input.Disks)
|
||||
@@ -473,18 +467,18 @@ func getNicDeviceOption(drvOpt QemuOptions, nic jsonutils.JSONObject, input *Gen
|
||||
if input.IsolatedDevicesParams != nil {
|
||||
isoDevsLen = len(input.IsolatedDevicesParams.Devices)
|
||||
}
|
||||
cmd += fmt.Sprintf(",addr=0x%x", GetNicAddr(int(index), disksLen, isoDevsLen, input.IsVdiSpice))
|
||||
cmd += fmt.Sprintf(",addr=0x%x", GetNicAddr(int(nic.Index), disksLen, isoDevsLen, input.IsVdiSpice))
|
||||
}
|
||||
if driver == "virtio" {
|
||||
if numQueues > 1 {
|
||||
if nic.Driver == "virtio" {
|
||||
if nic.NumQueues > 1 {
|
||||
cmd += fmt.Sprintf(",mq=on")
|
||||
}
|
||||
if nic.Contains("vectors") {
|
||||
cmd += fmt.Sprintf(",vectors=%d", vectors)
|
||||
if nic.Vectors != nil {
|
||||
cmd += fmt.Sprintf(",vectors=%d", *nic.Vectors)
|
||||
}
|
||||
cmd += fmt.Sprintf("$(nic_speed %d)", bw)
|
||||
if bridge == input.OVNIntegrationBridge {
|
||||
cmd += fmt.Sprintf("$(nic_mtu %q)", bridge)
|
||||
cmd += fmt.Sprintf("$(nic_speed %d)", nic.Bw)
|
||||
if nic.Bridge == input.OVNIntegrationBridge {
|
||||
cmd += fmt.Sprintf("$(nic_mtu %q)", nic.Bridge)
|
||||
}
|
||||
}
|
||||
return cmd
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
)
|
||||
|
||||
// this is mainly to avoid direct improt of
|
||||
// yunion.io/x/onecloud/pkg/hostman/guestman
|
||||
|
||||
import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
)
|
||||
|
||||
type IHealthCheckReactor interface {
|
||||
ShutdownServers()
|
||||
}
|
||||
@@ -28,7 +29,7 @@ type IHealthCheckReactor interface {
|
||||
var HealthCheckReactor IHealthCheckReactor
|
||||
|
||||
type IGuestDescGetter interface {
|
||||
GetGuestNicDesc(mac, ip, port, bridge string, isCandidate bool) (jsonutils.JSONObject, jsonutils.JSONObject)
|
||||
GetGuestNicDesc(mac, ip, port, bridge string, isCandidate bool) (*desc.SGuestDesc, *api.GuestnetworkJsonDesc)
|
||||
}
|
||||
|
||||
var GuestDescGetter IGuestDescGetter
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
execlient "yunion.io/x/executor/client"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/service"
|
||||
"yunion.io/x/onecloud/pkg/hostman/downloader"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/guesthandlers"
|
||||
"yunion.io/x/onecloud/pkg/hostman/host_health"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
@@ -130,7 +130,7 @@ func (host *SHostService) RunService() {
|
||||
&metadata.Service{
|
||||
Address: options.HostOptions.Address,
|
||||
Port: options.HostOptions.Port + 1000,
|
||||
DescGetter: metadata.DescGetterFunc(func(ip string) jsonutils.JSONObject {
|
||||
DescGetter: metadata.DescGetterFunc(func(ip string) *desc.SGuestDesc {
|
||||
guestDesc, _ := guestman.GetGuestManager().GetGuestNicDesc("", ip, "", "", false)
|
||||
return guestDesc
|
||||
}),
|
||||
|
||||
@@ -20,7 +20,9 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
)
|
||||
|
||||
func NewDeployInfo(
|
||||
@@ -86,44 +88,90 @@ func ConvertRoutes(routes string) []types.SRoute {
|
||||
return ret
|
||||
}
|
||||
|
||||
func GuestDescToDeployDesc(guestDesc *jsonutils.JSONDict) (*GuestDesc, error) {
|
||||
func GuestdisksDescToDeployDesc(guestDisks []*api.GuestdiskJsonDesc) []*Disk {
|
||||
if len(guestDisks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
disks := make([]*Disk, len(guestDisks))
|
||||
for i, disk := range guestDisks {
|
||||
disks[i] = new(Disk)
|
||||
disks[i].DiskId = disk.DiskId
|
||||
disks[i].Driver = disk.Driver
|
||||
disks[i].CacheMode = disk.CacheMode
|
||||
disks[i].AioMode = disk.AioMode
|
||||
disks[i].Size = int64(disk.Size)
|
||||
disks[i].TemplateId = disk.TemplateId
|
||||
disks[i].ImagePath = disk.ImagePath
|
||||
disks[i].StorageId = disk.StorageId
|
||||
disks[i].Migrating = disk.Migrating
|
||||
disks[i].TargetStorageId = disk.TargetStorageId
|
||||
disks[i].Path = disk.Path
|
||||
disks[i].Format = disk.Format
|
||||
disks[i].Index = int32(disk.Index)
|
||||
disks[i].MergeSnapshot = disk.MergeSnapshot
|
||||
disks[i].Fs = disk.Fs
|
||||
disks[i].Mountpoint = disk.Mountpoint
|
||||
disks[i].Dev = disk.Dev
|
||||
}
|
||||
return disks
|
||||
}
|
||||
|
||||
func GuestnetworksDescToDeployDesc(guestnetworks []*api.GuestnetworkJsonDesc) []*Nic {
|
||||
if len(guestnetworks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
nics := make([]*Nic, len(guestnetworks))
|
||||
for i, nic := range guestnetworks {
|
||||
nics[i] = new(Nic)
|
||||
nics[i].Mac = nic.Mac
|
||||
nics[i].Ip = nic.Ip
|
||||
nics[i].Net = nic.Net
|
||||
nics[i].NetId = nic.NetId
|
||||
nics[i].Virtual = nic.Virtual
|
||||
nics[i].Gateway = nic.Gateway
|
||||
nics[i].Dns = nic.Dns
|
||||
nics[i].Domain = nic.Domain
|
||||
if nic.Routes != nil {
|
||||
nics[i].Routes = nic.Routes.String()
|
||||
}
|
||||
nics[i].Ifname = nic.Ifname
|
||||
nics[i].Masklen = int32(nic.Masklen)
|
||||
nics[i].Driver = nic.Driver
|
||||
nics[i].Bridge = nic.Bridge
|
||||
nics[i].WireId = nic.WireId
|
||||
nics[i].Vlan = int32(nic.Vlan)
|
||||
nics[i].Interface = nic.Interface
|
||||
nics[i].Bw = int32(nic.Bw)
|
||||
nics[i].Index = int32(nic.Index)
|
||||
nics[i].VirtualIps = nic.VirtualIps
|
||||
//nics[i].ExternelId = nic.ExternelId
|
||||
nics[i].TeamWith = nic.TeamWith
|
||||
if nic.Manual != nil {
|
||||
nics[i].Manual = *nic.Manual
|
||||
}
|
||||
nics[i].NicType = nic.NicType
|
||||
nics[i].LinkUp = nic.LinkUp
|
||||
nics[i].Mtu = int64(nic.Mtu)
|
||||
//nics[i].Name = nic.Name
|
||||
}
|
||||
|
||||
return nics
|
||||
}
|
||||
|
||||
func GuestDescToDeployDesc(guestDesc *desc.SGuestDesc) *GuestDesc {
|
||||
ret := new(GuestDesc)
|
||||
ret.Name, _ = guestDesc.GetString("name")
|
||||
ret.Domain, _ = guestDesc.GetString("domain")
|
||||
ret.Uuid, _ = guestDesc.GetString("uuid")
|
||||
ret.Hostname, _ = guestDesc.GetString("hostname")
|
||||
jnics, _ := guestDesc.Get("nics")
|
||||
jdisks, _ := guestDesc.Get("disks")
|
||||
jnicsStandby, _ := guestDesc.Get("nics_standby")
|
||||
|
||||
if jnics != nil {
|
||||
nics := make([]*Nic, 0)
|
||||
err := jnics.Unmarshal(&nics)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret.Nics = nics
|
||||
}
|
||||
ret.Name = guestDesc.Name
|
||||
ret.Domain = guestDesc.Domain
|
||||
ret.Uuid = guestDesc.Uuid
|
||||
ret.Hostname = guestDesc.Hostname
|
||||
ret.Nics = GuestnetworksDescToDeployDesc(guestDesc.Nics)
|
||||
ret.Disks = GuestdisksDescToDeployDesc(guestDesc.Disks)
|
||||
ret.NicsStandby = GuestnetworksDescToDeployDesc(guestDesc.NicsStandby)
|
||||
|
||||
if jdisks != nil {
|
||||
disks := make([]*Disk, 0)
|
||||
err := jdisks.Unmarshal(&disks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret.Disks = disks
|
||||
}
|
||||
|
||||
if jnicsStandby != nil {
|
||||
nicsStandby := make([]*Nic, 0)
|
||||
err := jnicsStandby.Unmarshal(&nicsStandby)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret.NicsStandby = nicsStandby
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return ret
|
||||
}
|
||||
|
||||
func NewReleaseInfo(distro, version, arch string) *ReleaseInfo {
|
||||
|
||||
@@ -23,11 +23,11 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/util/fileutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/iproute2"
|
||||
@@ -53,12 +53,12 @@ type IBridgeDriver interface {
|
||||
PersistentConfig() error
|
||||
DisableDHCPClient() (bool, error)
|
||||
|
||||
GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error
|
||||
GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error
|
||||
GenerateIfupScripts(scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error
|
||||
GenerateIfdownScripts(scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error
|
||||
RegisterHostlocalServer(mac, ip string) error
|
||||
|
||||
getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error)
|
||||
getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error)
|
||||
getUpScripts(nic *api.GuestnetworkJsonDesc, isSlave bool) (string, error)
|
||||
getDownScripts(nic *api.GuestnetworkJsonDesc, isSlave bool) (string, error)
|
||||
|
||||
Bridge() string
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func (d *SBaseBridgeDriver) saveFileExecutable(scriptPath, script string) error
|
||||
return os.Chmod(scriptPath, syscall.S_IRUSR|syscall.S_IWUSR|syscall.S_IXUSR)
|
||||
}
|
||||
|
||||
func (d *SBaseBridgeDriver) generateIfdownScripts(driver IBridgeDriver, scriptPath string, nic jsonutils.JSONObject, isSlave bool) error {
|
||||
func (d *SBaseBridgeDriver) generateIfdownScripts(driver IBridgeDriver, scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error {
|
||||
script, err := driver.getDownScripts(nic, isSlave)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getDownScripts")
|
||||
@@ -348,7 +348,7 @@ func (d *SBaseBridgeDriver) generateIfdownScripts(driver IBridgeDriver, scriptPa
|
||||
return d.saveFileExecutable(scriptPath, script)
|
||||
}
|
||||
|
||||
func (d *SBaseBridgeDriver) generateIfupScripts(driver IBridgeDriver, scriptPath string, nic jsonutils.JSONObject, isSlave bool) error {
|
||||
func (d *SBaseBridgeDriver) generateIfupScripts(driver IBridgeDriver, scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error {
|
||||
script, err := driver.getUpScripts(nic, isSlave)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/util/iproute2"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
@@ -83,15 +83,15 @@ func (l *SLinuxBridgeDriver) Interfaces() ([]string, error) {
|
||||
return infs, nil
|
||||
}
|
||||
|
||||
func (l *SLinuxBridgeDriver) GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error {
|
||||
func (l *SLinuxBridgeDriver) GenerateIfdownScripts(scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error {
|
||||
return l.generateIfdownScripts(l, scriptPath, nic, isSlave)
|
||||
}
|
||||
|
||||
func (l *SLinuxBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error {
|
||||
func (l *SLinuxBridgeDriver) GenerateIfupScripts(scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error {
|
||||
return l.generateIfupScripts(l, scriptPath, nic, isSlave)
|
||||
}
|
||||
|
||||
func (l *SLinuxBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) {
|
||||
func (l *SLinuxBridgeDriver) getUpScripts(nic *api.GuestnetworkJsonDesc, isSlave bool) (string, error) {
|
||||
s := "#!/bin/bash\n\n"
|
||||
s += fmt.Sprintf("switch='%s'\n", l.bridge)
|
||||
if options.HostOptions.TunnelPaddingBytes > 0 {
|
||||
@@ -103,7 +103,7 @@ func (l *SLinuxBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (l *SLinuxBridgeDriver) getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) {
|
||||
func (l *SLinuxBridgeDriver) getDownScripts(nic *api.GuestnetworkJsonDesc, isSlave bool) (string, error) {
|
||||
s := "#!/bin/sh\n\n"
|
||||
s += fmt.Sprintf("switch='%s'\n", l.bridge)
|
||||
s += "brctl show ${switch} | grep $1\n"
|
||||
|
||||
@@ -18,12 +18,12 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/compute"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/hostman/system_service"
|
||||
"yunion.io/x/onecloud/pkg/util/bwutils"
|
||||
@@ -118,23 +118,23 @@ func (d *SOVSBridgeDriver) PersistentConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *SOVSBridgeDriver) GenerateIfdownScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error {
|
||||
func (o *SOVSBridgeDriver) GenerateIfdownScripts(scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error {
|
||||
return o.generateIfdownScripts(o, scriptPath, nic, isSlave)
|
||||
}
|
||||
|
||||
func (o *SOVSBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.JSONObject, isSlave bool) error {
|
||||
func (o *SOVSBridgeDriver) GenerateIfupScripts(scriptPath string, nic *api.GuestnetworkJsonDesc, isSlave bool) error {
|
||||
return o.generateIfupScripts(o, scriptPath, nic, isSlave)
|
||||
}
|
||||
|
||||
func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) {
|
||||
func (o *SOVSBridgeDriver) getUpScripts(nic *api.GuestnetworkJsonDesc, isSlave bool) (string, error) {
|
||||
var (
|
||||
bridge = o.bridge.String()
|
||||
ifname, _ = nic.GetString("ifname")
|
||||
ip, _ = nic.GetString("ip")
|
||||
mac, _ = nic.GetString("mac")
|
||||
netId, _ = nic.GetString("net_id")
|
||||
vlan, _ = nic.Int("vlan")
|
||||
vpcProvider, _ = nic.GetString("vpc", "provider")
|
||||
bridge = o.bridge.String()
|
||||
ifname = nic.Ifname
|
||||
ip = nic.Ip
|
||||
mac = nic.Mac
|
||||
netId = nic.NetId
|
||||
vlan = nic.Vlan
|
||||
vpcProvider = nic.Vpc.Provider
|
||||
)
|
||||
|
||||
if vpcProvider == compute.VPC_PROVIDER_OVN {
|
||||
@@ -148,13 +148,13 @@ func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool)
|
||||
s += fmt.Sprintf("MAC='%s'\n", mac)
|
||||
s += fmt.Sprintf("VLAN_ID=%d\n", vlan)
|
||||
s += fmt.Sprintf("NET_ID=%s\n", netId)
|
||||
limit, burst, err := bwutils.GetOvsBwValues(nic)
|
||||
limit, burst, err := bwutils.GetOvsBwValues(nic.Bw, nic.Ip)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
s += fmt.Sprintf("LIMIT=%d\n", limit)
|
||||
s += fmt.Sprintf("BURST=%d\n", burst)
|
||||
bwDownload, err := bwutils.GetDownloadBwValue(nic, options.HostOptions.BwDownloadBandwidth)
|
||||
bwDownload, err := bwutils.GetDownloadBwValue(nic.Bw, nic.Ip, nic.Ifname, options.HostOptions.BwDownloadBandwidth)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -196,13 +196,13 @@ func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (o *SOVSBridgeDriver) getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) {
|
||||
func (o *SOVSBridgeDriver) getDownScripts(nic *api.GuestnetworkJsonDesc, isSlave bool) (string, error) {
|
||||
var (
|
||||
bridge = o.bridge.String()
|
||||
ifname, _ = nic.GetString("ifname")
|
||||
ip, _ = nic.GetString("ip")
|
||||
mac, _ = nic.GetString("mac")
|
||||
vlan, _ = nic.Int("vlan")
|
||||
bridge = o.bridge.String()
|
||||
ifname = nic.Ifname
|
||||
ip = nic.Ip
|
||||
mac = nic.Mac
|
||||
vlan = nic.Vlan
|
||||
)
|
||||
|
||||
s := "#!/bin/bash\n\n"
|
||||
|
||||
@@ -20,11 +20,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
guestman "yunion.io/x/onecloud/pkg/hostman/guestman/types"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
"yunion.io/x/onecloud/pkg/util/dhcp"
|
||||
@@ -89,10 +91,83 @@ func (s *SGuestDHCPServer) RelaySetup(addr string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SGuestDHCPServer) getGuestConfig(guestDesc, guestNic jsonutils.JSONObject) *dhcp.ResponseConfig {
|
||||
func gusetnetworkJsonDescToServerNic(nicdesc *types.SServerNic, guestNic *api.GuestnetworkJsonDesc) error {
|
||||
if err := guestNic.Routes.Unmarshal(nicdesc.Routes); err != nil {
|
||||
return err
|
||||
}
|
||||
nicdesc.Index = int(guestNic.Index)
|
||||
nicdesc.Bridge = guestNic.Bridge
|
||||
nicdesc.Domain = guestNic.Domain
|
||||
nicdesc.Ip = guestNic.Ip
|
||||
nicdesc.Vlan = guestNic.Vlan
|
||||
nicdesc.Driver = guestNic.Driver
|
||||
nicdesc.Masklen = int(guestNic.Masklen)
|
||||
nicdesc.Virtual = guestNic.Virtual
|
||||
if guestNic.Manual != nil {
|
||||
nicdesc.Manual = *guestNic.Manual
|
||||
}
|
||||
nicdesc.WireId = guestNic.WireId
|
||||
nicdesc.NetId = guestNic.NetId
|
||||
nicdesc.Mac = guestNic.Mac
|
||||
nicdesc.Mtu = guestNic.Mtu
|
||||
nicdesc.Dns = guestNic.Dns
|
||||
nicdesc.Ntp = guestNic.Ntp
|
||||
nicdesc.Net = guestNic.Net
|
||||
nicdesc.Interface = guestNic.Interface
|
||||
nicdesc.Gateway = guestNic.Gateway
|
||||
nicdesc.Ifname = guestNic.Ifname
|
||||
nicdesc.NicType = guestNic.NicType
|
||||
nicdesc.LinkUp = guestNic.LinkUp
|
||||
nicdesc.TeamWith = guestNic.TeamWith
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetMainNic(nics []*api.GuestnetworkJsonDesc) (*api.GuestnetworkJsonDesc, error) {
|
||||
var mainIp netutils.IPV4Addr
|
||||
var mainNic *api.GuestnetworkJsonDesc
|
||||
for _, n := range nics {
|
||||
if n.Gateway != "" {
|
||||
ipInt, err := netutils.NewIPV4Addr(n.Ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mainIp == 0 {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
} else if !netutils.IsPrivate(ipInt) && netutils.IsPrivate(mainIp) {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
}
|
||||
}
|
||||
}
|
||||
if mainNic != nil {
|
||||
return mainNic, nil
|
||||
}
|
||||
for _, n := range nics {
|
||||
ipInt, err := netutils.NewIPV4Addr(n.Ip)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "netutils.NewIPV4Addr %s", n.Ip)
|
||||
}
|
||||
if mainIp == 0 {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
} else if !netutils.IsPrivate(ipInt) && netutils.IsPrivate(mainIp) {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
}
|
||||
}
|
||||
if mainNic != nil {
|
||||
return mainNic, nil
|
||||
}
|
||||
return nil, errors.Wrap(errors.ErrInvalidStatus, "no valid nic")
|
||||
}
|
||||
|
||||
func (s *SGuestDHCPServer) getGuestConfig(
|
||||
guestDesc *desc.SGuestDesc, guestNic *api.GuestnetworkJsonDesc,
|
||||
) *dhcp.ResponseConfig {
|
||||
var nicdesc = new(types.SServerNic)
|
||||
if err := guestNic.Unmarshal(nicdesc); err != nil {
|
||||
log.Errorln(err)
|
||||
if err := gusetnetworkJsonDescToServerNic(nicdesc, guestNic); err != nil {
|
||||
log.Errorf("failed convert server nic desc")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -105,26 +180,26 @@ func (s *SGuestDHCPServer) getGuestConfig(guestDesc, guestNic jsonutils.JSONObje
|
||||
conf.ServerIP = net.ParseIP(v4Ip.NetAddr(int8(masklen)).String())
|
||||
conf.SubnetMask = net.ParseIP(netutils2.Netlen2Mask(int(masklen)))
|
||||
conf.BroadcastAddr = v4Ip.BroadcastAddr(int8(masklen)).ToBytes()
|
||||
conf.Hostname, _ = guestDesc.GetString("name")
|
||||
if hostname, _ := guestDesc.GetString("hostname"); len(hostname) > 0 {
|
||||
conf.Hostname = hostname
|
||||
conf.Hostname = guestDesc.Name
|
||||
if len(guestDesc.Hostname) > 0 {
|
||||
conf.Hostname = guestDesc.Hostname
|
||||
}
|
||||
conf.Domain = nicdesc.Domain
|
||||
|
||||
// get main ip
|
||||
guestNics, _ := guestDesc.GetArray("nics")
|
||||
manNic, err := netutils2.GetMainNic(guestNics)
|
||||
guestNics := guestDesc.Nics
|
||||
manNic, err := GetMainNic(guestNics)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
mainIp, _ := manNic.GetString("ip")
|
||||
mainIp := manNic.Ip
|
||||
|
||||
var route = [][]string{}
|
||||
if len(nicdesc.Gateway) > 0 && mainIp == nicIp {
|
||||
conf.Gateway = net.ParseIP(nicdesc.Gateway)
|
||||
|
||||
osName, _ := guestDesc.GetString("os_name")
|
||||
osName := guestDesc.OsName
|
||||
if len(osName) == 0 {
|
||||
osName = "Linux"
|
||||
}
|
||||
@@ -155,7 +230,7 @@ func (s *SGuestDHCPServer) getGuestConfig(guestDesc, guestNic jsonutils.JSONObje
|
||||
conf.MTU = uint16(nicdesc.Mtu)
|
||||
}
|
||||
|
||||
conf.OsName, _ = guestDesc.GetString("os_name")
|
||||
conf.OsName = guestDesc.OsName
|
||||
conf.LeaseTime = time.Duration(options.HostOptions.DhcpLeaseTime) * time.Second
|
||||
conf.RenewalTime = time.Duration(options.HostOptions.DhcpRenewalTime) * time.Second
|
||||
return conf
|
||||
@@ -175,7 +250,7 @@ func (s *SGuestDHCPServer) getConfig(pkt dhcp.Packet) *dhcp.ResponseConfig {
|
||||
if guestNic == nil {
|
||||
guestDesc, guestNic = guestman.GuestDescGetter.GetGuestNicDesc(mac, ip, port, s.iface, !isCandidate)
|
||||
}
|
||||
if guestNic != nil && !jsonutils.QueryBoolean(guestNic, "virtual", false) {
|
||||
if guestNic != nil && !guestNic.Virtual {
|
||||
return s.getGuestConfig(guestDesc, guestNic)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostinfo/hostconsts"
|
||||
"yunion.io/x/onecloud/pkg/hostman/options"
|
||||
@@ -173,31 +174,29 @@ func (s *SGuestMonitorCollector) GetGuests() map[string]*SGuestMonitor {
|
||||
}
|
||||
pid := guest.GetPid()
|
||||
if pid > 0 {
|
||||
guestName, _ := guest.Desc.GetString("name")
|
||||
guestName := guest.Desc.Name
|
||||
guestId := guest.GetId()
|
||||
nicsDesc, _ := guest.Desc.GetArray("nics")
|
||||
nics := make([]jsonutils.JSONObject, len(nicsDesc))
|
||||
copy(nics, nicsDesc)
|
||||
vcpuCount, _ := guest.Desc.Int("cpu")
|
||||
nicsDesc := guest.Desc.Nics
|
||||
vcpuCount := guest.Desc.Cpu
|
||||
gm, ok := s.monitors[guestId]
|
||||
if ok && gm.Pid == pid {
|
||||
delete(s.monitors, guestId)
|
||||
gm.UpdateVmName(guestName)
|
||||
gm.UpdateNicsDesc(nics)
|
||||
gm.UpdateNicsDesc(nicsDesc)
|
||||
gm.UpdateCpuCount(int(vcpuCount))
|
||||
} else {
|
||||
delete(s.monitors, guestId)
|
||||
gm, err = NewGuestMonitor(guestName, guestId, pid, nics, int(vcpuCount))
|
||||
gm, err = NewGuestMonitor(guestName, guestId, pid, nicsDesc, int(vcpuCount))
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return true
|
||||
}
|
||||
}
|
||||
gm.ScalingGroupId, _ = guest.Desc.GetString("scaling_group_id")
|
||||
gm.Tenant, _ = guest.Desc.GetString("tenant")
|
||||
gm.TenantId, _ = guest.Desc.GetString("tenant_id")
|
||||
gm.DomainId, _ = guest.Desc.GetString("domain_id")
|
||||
gm.ProjectDomain, _ = guest.Desc.GetString("project_domain")
|
||||
gm.ScalingGroupId = guest.Desc.ScalingGroupId
|
||||
gm.Tenant = guest.Desc.Tenant
|
||||
gm.TenantId = guest.Desc.TenantId
|
||||
gm.DomainId = guest.Desc.DomainId
|
||||
gm.ProjectDomain = guest.Desc.ProjectDomain
|
||||
|
||||
gms[guestId] = gm
|
||||
}
|
||||
@@ -423,7 +422,7 @@ type SGuestMonitor struct {
|
||||
Name string
|
||||
Id string
|
||||
Pid int
|
||||
Nics []jsonutils.JSONObject
|
||||
Nics []*api.GuestnetworkJsonDesc
|
||||
CpuCnt int
|
||||
Ip string
|
||||
Process *process.Process
|
||||
@@ -434,11 +433,11 @@ type SGuestMonitor struct {
|
||||
ProjectDomain string
|
||||
}
|
||||
|
||||
func NewGuestMonitor(name, id string, pid int, nics []jsonutils.JSONObject, cpuCount int,
|
||||
func NewGuestMonitor(name, id string, pid int, nics []*api.GuestnetworkJsonDesc, cpuCount int,
|
||||
) (*SGuestMonitor, error) {
|
||||
var ip string
|
||||
if len(nics) >= 1 {
|
||||
ip, _ = nics[0].GetString("ip")
|
||||
ip = nics[0].Ip
|
||||
}
|
||||
proc, err := process.NewProcess(int32(pid))
|
||||
if err != nil {
|
||||
@@ -451,7 +450,7 @@ func (m *SGuestMonitor) UpdateVmName(name string) {
|
||||
m.Name = name
|
||||
}
|
||||
|
||||
func (m *SGuestMonitor) UpdateNicsDesc(nics []jsonutils.JSONObject) {
|
||||
func (m *SGuestMonitor) UpdateNicsDesc(nics []*api.GuestnetworkJsonDesc) {
|
||||
m.Nics = nics
|
||||
}
|
||||
|
||||
@@ -473,7 +472,7 @@ func (m *SGuestMonitor) Netio() jsonutils.JSONObject {
|
||||
|
||||
var res = jsonutils.NewArray()
|
||||
for i, nic := range m.Nics {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
ifname := nic.Ifname
|
||||
var nicStat *psnet.IOCountersStat
|
||||
for j, netstat := range netstats {
|
||||
if netstat.Name == ifname {
|
||||
@@ -486,7 +485,7 @@ func (m *SGuestMonitor) Netio() jsonutils.JSONObject {
|
||||
data := jsonutils.NewDict()
|
||||
meta := jsonutils.NewDict()
|
||||
|
||||
ip, _ := nic.GetString("ip")
|
||||
ip := nic.Ip
|
||||
ipv4, _ := netutils.NewIPV4Addr(ip)
|
||||
if netutils.IsExitAddress(ipv4) {
|
||||
meta.Set("ip_type", jsonutils.NewString("external"))
|
||||
@@ -494,7 +493,7 @@ func (m *SGuestMonitor) Netio() jsonutils.JSONObject {
|
||||
meta.Set("ip_type", jsonutils.NewString("internal"))
|
||||
}
|
||||
|
||||
netId, _ := nic.GetString("net_id")
|
||||
netId := nic.NetId
|
||||
meta.Set("ip", jsonutils.NewString(ip))
|
||||
meta.Set("index", jsonutils.NewInt(int64(i)))
|
||||
meta.Set("ifname", jsonutils.NewString(ifname))
|
||||
|
||||
@@ -24,12 +24,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
@@ -42,12 +42,12 @@ func Start(app *appsrv.Application, s *Service) {
|
||||
}
|
||||
|
||||
type DescGetter interface {
|
||||
Get(ip string) (guestDesc jsonutils.JSONObject)
|
||||
Get(ip string) (guestDesc *desc.SGuestDesc)
|
||||
}
|
||||
|
||||
type DescGetterFunc func(ip string) (guestDesc jsonutils.JSONObject)
|
||||
type DescGetterFunc func(ip string) (guestDesc *desc.SGuestDesc)
|
||||
|
||||
func (f DescGetterFunc) Get(ip string) (guestDesc jsonutils.JSONObject) {
|
||||
func (f DescGetterFunc) Get(ip string) (guestDesc *desc.SGuestDesc) {
|
||||
return f(ip)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ type Service struct {
|
||||
DescGetter DescGetter
|
||||
}
|
||||
|
||||
func (s *Service) getGuestNicDesc(r *http.Request) (guestDesc jsonutils.JSONObject) {
|
||||
func (s *Service) getGuestDesc(r *http.Request) (guestDesc *desc.SGuestDesc) {
|
||||
ip, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
panic(errors.Wrapf(err, "SplitHostPort %s", r.RemoteAddr))
|
||||
@@ -88,22 +88,21 @@ func (s *Service) versionOnly(ctx context.Context, w http.ResponseWriter, r *htt
|
||||
}
|
||||
|
||||
func (s *Service) userData(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
guestDesc := s.getGuestNicDesc(r)
|
||||
guestDesc := s.getGuestDesc(r)
|
||||
if guestDesc == nil {
|
||||
hostutils.Response(ctx, w, "")
|
||||
return
|
||||
}
|
||||
|
||||
if !guestDesc.Contains("user_data") {
|
||||
guestUserData := guestDesc.UserData
|
||||
if guestUserData == "" {
|
||||
hostutils.Response(ctx, w, "")
|
||||
return
|
||||
}
|
||||
|
||||
guestUserData, _ := guestDesc.GetString("user_data")
|
||||
userDataDecoded, err := base64.StdEncoding.DecodeString(guestUserData)
|
||||
if err != nil {
|
||||
guestId, _ := guestDesc.GetString("id")
|
||||
log.Errorf("Error format user_data %s, %s", guestId, guestUserData)
|
||||
log.Errorf("Error format user_data %s, %s", guestDesc.Uuid, guestUserData)
|
||||
hostutils.Response(ctx, w, "")
|
||||
return
|
||||
}
|
||||
@@ -111,7 +110,7 @@ func (s *Service) userData(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
}
|
||||
|
||||
func (s *Service) metaData(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
guestDesc := s.getGuestNicDesc(r)
|
||||
guestDesc := s.getGuestDesc(r)
|
||||
if guestDesc == nil {
|
||||
hostutils.Response(ctx, w, "")
|
||||
return
|
||||
@@ -134,13 +133,13 @@ func (s *Service) metaData(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
//"placement/", "public-keys/",
|
||||
//"reservation-id", "security-groups", "password",
|
||||
}
|
||||
if guestDesc.Contains("pubkey") {
|
||||
if guestDesc.Pubkey != "" {
|
||||
resNames = append(resNames, "public-keys/")
|
||||
}
|
||||
if guestDesc.Contains("zone") {
|
||||
if guestDesc.Zone != "" {
|
||||
resNames = append(resNames, "placement/")
|
||||
}
|
||||
if guestDesc.Contains("secgroup") {
|
||||
if guestDesc.Secgroup != "" {
|
||||
resNames = append(resNames, "security-groups/")
|
||||
}
|
||||
hostutils.Response(ctx, w, strings.Join(resNames, "\n"))
|
||||
@@ -149,7 +148,7 @@ func (s *Service) metaData(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
resName := req[0]
|
||||
switch resName {
|
||||
case "public-keys":
|
||||
if guestDesc.Contains("pubkey") {
|
||||
if guestDesc.Pubkey != "" {
|
||||
if len(req) == 1 {
|
||||
hostutils.Response(ctx, w, "0=my-public-key")
|
||||
return
|
||||
@@ -157,49 +156,45 @@ func (s *Service) metaData(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
hostutils.Response(ctx, w, "openssh-key")
|
||||
return
|
||||
} else if len(req) == 3 {
|
||||
pubkey, _ := guestDesc.GetString("pubkeu")
|
||||
pubkey := guestDesc.Pubkey
|
||||
hostutils.Response(ctx, w, pubkey)
|
||||
return
|
||||
}
|
||||
}
|
||||
case "hostname", "public-hostname", "local-hostname":
|
||||
guestName, _ := guestDesc.GetString("name")
|
||||
hostutils.Response(ctx, w, guestName)
|
||||
hostutils.Response(ctx, w, guestDesc.Name)
|
||||
return
|
||||
case "instance-id":
|
||||
guestUUID, _ := guestDesc.GetString("uuid")
|
||||
hostutils.Response(ctx, w, guestUUID)
|
||||
hostutils.Response(ctx, w, guestDesc.Uuid)
|
||||
return
|
||||
case "instance-type":
|
||||
flavor, err := guestDesc.GetString("flavor")
|
||||
if err != nil {
|
||||
flavor := guestDesc.Flavor
|
||||
if flavor == "" {
|
||||
flavor = "customized"
|
||||
}
|
||||
hostutils.Response(ctx, w, flavor)
|
||||
return
|
||||
case "mac":
|
||||
macs := make([]string, 0)
|
||||
guestNics, _ := guestDesc.GetArray("nics")
|
||||
guestNics := guestDesc.Nics
|
||||
for _, nic := range guestNics {
|
||||
nicMac, _ := nic.GetString("mac")
|
||||
macs = append(macs, nicMac)
|
||||
macs = append(macs, nic.Mac)
|
||||
}
|
||||
hostutils.Response(ctx, w, strings.Join(macs, "\n"))
|
||||
return
|
||||
case "local-ipv4":
|
||||
ips := make([]string, 0)
|
||||
guestNics, _ := guestDesc.GetArray("nics")
|
||||
guestNics := guestDesc.Nics
|
||||
for _, nic := range guestNics {
|
||||
nicip, _ := nic.GetString("ip")
|
||||
ips = append(ips, nicip)
|
||||
ips = append(ips, nic.Ip)
|
||||
}
|
||||
hostutils.Response(ctx, w, strings.Join(ips, "\n"))
|
||||
return
|
||||
case "local-sub-ipv4s":
|
||||
ips := make([]string, 0)
|
||||
guestNics, _ := guestDesc.GetArray("nics")
|
||||
guestNics := guestDesc.Nics
|
||||
for _, nic := range guestNics {
|
||||
nas, _ := nic.GetArray("networkaddresses")
|
||||
nas, _ := nic.Networkaddresses.GetArray()
|
||||
for _, na := range nas {
|
||||
if typ, _ := na.GetString("type"); typ == "sub_ip" {
|
||||
ip, _ := na.GetString("ip_addr")
|
||||
@@ -213,31 +208,28 @@ func (s *Service) metaData(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
case "public-ipv4":
|
||||
ips := make([]string, 0)
|
||||
guestNics, _ := guestDesc.GetArray("nics")
|
||||
guestNics := guestDesc.Nics
|
||||
for _, nic := range guestNics {
|
||||
nicip, _ := nic.GetString("ip")
|
||||
ipv4, _ := netutils.NewIPV4Addr(nicip)
|
||||
ipv4, _ := netutils.NewIPV4Addr(nic.Ip)
|
||||
if !netutils.IsPrivate(ipv4) {
|
||||
ips = append(ips, nicip)
|
||||
ips = append(ips, nic.Ip)
|
||||
}
|
||||
}
|
||||
hostutils.Response(ctx, w, strings.Join(ips, "\n"))
|
||||
return
|
||||
case "placement":
|
||||
if guestDesc.Contains("zone") {
|
||||
if guestDesc.Zone != "" {
|
||||
if len(req) == 1 {
|
||||
hostutils.Response(ctx, w, "availability-zone")
|
||||
return
|
||||
} else if len(req) == 2 && req[1] == "availability-zone" {
|
||||
guestZone, _ := guestDesc.GetString("zone")
|
||||
hostutils.Response(ctx, w, guestZone)
|
||||
hostutils.Response(ctx, w, guestDesc.Zone)
|
||||
return
|
||||
}
|
||||
}
|
||||
case "security-groups":
|
||||
if guestDesc.Contains("secgroup") {
|
||||
guestSecgroup, _ := guestDesc.GetString("secgroup")
|
||||
hostutils.Response(ctx, w, guestSecgroup)
|
||||
if guestDesc.Secgroup != "" {
|
||||
hostutils.Response(ctx, w, guestDesc.Secgroup)
|
||||
return
|
||||
}
|
||||
case "ami-launch-index":
|
||||
@@ -258,16 +250,14 @@ func (s *Service) metaData(ctx context.Context, w http.ResponseWriter, r *http.R
|
||||
}
|
||||
}
|
||||
case "block-device-mapping":
|
||||
guestDisks, _ := guestDesc.GetArray("disks")
|
||||
guestDisks := guestDesc.Disks
|
||||
swapDisks := make([]string, 0)
|
||||
dataDisk := make([]string, 0)
|
||||
for _, d := range guestDisks {
|
||||
fs, err := d.GetString("fs")
|
||||
idx, _ := d.Int("index")
|
||||
if err != nil && fs == "swap" {
|
||||
swapDisks = append(swapDisks, strconv.Itoa(int(idx)))
|
||||
if d.Fs == "swap" {
|
||||
swapDisks = append(swapDisks, strconv.Itoa(int(d.Index)))
|
||||
} else {
|
||||
dataDisk = append(dataDisk, strconv.Itoa(int(idx)))
|
||||
dataDisk = append(dataDisk, strconv.Itoa(int(d.Index)))
|
||||
}
|
||||
}
|
||||
if len(req) == 1 {
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
|
||||
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
"yunion.io/x/onecloud/pkg/util/qemuimg"
|
||||
@@ -63,7 +64,7 @@ type IDisk interface {
|
||||
PostCreateFromImageFuse()
|
||||
CreateSnapshot(snapshotId string, encryptKey string, encFormat qemuimg.TEncryptFormat, encAlg seclib2.TSymEncAlg) error
|
||||
DeleteSnapshot(snapshotId, convertSnapshot string, pendingDelete bool) error
|
||||
DeployGuestFs(diskInfo *deployapi.DiskInfo, guestDesc *jsonutils.JSONDict,
|
||||
DeployGuestFs(diskInfo *deployapi.DiskInfo, guestDesc *desc.SGuestDesc,
|
||||
deployInfo *deployapi.DeployInfo) (jsonutils.JSONObject, error)
|
||||
|
||||
GetBackupDir() string
|
||||
@@ -124,12 +125,9 @@ func (d *SBaseDisk) GetZoneId() string {
|
||||
return d.Storage.GetZoneId()
|
||||
}
|
||||
|
||||
func (d *SBaseDisk) DeployGuestFs(diskInfo *deployapi.DiskInfo, guestDesc *jsonutils.JSONDict,
|
||||
func (d *SBaseDisk) DeployGuestFs(diskInfo *deployapi.DiskInfo, guestDesc *desc.SGuestDesc,
|
||||
deployInfo *deployapi.DeployInfo) (jsonutils.JSONObject, error) {
|
||||
deployGuestDesc, err := deployapi.GuestDescToDeployDesc(guestDesc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "guest desc to deploy desc")
|
||||
}
|
||||
deployGuestDesc := deployapi.GuestDescToDeployDesc(guestDesc)
|
||||
ret, err := deployclient.GetDeployClient().DeployGuestFs(
|
||||
context.Background(), &deployapi.DeployParams{
|
||||
DiskInfo: diskInfo,
|
||||
|
||||
@@ -139,7 +139,7 @@ type IStorage interface {
|
||||
GetImgsaveBackupPath() string
|
||||
|
||||
DestinationPrepareMigrate(ctx context.Context, liveMigrate bool, disksUri string, snapshotsUri string,
|
||||
disksBackingFile, srcSnapshots jsonutils.JSONObject, rebaseDisks bool, diskDesc jsonutils.JSONObject, serverId string, idx, totalDiskCount int, encInfo *apis.SEncryptInfo) error
|
||||
disksBackingFile, srcSnapshots jsonutils.JSONObject, rebaseDisks bool, diskDesc *api.GuestdiskJsonDesc, serverId string, idx, totalDiskCount int, encInfo *apis.SEncryptInfo) error
|
||||
|
||||
Accessible() error
|
||||
Detach() error
|
||||
@@ -431,7 +431,7 @@ func (s *SBaseStorage) createDiskFromBackup(ctx context.Context, disk IDisk, inp
|
||||
|
||||
func (s *SBaseStorage) DestinationPrepareMigrate(
|
||||
ctx context.Context, liveMigrate bool, disksUri string, snapshotsUri string,
|
||||
disksBackingFile, srcSnapshots jsonutils.JSONObject, rebaseDisks bool, diskinfo jsonutils.JSONObject, serverId string, idx, totalDiskCount int, encInfo *apis.SEncryptInfo,
|
||||
disksBackingFile, srcSnapshots jsonutils.JSONObject, rebaseDisks bool, diskinfo *api.GuestdiskJsonDesc, serverId string, idx, totalDiskCount int, encInfo *apis.SEncryptInfo,
|
||||
) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -519,12 +519,12 @@ func (s *SLocalStorage) DestinationPrepareMigrate(
|
||||
ctx context.Context, liveMigrate bool, disksUri string, snapshotsUri string,
|
||||
disksBackingFile, srcSnapshots jsonutils.JSONObject,
|
||||
rebaseDisks bool,
|
||||
diskinfo jsonutils.JSONObject,
|
||||
diskinfo *api.GuestdiskJsonDesc,
|
||||
serverId string, idx, totalDiskCount int,
|
||||
encInfo *apis.SEncryptInfo,
|
||||
) error {
|
||||
var (
|
||||
diskId, _ = diskinfo.GetString("disk_id")
|
||||
diskId = diskinfo.DiskId
|
||||
snapshots, _ = srcSnapshots.GetArray(diskId)
|
||||
disk = s.CreateDisk(diskId)
|
||||
)
|
||||
@@ -534,7 +534,7 @@ func (s *SLocalStorage) DestinationPrepareMigrate(
|
||||
"Storage %s create disk %s failed", s.GetId(), diskId)
|
||||
}
|
||||
|
||||
templateId, _ := diskinfo.GetString("template_id")
|
||||
templateId := diskinfo.TemplateId
|
||||
// prepare disk snapshot dir
|
||||
if len(snapshots) > 0 && !fileutils2.Exists(disk.GetSnapshotDir()) {
|
||||
output, err := procutils.NewCommand("mkdir", "-p", disk.GetSnapshotDir()).Output()
|
||||
@@ -545,8 +545,8 @@ func (s *SLocalStorage) DestinationPrepareMigrate(
|
||||
|
||||
// create snapshots form remote url
|
||||
var (
|
||||
diskStorageId, _ = diskinfo.GetString("storage_id")
|
||||
baseImagePath string
|
||||
diskStorageId = diskinfo.StorageId
|
||||
baseImagePath string
|
||||
)
|
||||
for i, snapshotId := range snapshots {
|
||||
snapId, _ := snapshotId.GetString()
|
||||
@@ -584,8 +584,7 @@ func (s *SLocalStorage) DestinationPrepareMigrate(
|
||||
if liveMigrate {
|
||||
// create local disk
|
||||
backingFile, _ := disksBackingFile.GetString(diskId)
|
||||
size, _ := diskinfo.Int("size")
|
||||
_, err := disk.CreateRaw(ctx, int(size), "qcow2", "", encInfo, "", backingFile)
|
||||
_, err := disk.CreateRaw(ctx, int(diskinfo.Size), "qcow2", "", encInfo, "", backingFile)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return err
|
||||
@@ -626,8 +625,7 @@ func (s *SLocalStorage) DestinationPrepareMigrate(
|
||||
return err
|
||||
}
|
||||
}
|
||||
diskDesc, _ := diskinfo.(*jsonutils.JSONDict)
|
||||
diskDesc.Set("path", jsonutils.NewString(disk.GetPath()))
|
||||
diskinfo.Path = disk.GetPath()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,12 @@
|
||||
package bwutils
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
)
|
||||
|
||||
func GetBwValue(nicDesc jsonutils.JSONObject) int {
|
||||
bw, err := nicDesc.Int("bw")
|
||||
if err != nil {
|
||||
ip, err := nicDesc.GetString("ip")
|
||||
if err != nil {
|
||||
func GetBwValue(bw int, ip string) int {
|
||||
if bw > 0 {
|
||||
if ip == "" {
|
||||
bw = 1
|
||||
} else {
|
||||
ipv4, err := netutils.NewIPV4Addr(ip)
|
||||
@@ -37,16 +34,14 @@ func GetBwValue(nicDesc jsonutils.JSONObject) int {
|
||||
return int(bw)
|
||||
}
|
||||
|
||||
func GetDownloadBwValue(nicDesc jsonutils.JSONObject, bwDownloadBandwidth int) (int, error) {
|
||||
ip, _ := nicDesc.GetString("ip")
|
||||
ifname, _ := nicDesc.GetString("ifname")
|
||||
func GetDownloadBwValue(bw int, ip, ifname string, bwDownloadBandwidth int) (int, error) {
|
||||
if len(ip) > 0 {
|
||||
ipv4, err := netutils.NewIPV4Addr(ip)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if netutils.IsExitAddress(ipv4) && len(ifname) > 0 && bwDownloadBandwidth > 0 {
|
||||
bw := GetBwValue(nicDesc)
|
||||
bw = GetBwValue(bw, ip)
|
||||
if bw > bwDownloadBandwidth {
|
||||
return bw, nil
|
||||
} else {
|
||||
@@ -57,11 +52,10 @@ func GetDownloadBwValue(nicDesc jsonutils.JSONObject, bwDownloadBandwidth int) (
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func GetOvsBwValues(nicDesc jsonutils.JSONObject) (int, int, error) {
|
||||
func GetOvsBwValues(bw int, ip string) (int, int, error) {
|
||||
var bwOvs int
|
||||
bw := GetBwValue(nicDesc)
|
||||
ip, err := nicDesc.GetString("ip")
|
||||
if err == nil {
|
||||
bw = GetBwValue(bw, ip)
|
||||
if ip != "" {
|
||||
ipv4, err := netutils.NewIPV4Addr(ip)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
@@ -135,48 +134,6 @@ func GetMainNicFromDeployApi(nics []*types.SServerNic) (*types.SServerNic, error
|
||||
return nil, errors.Wrap(errors.ErrInvalidStatus, "no valid nic")
|
||||
}
|
||||
|
||||
func GetMainNic(nics []jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
var mainIp netutils.IPV4Addr
|
||||
var mainNic jsonutils.JSONObject
|
||||
for _, n := range nics {
|
||||
if n.Contains("gateway") {
|
||||
ip, _ := n.GetString("ip")
|
||||
ipInt, err := netutils.NewIPV4Addr(ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mainIp == 0 {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
} else if !netutils.IsPrivate(ipInt) && netutils.IsPrivate(mainIp) {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
}
|
||||
}
|
||||
}
|
||||
if mainNic != nil {
|
||||
return mainNic, nil
|
||||
}
|
||||
for _, n := range nics {
|
||||
ip, _ := n.GetString("ip")
|
||||
ipInt, err := netutils.NewIPV4Addr(ip)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "netutils.NewIPV4Addr %s", ip)
|
||||
}
|
||||
if mainIp == 0 {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
} else if !netutils.IsPrivate(ipInt) && netutils.IsPrivate(mainIp) {
|
||||
mainIp = ipInt
|
||||
mainNic = n
|
||||
}
|
||||
}
|
||||
if mainNic != nil {
|
||||
return mainNic, nil
|
||||
}
|
||||
return nil, errors.Wrap(errors.ErrInvalidStatus, "no valid nic")
|
||||
}
|
||||
|
||||
func Netlen2Mask(netmasklen int) string {
|
||||
var mask = ""
|
||||
var segCnt = 0
|
||||
|
||||
Reference in New Issue
Block a user