Class: VmShepherd::VsphereManager
- Inherits:
-
Object
- Object
- VmShepherd::VsphereManager
- Defined in:
- lib/vm_shepherd/vsphere_manager.rb
Constant Summary collapse
- TEMPLATE_PREFIX =
'tpl'.freeze
Instance Method Summary collapse
- #deploy(ova_path, vm_config, vsphere_config) ⇒ Object
- #destroy(folder_name) ⇒ Object
-
#initialize(host, username, password, datacenter_name) ⇒ VsphereManager
constructor
A new instance of VsphereManager.
Constructor Details
#initialize(host, username, password, datacenter_name) ⇒ VsphereManager
Returns a new instance of VsphereManager.
8 9 10 11 12 13 14 |
# File 'lib/vm_shepherd/vsphere_manager.rb', line 8 def initialize(host, username, password, datacenter_name) @host = host @username = username @password = password @datacenter_name = datacenter_name @logger = Logger.new(STDERR) end |
Instance Method Details
#deploy(ova_path, vm_config, vsphere_config) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vm_shepherd/vsphere_manager.rb', line 16 def deploy(ova_path, vm_config, vsphere_config) raise ArgumentError unless folder_name_is_valid?(vsphere_config[:folder]) ova_path = File.(ova_path.strip) ensure_no_running_vm(vm_config) tmp_dir = untar_vbox_ova(ova_path) ovf_file_path = ovf_file_path_from_dir(tmp_dir) template = deploy_ovf_template(ovf_file_path, vsphere_config) vm = create_vm_from_template(template, vsphere_config) reconfigure_vm(vm, vm_config) power_on_vm(vm) ensure FileUtils.remove_entry_secure(ovf_file_path, force: true) unless ovf_file_path.nil? end |
#destroy(folder_name) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/vm_shepherd/vsphere_manager.rb', line 34 def destroy(folder_name) fail("#{folder_name.inspect} is not a valid folder name") unless folder_name_is_valid?(folder_name) delete_folder_and_vms(folder_name) fail("#{folder_name.inspect} already exists") unless datacenter.vmFolder.traverse(folder_name).nil? datacenter.vmFolder.traverse(folder_name, RbVmomi::VIM::Folder, true) end |