forked from chef/knife-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request chef#63 from ezrapagel/vm_config
added command vm config PROPERTY VALUE
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Author:: Brian Dupras (<[email protected]>) | ||
# License:: Apache License, Version 2.0 | ||
|
||
require 'chef/knife' | ||
require 'chef/knife/base_vsphere_command' | ||
require 'rbvmomi' | ||
require 'netaddr' | ||
|
||
class Chef::Knife::VsphereVmConfig < Chef::Knife::BaseVsphereCommand | ||
banner "knife vsphere vm config VMNAME PROPERTY VALUE. See \"http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html\" for allowed ATTRIBUTE values (any property of type xs:string is supported)." | ||
|
||
get_common_options | ||
|
||
def run | ||
$stdout.sync = true | ||
vmname = @name_args[0] | ||
if vmname.nil? | ||
show_usage | ||
fatal_exit("You must specify a virtual machine name") | ||
end | ||
|
||
property_name = @name_args[1] | ||
if property_name.nil? | ||
show_usage | ||
fatal_exit("You must specify a PROPERTY name (e.g. annotation)") | ||
end | ||
property_name = property_name.to_sym | ||
|
||
property_value = @name_args[2] | ||
if property_value.nil? | ||
show_usage | ||
fatal_exit("You must specify a PROPERTY value") | ||
end | ||
|
||
vim = get_vim_connection | ||
|
||
dcname = get_config(:vsphere_dc) | ||
dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found" | ||
folder = find_folder(get_config(:folder)) || dc.vmFolder | ||
|
||
vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or | ||
abort "VM #{vmname} not found" | ||
|
||
properties = {} | ||
properties[property_name] = property_value | ||
vm.ReconfigVM_Task(:spec => RbVmomi::VIM.VirtualMachineConfigSpec(properties)).wait_for_completion | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module KnifeVsphere | ||
VERSION = "0.9.0" | ||
VERSION = "0.9.1" | ||
end | ||
|