-
Notifications
You must be signed in to change notification settings - Fork 894
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
Attach and list RDM/LUN #656
Conversation
@bastienbc, you must sign our contributor license agreement before your changes are merged. Click here to sign the agreement. If you are a VMware employee, read this for further instruction. |
@bastienbc, your company's legal contact has rejected your signed contributor license agreement. The merge can not proceed until the agreement has been resigned. Click here to resign the agreement. |
@bastienbc, your company's legal contact has approved your signed contributor license agreement. It will also be reviewed by VMware, but the merge can proceed. |
@bastienbc, VMware has approved your signed contributor license agreement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bastienbc thanks, looks very useful. A few comments for you to consider.
} | ||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a Description here (example from vm.clone below). This'll get included in the help output and the generated govc/USAGE.md doc.
func (cmd *clone) Description() string {
return `Clone VM to NAME.
Examples:
govc vm.clone -vm template-vm new-vm`
}
if err != nil { | ||
return err | ||
} | ||
var VM_withProp mo.VirtualMachine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can rename to avoid the go-lint warning below, just 'mvm' for example would be fine.
don't use underscores in Go names; var VM_withProp should be VMWithProp
|
||
err = task.Wait(ctx) | ||
if err != nil { | ||
return errors.New(fmt.Sprintf("Error adding device %+v \n with backing %+v \nLogged Item: %s", device, backing, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from go-lint:
should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
return nil | ||
|
||
} | ||
return errors.New(fmt.Sprintf("Error: No LUN with device name containing %s found.", cmd.device)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from go-lint:
should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...)
//Query VM To Find Devices avilable for attaching to VM | ||
var queryConfigRequest types.QueryConfigTarget | ||
queryConfigRequest.This = VM_withProp.EnvironmentBrowser | ||
cl, err := cmd.Client() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check err != nil
here.
for u = 0; u < 16; u++ { | ||
free := true | ||
for _, device := range devices { | ||
if device.GetVirtualDevice().ControllerKey == device.GetVirtualDevice().ControllerKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you need to rename 'device' in the loop (to 'd' for example), so you can compare to the device defined on line 105 above.
backing.CompatibilityMode = "physicalMode" | ||
backing.DeviceName = ScsiDisk.Disk.DeviceName | ||
for _, descriptor := range ScsiDisk.Disk.Descriptor { | ||
if string([]rune(descriptor.Id)[:4]) == "vml." { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings.HasPrefix(descriptor.Id, "vml.")
var queryConfigRequest types.QueryConfigTarget | ||
queryConfigRequest.This = VM_withProp.EnvironmentBrowser | ||
cl, err := cmd.Client() | ||
queryConfigResp, err := methods.QueryConfigTarget(ctx, cl, &queryConfigRequest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wrap this in a helper, since its being used in 2 places:
func (v VirtualMachine) QueryConfigTarget(ctx context.Context) (*types.ConfigTarget, error) {
var vm mo.VirtualMachine
err := v.Properties(ctx, v.Reference(), []string{"environmentBrowser"}, &vm)
if err != nil {
return nil, err
}
req := types.QueryConfigTarget{
This: vm.EnvironmentBrowser,
}
res, err := methods.QueryConfigTarget(ctx, v.Client(), &req)
if err != nil {
return nil, err
}
return res.Returnval, nil
}
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0) | ||
for _, disk := range r.Disks { | ||
fmt.Fprintf(tw, "Name:\t%s\n", disk.Name) | ||
fmt.Fprintf(tw, " Device name:\t%s\n", disk.Disk.DeviceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 space indent like the other commands, rather than tab.
Hi! About this pull request itself: |
…alMachine method. Also took in consideration comments made by dougm to merge this to the vmware branch.
…are branch. Added Description method in both vm.rdm.attach and vm.rdm.ls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just a few more minor suggestions.
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx) | ||
cmd.VirtualMachineFlag.Register(ctx, f) | ||
|
||
f.StringVar(&cmd.device, "deviceName", "", "Device Name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name the flag "device", we use that name in other commands.
return `Attach DEVICE to VM with RDM. | ||
|
||
Examples: | ||
govc vm.rdm.attach -vm VM -deviceName DEVICE` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/deviceName/device/ here too. Can you use a real example value for DEVICE? An example from the output of device.ls, such as "disk-200-0"
return err | ||
} | ||
|
||
for _, ScsiDisk := range vmConfigOptions.ScsiDisk { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go style nit: unexported vars start with lower case, 'scsiDisk' or just 'disk' here would be fine.
continue | ||
} | ||
var backing types.VirtualDiskRawDiskMappingVer1BackingInfo | ||
backing.CompatibilityMode = "physicalMode" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use the generated enum here: string(types.VirtualDiskCompatibilityModePhysicalMode)
for u = 0; u < 16; u++ { | ||
free := true | ||
for _, d := range devices { | ||
if d.GetVirtualDevice().ControllerKey == d.GetVirtualDevice().ControllerKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still comparing the same device ('d'), shouldn't this compare the ControllerKey of 'd' and 'device' instead ?
@@ -689,3 +689,24 @@ func (v VirtualMachine) Unregister(ctx context.Context) error { | |||
_, err := methods.UnregisterVM(ctx, v.Client(), &req) | |||
return err | |||
} | |||
|
|||
// QueryEnvironmentBrowser is a helper to get the environmentBrowser property. | |||
func (v VirtualMachine) QueryEnvironmentBrowser(ctx context.Context) (*types.ConfigTarget, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name this method 'QueryConfigTarget', since 'EnvironmentBrowser' is just a parameter.
@bastienbc thanks for the updates! Just '2017' is fine for the copyright year. |
…o 2017, and resolve some bug
thanks @bastienbc ! |
govc does not provide command line options to: