Module: Chef::Knife::VcVmCommon
- Included in:
- VcVmBootstrap, VcVmConfigGuest, VcVmDiscardSuspended, VcVmNetwork, VcVmReboot, VcVmReset, VcVmSetDisks, VcVmSetInfo, VcVmShow, VcVmStart, VcVmStop, VcVmSuspend
- Defined in:
- lib/chef/knife/common/vc_vm_common.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_vm(vm_arg) ⇒ Object
-
#sanitize_guest_name(name) ⇒ Object
Accept only characters and hyphens.
-
#stop_if_running(connection, vm) ⇒ Object
Verify a VM and stop it if it’s running.
Class Method Details
.included(includer) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chef/knife/common/vc_vm_common.rb', line 23 def self.included(includer) includer.class_eval do option :vcloud_vdc, :long => "--vdc VDC_NAME", :description => "VDC to whom VM's vApp belongs", :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_vdc] = key } option :vcloud_vapp, :long => "--vapp VAPP_NAME", :description => "vApp to whom VM belongs", :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_vapp] = key } end end |
Instance Method Details
#get_vm(vm_arg) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef/knife/common/vc_vm_common.rb', line 37 def get_vm(vm_arg) vm = nil vapp_name = locate_config_value(:vcloud_vapp) org_name = locate_org_option vdc_name = locate_config_value(:vcloud_vdc) unless vdc_name && vapp_name notice_msg("--vapp and --vdc not specified, assuming VM is an ID") vm = connection.get_vm vm_arg else org = connection.get_organization_by_name org_name vm = connection.get_vm_by_name org, vdc_name, vapp_name, vm_arg end raise ArgumentError, "VM #{vm_arg} not found" unless vm vm end |
#sanitize_guest_name(name) ⇒ Object
Accept only characters and hyphens
Underscores are converted to hyphens
57 58 59 |
# File 'lib/chef/knife/common/vc_vm_common.rb', line 57 def sanitize_guest_name(name) name.gsub(/_/, '-').gsub(/[^[0-9]|^[a-z]|^[A-Z]|^-]/, '') end |
#stop_if_running(connection, vm) ⇒ Object
Verify a VM and stop it if it’s running
Return :nothing if nothing was made
:errored for errors
:stopped if was stopped
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/chef/knife/common/vc_vm_common.rb', line 66 def stop_if_running(connection, vm) if vm[:status] == 'running' if ui.confirm("Guest customizations must be applied to a stopped VM, " \ "but it's running. Can I #{ui.color('STOP', :red)} it") ui.msg "Stopping VM..." task_id, response = connection.poweroff_vm vm[:id] return :errored unless wait_task(connection, task_id) end return :stopped end return :nothing end |