bugfix: guest desc and guest create backup (#155)

* bugfix:
    1. fix get network desc choose wrong host wire
    2. fix guest create backup doesn't cache iso image

* host wire detach filter by mac addr
This commit is contained in:
wanyaoqi
2019-04-02 11:51:11 +08:00
committed by Yousong Zhou
parent f0810bbe88
commit b63f957c9c
4 changed files with 44 additions and 7 deletions
+8 -3
View File
@@ -102,11 +102,16 @@ func init() {
})
type HostWireDetachOptions struct {
HOST string `help:"ID or Name of Host"`
WIRE string `help:"ID or Name of Wire"`
HOST string `help:"ID or Name of Host"`
WIRE string `help:"ID or Name of Wire"`
MacAddr string `help:"Host wire mac addr"`
}
R(&HostWireDetachOptions{}, "host-wire-detach", "Detach host from wire", func(s *mcclient.ClientSession, args *HostWireDetachOptions) error {
result, err := modules.Hostwires.Detach(s, args.HOST, args.WIRE, nil)
params := jsonutils.NewDict()
if len(args.MacAddr) > 0 {
params.Set("mac_addr", jsonutils.NewString(args.MacAddr))
}
result, err := modules.Hostwires.Detach(s, args.HOST, args.WIRE, params)
if err != nil {
return err
}
+13 -3
View File
@@ -271,10 +271,20 @@ func (self *SGuestnetwork) getJsonDescAtBaremetal(host *SHost) jsonutils.JSONObj
func (self *SGuestnetwork) getJsonDescAtHost(host *SHost) jsonutils.JSONObject {
network := self.GetNetwork()
hostwires := host.getHostwiresOfId(network.WireId)
if len(hostwires) > 1 {
log.Warningf("host attach to wire multiple times: %d", len(hostwires))
var hostWire *SHostwire
for i := 0; i < len(hostwires); i++ {
if netInter, _ := NetInterfaceManager.FetchByMac(hostwires[i].MacAddr); netInter != nil {
if netInter.NicType == NIC_TYPE_ADMIN {
hostWire = &hostwires[i]
break
}
}
}
return self.getGeneralJsonDesc(host, network, &hostwires[0])
if hostWire == nil {
log.Errorf("Host %s has no net interface on wire %s as guest network %s", host.Name, network.WireId, NIC_TYPE_ADMIN)
return nil
}
return self.getGeneralJsonDesc(host, network, hostWire)
}
func (self *SGuestnetwork) getGeneralJsonDesc(host *SHost, network *SNetwork, hostwire *SHostwire) jsonutils.JSONObject {
+4
View File
@@ -1596,6 +1596,10 @@ func (self *SGuest) getDiskSize() int {
return size
}
func (self *SGuest) GetCdrom() *SGuestcdrom {
return self.getCdrom()
}
func (self *SGuest) getCdrom() *SGuestcdrom {
cdrom := SGuestcdrom{}
cdrom.SetModelManager(GuestcdromManager)
+19 -1
View File
@@ -255,11 +255,29 @@ func (self *GuestCreateBackupTask) StartCreateBackupDisks(ctx context.Context, g
}
}
func (self *GuestCreateBackupTask) OnCreateBackupDisks(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
func (self *GuestCreateBackupTask) StartInsertIso(ctx context.Context, guest *models.SGuest, imageId string) {
self.SetStage("OnInsertIso", nil)
guest.StartInsertIsoTask(ctx, imageId, guest.BackupHostId, self.UserCred, self.GetTaskId())
}
func (self *GuestCreateBackupTask) OnInsertIso(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
self.SetStage("OnCreateBackup", nil)
guest.StartCreateBackup(ctx, self.UserCred, self.GetTaskId(), nil)
}
func (self *GuestCreateBackupTask) OnInsertIsoFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
self.TaskFailed(ctx, guest, fmt.Sprintf("Backup guest insert ISO failed %s", data.String()))
}
func (self *GuestCreateBackupTask) OnCreateBackupDisks(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
if cdrom := guest.GetCdrom(); cdrom != nil && len(cdrom.ImageId) > 0 {
self.StartInsertIso(ctx, guest, cdrom.ImageId)
} else {
self.SetStage("OnCreateBackup", nil)
guest.StartCreateBackup(ctx, self.UserCred, self.GetTaskId(), nil)
}
}
func (self *GuestCreateBackupTask) OnCreateBackupDisksFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
self.TaskFailed(ctx, guest, fmt.Sprintf("Create Backup Disks failed %s", data.String()))
}