Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Openstack]VMHandler - VolumeClient 안전 처리 #673

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (OpenStackDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.NLBHandler = true

return drvCapabilityInfo
}
Expand All @@ -63,10 +64,7 @@ func (driver *OpenStackDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo)
if err != nil {
return nil, err
}
VolumeClient, err := getVolumeClient(connectionInfo)
if err != nil {
return nil, err
}
VolumeClient, _ := getVolumeClient(connectionInfo)

iConn := oscon.OpenStackCloudConnection{Region: connectionInfo.RegionInfo, Client: Client, ImageClient: ImageClient, NetworkClient: NetworkClient, VolumeClient: VolumeClient}

Expand Down Expand Up @@ -164,7 +162,12 @@ func getVolumeClient(connInfo idrv.ConnectionInfo) (*gophercloud.ServiceClient,
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
client, err = openstack.NewBlockStorageV3(provider, gophercloud.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
}
return client, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (vmHandler *OpenStackVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (startvm i
LoggingError(hiscallInfo, createErr)
return irs.VMInfo{}, createErr
}

// Flavor 정보 조회 (Name)
vmSpecId, err := GetFlavorByName(vmHandler.Client, vmReqInfo.VMSpecName)
if err != nil {
Expand Down Expand Up @@ -157,6 +156,13 @@ func (vmHandler *OpenStackVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (startvm i
if vmReqInfo.RootDiskSize == "" || vmReqInfo.RootDiskSize == "default" {
createVolumeFlag = false
serverCreateOpts.ImageRef = image.IId.SystemId
} else {
if vmHandler.VolumeClient == nil{
createErr := errors.New(fmt.Sprintf("Failed to startVM err = this Openstack cannot provide VolumeClient. RootDiskSize cannot be changed"))
cblogger.Error(createErr.Error())
LoggingError(hiscallInfo, createErr)
return irs.VMInfo{}, createErr
}
}
segHandler := OpenStackSecurityHandler{
Client: vmHandler.Client,
Expand Down Expand Up @@ -596,13 +602,16 @@ func (vmHandler *OpenStackVMHandler) mappingServerInfo(server servers.Server) ir
// VM DiskSize Custom
if len(server.AttachedVolumes) != 0 {
for _, volume := range server.AttachedVolumes {
rawVolume, _ := volumes.Get(vmHandler.VolumeClient, volume.ID).Extract()
if rawVolume.Bootable == "true" {
vmInfo.RootDiskSize = strconv.Itoa(rawVolume.Size)
if vmHandler.VolumeClient != nil {
rawVolume, err := volumes.Get(vmHandler.VolumeClient, volume.ID).Extract()
if err == nil{
if rawVolume.Bootable == "true" {
vmInfo.RootDiskSize = strconv.Itoa(rawVolume.Size)
}
}
}
}
}

// VM Flavor 정보 설정
flavorId := server.Flavor["id"].(string)
flavor, _ := flavors.Get(vmHandler.Client, flavorId).Extract()
Expand Down Expand Up @@ -663,16 +672,17 @@ func (vmHandler *OpenStackVMHandler) mappingServerInfo(server servers.Server) ir
// Network Interface 정보 설정
vmInfo.NetworkInterface = port.ID
}

// Volume Disk 조회
pages, _ := volumes.List(vmHandler.VolumeClient, volumes.ListOpts{}).AllPages()
volList, _ := volumes.ExtractVolumes(pages)
for _, vol := range volList {
for _, attach := range vol.Attachments {
if attach.ServerID == vmInfo.IId.SystemId {
vmInfo.VMBlockDisk = attach.Device
vmInfo.RootDeviceName = attach.Device
break
if vmHandler.VolumeClient != nil {
// Volume Disk 조회
pages, _ := volumes.List(vmHandler.VolumeClient, volumes.ListOpts{}).AllPages()
volList, _ := volumes.ExtractVolumes(pages)
for _, vol := range volList {
for _, attach := range vol.Attachments {
if attach.ServerID == vmInfo.IId.SystemId {
vmInfo.VMBlockDisk = attach.Device
vmInfo.RootDeviceName = attach.Device
break
}
}
}
}
Expand Down