Skip to content

Commit

Permalink
Merge pull request #579 from inno-cloudbarista/feature/Common-RootDev…
Browse files Browse the repository at this point in the history
…iceName-VMBlockDisk

[VMInfo] RootDeviceName / VMBlockDisk 값 설정
  • Loading branch information
powerkimhub authored Mar 14, 2022
2 parents 54dd39a + 618152b commit 73a7849
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ func (vmHandler *AzureVMHandler) mappingServerInfo(server compute.VirtualMachine
Region: *server.Location,
},
VMSpecName: string(server.VirtualMachineProperties.HardwareProfile.VMSize),
RootDeviceName: "Not visible in Azure",
VMBlockDisk: "Not visible in Azure",
}

// Set VM Zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ func (vmHandler *ClouditVMHandler) mappingServerInfo(server server.ServerInfo) i
PrivateIP: server.PrivateIp,
SSHAccessPoint: fmt.Sprintf("%s:%d", server.AdaptiveIp, SSHDefaultPort),
RootDiskSize: strconv.Itoa(server.VolumeSize),
RootDeviceName: "Not visible in Cloudit",
VMBlockDisk: "Not visible in Cloudit",
}
if server.CreatedAt != "" {
timeArr := strings.Split(server.CreatedAt, " ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io/ioutil"
"net/url"
"os"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -681,6 +682,23 @@ func getVMNextHref(next *vpcv1.InstanceCollectionNext) (string, error) {
}
return "", errors.New("NOT NEXT")
}
func getVolumeNextHref(next *vpcv1.VolumeCollectionNext) (string, error) {
if next != nil {
href := *next.Href
u, err := url.Parse(href)
if err != nil {
return "", err
}
paramMap, _ := url.ParseQuery(u.RawQuery)
if paramMap != nil {
safe := paramMap["start"]
if safe != nil && len(safe) > 0 {
return safe[0], nil
}
}
}
return "", errors.New("NOT NEXT")
}
func checkVmIID(vmIID irs.IID) error {
if vmIID.SystemId == "" && vmIID.NameId == "" {
return errors.New("invalid IID")
Expand Down Expand Up @@ -736,6 +754,46 @@ func existInstance(vmIID irs.IID, vpcService *vpcv1.VpcV1, ctx context.Context)
}
return false, nil
}

func getRawVolume(volumeIId irs.IID, vpcService *vpcv1.VpcV1, ctx context.Context) (vpcv1.Volume, error) {
if volumeIId.SystemId == "" {
options := &vpcv1.ListVolumesOptions{}
volumes, _, err := vpcService.ListVolumesWithContext(ctx, options)
if err != nil {
return vpcv1.Volume{}, err
}
for {
for _, volume := range volumes.Volumes {
if *volume.Name == volumeIId.NameId {
return volume, nil
}
}
nextstr, _ := getVolumeNextHref(volumes.Next)
if nextstr != "" {
listVolumeOptionsNext := &vpcv1.ListVolumesOptions{
Start: core.StringPtr(nextstr),
}
volumes, _, err = vpcService.ListVolumesWithContext(ctx, listVolumeOptionsNext)
if err != nil {
return vpcv1.Volume{}, err
}
} else {
break
}
}
err = errors.New(fmt.Sprintf("not found Volume %s", volumeIId.NameId))
return vpcv1.Volume{}, err
} else {
options := &vpcv1.GetVolumeOptions{}
options.SetID(volumeIId.SystemId)
volume, _, err := vpcService.GetVolumeWithContext(ctx, options)
if err != nil {
return vpcv1.Volume{}, err
}
return *volume, err
}
}

func getRawInstance(vmIID irs.IID, vpcService *vpcv1.VpcV1, ctx context.Context) (vpcv1.Instance, error) {
if vmIID.SystemId == "" {
options := &vpcv1.ListInstancesOptions{}
Expand Down Expand Up @@ -903,8 +961,10 @@ func (vmHandler *IbmVMHandler) setVmInfo(instance vpcv1.Instance) (irs.VMInfo, e
NameId: *instance.PrimaryNetworkInterface.Subnet.Name,
SystemId: *instance.PrimaryNetworkInterface.Subnet.ID,
},
PrivateIP: *instance.PrimaryNetworkInterface.PrimaryIpv4Address,
VMUserId: CBDefaultVmUserName,
PrivateIP: *instance.PrimaryNetworkInterface.PrimaryIpv4Address,
VMUserId: CBDefaultVmUserName,
RootDeviceName: "Not visible in IBMCloud-VPC",
VMBlockDisk: "Not visible in IBMCloud-VPC",
}
// KeyGet
instanceInitializationOptions := &vpcv1.GetInstanceInitializationOptions{}
Expand Down Expand Up @@ -936,5 +996,10 @@ func (vmHandler *IbmVMHandler) setVmInfo(instance vpcv1.Instance) (irs.VMInfo, e
vmInfo.SSHAccessPoint = vmInfo.PublicIP + ":22"
}
}
volumeIId := irs.IID{SystemId: *instance.BootVolumeAttachment.Volume.ID}
rawVolume, err := getRawVolume(volumeIId, vmHandler.VpcService, vmHandler.Ctx)
if err == nil {
vmInfo.RootDiskSize = strconv.Itoa(int(*rawVolume.Capacity))
}
return vmInfo, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,12 @@ func (vmHandler *OpenStackVMHandler) mappingServerInfo(server servers.Server) ir
// 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

0 comments on commit 73a7849

Please sign in to comment.