mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vsphere|compute] Updates reference to service
This commit is contained in:
parent
b24877b9ed
commit
e8630a0083
16 changed files with 55 additions and 55 deletions
|
@ -13,8 +13,8 @@ module Fog
|
|||
attribute :overall_status
|
||||
|
||||
def resource_pools(filters = { })
|
||||
self.attributes[:resource_pools] ||= id.nil? ? [] : connection.resource_pools({
|
||||
:connection => connection,
|
||||
self.attributes[:resource_pools] ||= id.nil? ? [] : service.resource_pools({
|
||||
:service => service,
|
||||
:cluster => name,
|
||||
:datacenter => datacenter
|
||||
}.merge(filters))
|
||||
|
|
|
@ -12,12 +12,12 @@ module Fog
|
|||
|
||||
def all(filters = {})
|
||||
requires :datacenter
|
||||
load connection.list_clusters(filters.merge(:datacenter => datacenter))
|
||||
load service.list_clusters(filters.merge(:datacenter => datacenter))
|
||||
end
|
||||
|
||||
def get(id)
|
||||
requires :datacenter
|
||||
new connection.get_cluster(id, datacenter)
|
||||
new service.get_cluster(id, datacenter)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,23 +9,23 @@ module Fog
|
|||
attribute :status
|
||||
|
||||
def clusters filters = { }
|
||||
connection.clusters({ :datacenter => name }.merge(filters))
|
||||
service.clusters({ :datacenter => name }.merge(filters))
|
||||
end
|
||||
|
||||
def networks filters = { }
|
||||
connection.networks({ :datacenter => name }.merge(filters))
|
||||
service.networks({ :datacenter => name }.merge(filters))
|
||||
end
|
||||
|
||||
def datastores filters = { }
|
||||
connection.datastores({ :datacenter => name }.merge(filters))
|
||||
service.datastores({ :datacenter => name }.merge(filters))
|
||||
end
|
||||
|
||||
def vm_folders filters = { }
|
||||
connection.folders({ :datacenter => name, :type => :vm }.merge(filters))
|
||||
service.folders({ :datacenter => name, :type => :vm }.merge(filters))
|
||||
end
|
||||
|
||||
|
||||
def virtual_machines filters = {}
|
||||
connection.servers({ :datacenter => name }.merge(filters))
|
||||
service.servers({ :datacenter => name }.merge(filters))
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -10,14 +10,14 @@ module Fog
|
|||
model Fog::Compute::Vsphere::Datacenter
|
||||
|
||||
def all(filters = {})
|
||||
load connection.list_datacenters(filters)
|
||||
load service.list_datacenters(filters)
|
||||
end
|
||||
|
||||
def get(name)
|
||||
new connection.get_datacenter(name)
|
||||
new service.get_datacenter(name)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,12 +11,12 @@ module Fog
|
|||
attr_accessor :datacenter
|
||||
|
||||
def all(filters = {})
|
||||
load connection.list_datastores(filters.merge(:datacenter => datacenter))
|
||||
load service.list_datastores(filters.merge(:datacenter => datacenter))
|
||||
end
|
||||
|
||||
def get(id)
|
||||
requires :datacenter
|
||||
new connection.get_datastore(id, datacenter)
|
||||
new service.get_datastore(id, datacenter)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
|
||||
def vms
|
||||
return [] if type.to_s != 'vm'
|
||||
connection.servers(:folder => path, :datacenter => datacenter)
|
||||
service.servers(:folder => path, :datacenter => datacenter)
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -13,12 +13,12 @@ module Fog
|
|||
def all(filters = { })
|
||||
requires :datacenter
|
||||
requires :type
|
||||
load connection.list_folders(filters.merge(:datacenter => datacenter, :type => type, :path => path))
|
||||
load service.list_folders(filters.merge(:datacenter => datacenter, :type => type, :path => path))
|
||||
end
|
||||
|
||||
def get(id)
|
||||
requires :datacenter
|
||||
new connection.get_folder(id, datacenter, type)
|
||||
new service.get_folder(id, datacenter, type)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,16 +15,16 @@ module Fog
|
|||
requires :vm
|
||||
case vm
|
||||
when Fog::Compute::Vsphere::Server
|
||||
load connection.list_vm_interfaces(vm.id)
|
||||
load service.list_vm_interfaces(vm.id)
|
||||
when Fog::Compute::Vsphere::Template
|
||||
load connection.list_template_interfaces(vm.id)
|
||||
load service.list_template_interfaces(vm.id)
|
||||
else
|
||||
raise 'interfaces should have vm or template'
|
||||
end
|
||||
end
|
||||
|
||||
def get(id)
|
||||
new connection.get_interface(id)
|
||||
new service.get_interface(id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,12 +11,12 @@ module Fog
|
|||
attr_accessor :datacenter
|
||||
|
||||
def all(filters = {})
|
||||
load connection.list_networks(filters.merge(:datacenter => datacenter))
|
||||
load service.list_networks(filters.merge(:datacenter => datacenter))
|
||||
end
|
||||
|
||||
def get(id)
|
||||
requires :datacenter
|
||||
new connection.get_network(id, datacenter)
|
||||
new service.get_network(id, datacenter)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,16 +11,16 @@ module Fog
|
|||
attr_accessor :datacenter, :cluster
|
||||
|
||||
def all(filters = {})
|
||||
load connection.list_resource_pools(filters.merge(:datacenter => datacenter, :cluster => cluster))
|
||||
load service.list_resource_pools(filters.merge(:datacenter => datacenter, :cluster => cluster))
|
||||
end
|
||||
|
||||
def get(id)
|
||||
requires :datacenter
|
||||
requires :cluster
|
||||
new connection.get_resource_pool(id, cluster, datacenter)
|
||||
new service.get_resource_pool(id, cluster, datacenter)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,46 +54,46 @@ module Fog
|
|||
|
||||
def vm_reconfig_memory(options = {})
|
||||
requires :instance_uuid, :memory
|
||||
connection.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory)
|
||||
service.vm_reconfig_memory('instance_uuid' => instance_uuid, 'memory' => memory)
|
||||
end
|
||||
|
||||
def vm_reconfig_cpus(options = {})
|
||||
requires :instance_uuid, :cpus
|
||||
connection.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus)
|
||||
service.vm_reconfig_cpus('instance_uuid' => instance_uuid, 'cpus' => cpus)
|
||||
end
|
||||
|
||||
def vm_reconfig_hardware(options = {})
|
||||
requires :instance_uuid, :hardware_spec
|
||||
connection.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
|
||||
service.vm_reconfig_hardware('instance_uuid' => instance_uuid, 'hardware_spec' => hardware_spec)
|
||||
end
|
||||
|
||||
def start(options = {})
|
||||
requires :instance_uuid
|
||||
connection.vm_power_on('instance_uuid' => instance_uuid)
|
||||
service.vm_power_on('instance_uuid' => instance_uuid)
|
||||
end
|
||||
|
||||
def stop(options = {})
|
||||
options = { :force => !tools_installed? }.merge(options)
|
||||
requires :instance_uuid
|
||||
connection.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
|
||||
service.vm_power_off('instance_uuid' => instance_uuid, 'force' => options[:force])
|
||||
end
|
||||
|
||||
def reboot(options = {})
|
||||
options = { :force => false }.merge(options)
|
||||
requires :instance_uuid
|
||||
connection.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
|
||||
service.vm_reboot('instance_uuid' => instance_uuid, 'force' => options[:force])
|
||||
end
|
||||
|
||||
def destroy(options = {})
|
||||
requires :instance_uuid
|
||||
stop if ready? # need to turn it off before destroying
|
||||
connection.vm_destroy('instance_uuid' => instance_uuid)
|
||||
service.vm_destroy('instance_uuid' => instance_uuid)
|
||||
end
|
||||
|
||||
def migrate(options = {})
|
||||
options = { :priority => 'defaultPriority' }.merge(options)
|
||||
requires :instance_uuid
|
||||
connection.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
|
||||
service.vm_migrate('instance_uuid' => instance_uuid, 'priority' => options[:priority])
|
||||
end
|
||||
|
||||
# Clone from a server object
|
||||
|
@ -111,13 +111,13 @@ module Fog
|
|||
req_options['template_path'] ="#{relative_path}/#{name}"
|
||||
req_options['datacenter'] = "#{datacenter}"
|
||||
# Perform the actual clone
|
||||
clone_results = connection.vm_clone(req_options)
|
||||
clone_results = service.vm_clone(req_options)
|
||||
# Create the new VM model. TODO This only works when "wait=true"
|
||||
new_vm = self.class.new(clone_results['new_vm'])
|
||||
# We need to assign the collection and the connection otherwise we
|
||||
# cannot reload the model.
|
||||
new_vm.collection = self.collection
|
||||
new_vm.connection = self.connection
|
||||
new_vm.service = service
|
||||
# Return the new VM model.
|
||||
new_vm
|
||||
end
|
||||
|
@ -133,13 +133,13 @@ module Fog
|
|||
# defines VNC attributes on the hypervisor
|
||||
def config_vnc(options = {})
|
||||
requires :instance_uuid
|
||||
connection.vm_config_vnc(options.merge('instance_uuid' => instance_uuid))
|
||||
service.vm_config_vnc(options.merge('instance_uuid' => instance_uuid))
|
||||
end
|
||||
|
||||
# returns a hash of VNC attributes required for connection
|
||||
# returns a hash of VNC attributes required for service
|
||||
def vnc
|
||||
requires :instance_uuid
|
||||
connection.vm_get_vnc(instance_uuid)
|
||||
service.vm_get_vnc(instance_uuid)
|
||||
end
|
||||
|
||||
def memory
|
||||
|
@ -151,25 +151,25 @@ module Fog
|
|||
end
|
||||
|
||||
def interfaces
|
||||
attributes[:interfaces] ||= id.nil? ? [] : connection.interfaces( :vm => self )
|
||||
attributes[:interfaces] ||= id.nil? ? [] : service.interfaces( :vm => self )
|
||||
end
|
||||
|
||||
def volumes
|
||||
attributes[:volumes] ||= id.nil? ? [] : connection.volumes( :vm => self )
|
||||
attributes[:volumes] ||= id.nil? ? [] : service.volumes( :vm => self )
|
||||
end
|
||||
|
||||
def folder
|
||||
return nil unless datacenter and path
|
||||
attributes[:folder] ||= connection.folders(:datacenter => datacenter, :type => :vm).get(path)
|
||||
attributes[:folder] ||= service.folders(:datacenter => datacenter, :type => :vm).get(path)
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name, :cluster, :datacenter
|
||||
if persisted?
|
||||
raise "update is not supported yet"
|
||||
# connection.update_vm(attributes)
|
||||
# service.update_vm(attributes)
|
||||
else
|
||||
self.id = connection.create_vm(attributes)
|
||||
self.id = service.create_vm(attributes)
|
||||
end
|
||||
reload
|
||||
end
|
||||
|
@ -199,13 +199,13 @@ module Fog
|
|||
|
||||
def initialize_interfaces
|
||||
if attributes[:interfaces] and attributes[:interfaces].is_a?(Array)
|
||||
self.attributes[:interfaces].map! { |nic| nic.is_a?(Hash) ? connection.interfaces.new(nic) : nic }
|
||||
self.attributes[:interfaces].map! { |nic| nic.is_a?(Hash) ? service.interfaces.new(nic) : nic }
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_volumes
|
||||
if attributes[:volumes] and attributes[:volumes].is_a?(Array)
|
||||
self.attributes[:volumes].map! { |vol| vol.is_a?(Hash) ? connection.volumes.new(vol) : vol }
|
||||
self.attributes[:volumes].map! { |vol| vol.is_a?(Hash) ? service.volumes.new(vol) : vol }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
# 'folder' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
|
||||
# than simply listing everything.
|
||||
def all(filters = { })
|
||||
load connection.list_virtual_machines(filters.merge(
|
||||
load service.list_virtual_machines(filters.merge(
|
||||
:datacenter => datacenter,
|
||||
:cluster => cluster,
|
||||
:network => network,
|
||||
|
@ -27,7 +27,7 @@ module Fog
|
|||
end
|
||||
|
||||
def get(id, datacenter = nil)
|
||||
new connection.get_virtual_machine id, datacenter
|
||||
new service.get_virtual_machine id, datacenter
|
||||
rescue Fog::Compute::Vsphere::NotFound
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -10,11 +10,11 @@ module Fog
|
|||
model Fog::Compute::Vsphere::Template
|
||||
|
||||
def all(filters = {})
|
||||
load connection.list_templates(filters)
|
||||
load service.list_templates(filters)
|
||||
end
|
||||
|
||||
def get(id)
|
||||
new connection.get_template(id)
|
||||
new service.get_template(id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,16 +15,16 @@ module Fog
|
|||
requires :vm
|
||||
case vm
|
||||
when Fog::Compute::Vsphere::Server
|
||||
load connection.list_vm_volumes(vm.id)
|
||||
load service.list_vm_volumes(vm.id)
|
||||
when Fog::Compute::Vsphere::Template
|
||||
load connection.list_template_volumes(vm.id)
|
||||
load service.list_template_volumes(vm.id)
|
||||
else
|
||||
raise 'volumes should have vm or template'
|
||||
end
|
||||
end
|
||||
|
||||
def get(id)
|
||||
new connection.get_volume(id)
|
||||
new service.get_volume(id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module Fog
|
|||
vm = case id
|
||||
# UUID based
|
||||
when /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/
|
||||
@connection.searchIndex.FindByUuid :uuid => id, :vmSearch => true, :instanceUuid => true, :datacenter => dc
|
||||
@service.searchIndex.FindByUuid :uuid => id, :vmSearch => true, :instanceUuid => true, :datacenter => dc
|
||||
else
|
||||
# try to find based on VM name
|
||||
if dc
|
||||
|
|
|
@ -9,7 +9,7 @@ module Fog
|
|||
|
||||
options[:folder] ||= options['folder']
|
||||
if options['instance_uuid'] then
|
||||
[connection.get_virtual_machine(options['instance_uuid'])]
|
||||
[service.get_virtual_machine(options['instance_uuid'])]
|
||||
elsif options[:folder] && options[:datacenter] then
|
||||
list_all_virtual_machines_in_folder(options[:folder], options[:datacenter])
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue