Class: Vmesh::VSphere
- Inherits:
-
Object
- Object
- Vmesh::VSphere
- Defined in:
- lib/vmesh/vsphere.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#vim ⇒ Object
Returns the value of attribute vim.
Instance Method Summary collapse
- #clone_machine(vm_type, vm_target, default_vm_folder, machine_options) ⇒ Object
- #get_custom_spec(name) ⇒ Object
- #get_datacenter(name) ⇒ Object
- #get_datastore(name, datacenter) ⇒ Object
- #get_folder(path, datacenter_name = ) ⇒ Object
-
#get_machine(machine_name, datacenter) ⇒ Object
Can we search through the datacenters for a machine? Should we get the machine from the datacenters?.
- #get_resource_pool(name, datacenter_name) ⇒ Object
-
#initialize(connection_options) ⇒ VSphere
constructor
A new instance of VSphere.
- #root_folder ⇒ Object
- #vm_root_folder ⇒ Object
Constructor Details
#initialize(connection_options) ⇒ VSphere
Returns a new instance of VSphere.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vmesh/vsphere.rb', line 8 def initialize() Vmesh::logger.debug "Opening connection to #{[:host]} as #{[:user]}, dc #{[:datacenter]}, resource pool #{[:resource_pool]}, insecure #{[:insecure]}" opts = { :host => [:host], :user => [:user], :password => [:password], :datacenter => [:datacenter], :host => [:host], :resource_pool => [:resource_pool], :insecure => [:insecure], } @vim = RbVmomi::VIM.connect opts @options = opts end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/vmesh/vsphere.rb', line 7 def @options end |
#vim ⇒ Object
Returns the value of attribute vim.
7 8 9 |
# File 'lib/vmesh/vsphere.rb', line 7 def vim @vim end |
Instance Method Details
#clone_machine(vm_type, vm_target, default_vm_folder, machine_options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vmesh/vsphere.rb', line 29 def clone_machine(vm_type, vm_target, default_vm_folder, ) Vmesh::template.has_key? vm_type.to_sym or raise "unknown machine type #{vm_type}, known types are #{Vmesh::template.keys.to_s}" config = {} template = Vmesh::template[vm_type.to_sym] vm_dest = VSphere.parse_vm_target vm_target, default_vm_folder vm_template = get_machine(template[:name], @options[:datacenter]) # Refactor & pass in options with the get or alternatively add a get and set method spec = get_custom_spec(template[:spec]) spec.destination_ip_address = [:ip_address] if [:ip_address] config[:numCPUs] = [:numCPUs] if [:numCPUs].to_s != '' config[:memoryMB] = [:memoryMB] if [:memoryMB].to_s != '' pool = get_resource_pool(@options[:resource_pool], @options[:datacenter]) datacenter = get_datacenter(@options[:datacenter]) datastore = get_datastore([:datastore], datacenter) raise "No datastore found matching #{[:datastore]}. Exiting." if datastore.nil? Vmesh::logger.debug "Got datastore named #{datastore.name} with free space #{datastore.free_space}." Vmesh::logger.debug "Creating vm in folder #{vm_dest[:folder]} with name #{vm_dest[:name]}." folder = get_folder(vm_dest[:folder], @options[:datacenter]) Vmesh::logger.debug "Using folder #{folder.to_s}." vm_template.clone_to(vm_dest[:name], folder, datastore, spec, pool, config) end |
#get_custom_spec(name) ⇒ Object
51 52 53 54 |
# File 'lib/vmesh/vsphere.rb', line 51 def get_custom_spec(name) spec_mgr = @vim.serviceContent.customizationSpecManager CustomSpec::get(spec_mgr, name) end |
#get_datacenter(name) ⇒ Object
67 68 69 |
# File 'lib/vmesh/vsphere.rb', line 67 def get_datacenter(name) Vmesh::Datacenter::get(@vim, name) end |
#get_datastore(name, datacenter) ⇒ Object
62 63 64 65 |
# File 'lib/vmesh/vsphere.rb', line 62 def get_datastore(name, datacenter) Vmesh::logger.debug "Getting datastore #{name}" Datastore::get(@vim, name, datacenter) end |
#get_folder(path, datacenter_name = ) ⇒ Object
79 80 81 82 |
# File 'lib/vmesh/vsphere.rb', line 79 def get_folder(path, datacenter_name = @options[:datacenter]) Vmesh::logger.debug "Looking for folder #{path}." path.to_s == '/' ? vm_root_folder : vm_root_folder.traverse(path) end |
#get_machine(machine_name, datacenter) ⇒ Object
Can we search through the datacenters for a machine? Should we get the machine from the datacenters?
25 26 27 |
# File 'lib/vmesh/vsphere.rb', line 25 def get_machine(machine_name, datacenter) Machine::get(self, datacenter, machine_name) end |
#get_resource_pool(name, datacenter_name) ⇒ Object
56 57 58 59 60 |
# File 'lib/vmesh/vsphere.rb', line 56 def get_resource_pool(name, datacenter_name) # KRUT this should be a ResourcePool wrapper object instead? Vmesh::logger.debug "Chasing resource pool #{name}" Datacenter::find_pool(@vim, name, datacenter_name) end |
#root_folder ⇒ Object
71 72 73 |
# File 'lib/vmesh/vsphere.rb', line 71 def root_folder @vim.serviceInstance.content.rootFolder end |
#vm_root_folder ⇒ Object
75 76 77 |
# File 'lib/vmesh/vsphere.rb', line 75 def vm_root_folder @vim.serviceInstance.content.rootFolder.traverse(@options[:datacenter]).vmFolder end |