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

Attach and list RDM/LUN #656

Merged
merged 5 commits into from
Jan 30, 2017
Merged

Attach and list RDM/LUN #656

merged 5 commits into from
Jan 30, 2017

Conversation

bastienbc
Copy link
Contributor

govc does not provide command line options to:

  • attach RDM using the device name.
  • list available devices for a specific VM, retrieving various useful information ( UIDS, Device name, Device path, ... )

@vmwclabot
Copy link
Member

@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 bastienbc changed the title Rdmattachement Attach and list RDM/LUN Jan 17, 2017
@vmwclabot
Copy link
Member

@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.

@vmwclabot
Copy link
Member

@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.

@vmwclabot
Copy link
Member

@bastienbc, VMware has approved your signed contributor license agreement.

Copy link
Member

@dougm dougm left a 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
}

Copy link
Member

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
Copy link
Member

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))
Copy link
Member

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))
Copy link
Member

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()
Copy link
Member

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 {
Copy link
Member

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." {
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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.

@bastienbc
Copy link
Contributor Author

bastienbc commented Jan 25, 2017

Hi!
First thank you to have a look into my code.
I am relatively new to Go, so I am keeping any of your advises preciously.
Also I did not knew about golint, which is now installed and used :-)

About this pull request itself:
To 2014-2017?
Something else?
You mentioned it on an other pull request comment, so I was wondering what to do exactly.

Bastien Barbé Creuly added 2 commits January 25, 2017 12:28
…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.
Copy link
Member

@dougm dougm left a 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")
Copy link
Member

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`
Copy link
Member

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 {
Copy link
Member

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"
Copy link
Member

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 {
Copy link
Member

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) {
Copy link
Member

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.

@dougm
Copy link
Member

dougm commented Jan 27, 2017

@bastienbc thanks for the updates! Just '2017' is fine for the copyright year.

@dougm dougm merged commit 3e95cb1 into vmware:master Jan 30, 2017
@dougm
Copy link
Member

dougm commented Jan 30, 2017

thanks @bastienbc !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants