Skip to content

Commit

Permalink
Merge pull request chef#63 from ezrapagel/vm_config
Browse files Browse the repository at this point in the history
added command vm config PROPERTY VALUE
  • Loading branch information
bdupras committed Sep 5, 2013
2 parents 59dad7a + 895fbe6 commit 5f69f83
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions lib/chef/knife/vsphere_vm_config.rb
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
2 changes: 1 addition & 1 deletion lib/chef/knife/vsphere_vm_query.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Author:: Ian Delahorne (<ian@delahorne.com>)
# Author:: Brian Dupras (<bdupras@rallydev.com>)
# License:: Apache License, Version 2.0

require 'chef/knife'
Expand Down
2 changes: 1 addition & 1 deletion lib/knife-vsphere/version.rb
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

0 comments on commit 5f69f83

Please sign in to comment.