Class: Fog::Compute::Vsphere::Mock
- Inherits:
-
Object
- Object
- Fog::Compute::Vsphere::Mock
- Includes:
- Shared
- Defined in:
- lib/fog/vsphere/compute.rb,
lib/fog/vsphere/requests/compute/vm_clone.rb,
lib/fog/vsphere/requests/compute/create_vm.rb,
lib/fog/vsphere/requests/compute/vm_reboot.rb,
lib/fog/vsphere/requests/compute/get_folder.rb,
lib/fog/vsphere/requests/compute/vm_destroy.rb,
lib/fog/vsphere/requests/compute/vm_migrate.rb,
lib/fog/vsphere/requests/compute/get_cluster.rb,
lib/fog/vsphere/requests/compute/get_network.rb,
lib/fog/vsphere/requests/compute/vm_power_on.rb,
lib/fog/vsphere/requests/compute/current_time.rb,
lib/fog/vsphere/requests/compute/get_template.rb,
lib/fog/vsphere/requests/compute/vm_power_off.rb,
lib/fog/vsphere/requests/compute/get_datastore.rb,
lib/fog/vsphere/requests/compute/list_clusters.rb,
lib/fog/vsphere/requests/compute/list_networks.rb,
lib/fog/vsphere/requests/compute/vm_config_vnc.rb,
lib/fog/vsphere/requests/compute/get_datacenter.rb,
lib/fog/vsphere/requests/compute/list_templates.rb,
lib/fog/vsphere/requests/compute/get_server_type.rb,
lib/fog/vsphere/requests/compute/list_datastores.rb,
lib/fog/vsphere/requests/compute/list_vm_volumes.rb,
lib/fog/vsphere/requests/compute/list_datacenters.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb,
lib/fog/vsphere/requests/compute/get_resource_pool.rb,
lib/fog/vsphere/requests/compute/list_customfields.rb,
lib/fog/vsphere/requests/compute/list_server_types.rb,
lib/fog/vsphere/requests/compute/list_vm_interfaces.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb,
lib/fog/vsphere/requests/compute/get_virtual_machine.rb,
lib/fog/vsphere/requests/compute/list_resource_pools.rb,
lib/fog/vsphere/requests/compute/modify_vm_interface.rb,
lib/fog/vsphere/requests/compute/list_vm_customvalues.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb,
lib/fog/vsphere/requests/compute/list_virtual_machines.rb
Instance Attribute Summary
Attributes included from Shared
#vsphere_is_vcenter, #vsphere_rev, #vsphere_server, #vsphere_username
Class Method Summary collapse
Instance Method Summary collapse
- #add_vm_interface(vmid, options = {}) ⇒ Object
- #create_vm(attributes = { }) ⇒ Object
- #current_time ⇒ Object
- #data ⇒ Object
- #destroy_vm_interface(vmid, options = {}) ⇒ Object
- #get_cluster(id) ⇒ Object
- #get_datacenter(name) ⇒ Object
- #get_datastore(name, datacenter_name) ⇒ Object
- #get_folder(path, filters = { }) ⇒ Object
- #get_folder_path(folder, root = nil) ⇒ Object
- #get_network(id) ⇒ Object
- #get_resource_pool(name, cluster_name, datacenter_name) ⇒ Object
- #get_server_type(id) ⇒ Object
- #get_template(id, datacenter_name = nil) ⇒ Object
- #get_virtual_machine(id, datacenter_name = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_clusters(filters = { }) ⇒ Object
- #list_datacenters(filters = {}) ⇒ Object
- #list_datastores(datacenter_name) ⇒ Object
- #list_networks(datacenter_name) ⇒ Object
- #list_resource_pools(filters = { }) ⇒ Object
- #list_server_types(datacenter_name) ⇒ Object
- #list_templates(filters = { }) ⇒ Object
- #list_virtual_machines(options = { }) ⇒ Object
- #list_vm_customfields(vm_id) ⇒ Object
- #list_vm_interfaces(vm_id) ⇒ Object
- #list_vm_volumes(vm_id) ⇒ Object
- #reset_data ⇒ Object
- #vm_clone(options = {}) ⇒ Object
- #vm_config_vnc(options = { }) ⇒ Object
- #vm_destroy(options = {}) ⇒ Object
- #vm_get_vnc(uuid) ⇒ Object
- #vm_migrate(options = {}) ⇒ Object
- #vm_power_off(options = {}) ⇒ Object
- #vm_power_on(options = {}) ⇒ Object
- #vm_reboot(options = {}) ⇒ Object
- #vm_reconfig_cpus(options = {}) ⇒ Object
- #vm_reconfig_hardware(options = {}) ⇒ Object
- #vm_reconfig_memory(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
311 312 313 314 315 316 317 318 319 |
# File 'lib/fog/vsphere/compute.rb', line 311 def initialize(={}) require 'rbvmomi' @vsphere_username = [:vsphere_username] @vsphere_password = 'REDACTED' @vsphere_server = [:vsphere_server] @vsphere_expected_pubkey_hash = [:vsphere_expected_pubkey_hash] @vsphere_is_vcenter = true @vsphere_rev = '4.0' end |
Class Method Details
.data ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/fog/vsphere/compute.rb', line 191 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :servers => { "5032c8a5-9c5e-ba7a-3804-832a03e16381" => { "resource_pool" => "Resources", "memory_mb" => 2196, "mac_addresses" => { "Network adapter 1" => "00:50:56:a9:00:28" }, "power_state" => "poweredOn", "cpus" => 1, "hostname" => "dhcp75-197.virt.bos.redhat.com", "mo_ref" => "vm-562", "connection_state" => "connected", "overall_status" => "green", "datacenter" => "Solutions", "volumes" => [{ "id" => "6000C29c-a47d-4cd9-5249-c371de775f06", "datastore" => "Storage1", "mode" => "persistent", "size" => 8388608, "thin" => true, "name" => "Hard disk 1", "filename" => "[Storage1] rhel6-mfojtik/rhel6-mfojtik.vmdk", "size_gb" => 8 }], "interfaces" => [{"mac" => "00:50:56:a9:00:28", "network" => "VM Network", "name" => "Network adapter 1", "status" => "ok", "summary" => "VM Network", }], "hypervisor" => "gunab.puppetlabs.lan", "guest_id" => "rhel6_64Guest", "tools_state" => "toolsOk", "cluster" => "Solutionscluster", "name" => "rhel64", "operatingsystem" => "Red Hat Enterprise Linux 6 (64-bit)", "path" => "/Datacenters/Solutions/vm", "uuid" => "4229f0e9-bfdc-d9a7-7bac-12070772e6dc", "instance_uuid" => "5032c8a5-9c5e-ba7a-3804-832a03e16381", "id" => "5032c8a5-9c5e-ba7a-3804-832a03e16381", "tools_version" => "guestToolsUnmanaged", "ipaddress" => "192.168.100.184", "template" => false }, "502916a3-b42e-17c7-43ce-b3206e9524dc" => { "resource_pool" => "Resources", "memory_mb" => 512, "power_state" => "poweredOn", "mac_addresses" => { "Network adapter 1" => "00:50:56:a9:00:00" }, "hostname" => nil, "cpus" => 1, "connection_state" => "connected", "mo_ref" => "vm-621", "overall_status" => "green", "datacenter" => "Solutions", "volumes" => [{"thin" => false, "size_gb" => 10, "datastore" => "datastore1", "filename" => "[datastore1] i-1342439683/i-1342439683.vmdk", "size" => 10485762, "name" => "Hard disk 1", "mode" => "persistent", "id" => "6000C29b-f364-d073-8316-8e98ac0a0eae" }], "interfaces" => [{ "summary" => "VM Network", "mac" => "00:50:56:a9:00:00", "status" => "ok", "network" => "VM Network", "name" => "Network adapter 1" }], "hypervisor" => "gunab.puppetlabs.lan", "guest_id" => nil, "cluster" => "Solutionscluster", "tools_state" => "toolsNotInstalled", "name" => "i-1342439683", "operatingsystem" => nil, "path" => "/", "tools_version" => "guestToolsNotInstalled", "uuid" => "4229e0de-30cb-ceb2-21f9-4d8d8beabb52", "instance_uuid" => "502916a3-b42e-17c7-43ce-b3206e9524dc", "id" => "502916a3-b42e-17c7-43ce-b3206e9524dc", "ipaddress" => nil, "template" => false }, "5029c440-85ee-c2a1-e9dd-b63e39364603" => { "resource_pool" => "Resources", "memory_mb" => 2196, "power_state" => "poweredOn", "mac_addresses" => { "Network adapter 1" => "00:50:56:b2:00:af" }, "hostname" => "centos56gm.localdomain", "cpus" => 1, "connection_state" => "connected", "mo_ref" => "vm-715", "overall_status" => "green", "datacenter" => "Solutions", "hypervisor" => "gunab.puppetlabs.lan", "guest_id" => "rhel6_64Guest", "cluster" => "Solutionscluster", "tools_state" => "toolsOk", "name" => "jefftest", "operatingsystem" => "Red Hat Enterprise Linux 6 (64-bit)", "path" => "/", "tools_version" => "guestToolsUnmanaged", "ipaddress" => "192.168.100.187", "uuid" => "42329da7-e8ab-29ec-1892-d6a4a964912a", "instance_uuid" => "5029c440-85ee-c2a1-e9dd-b63e39364603", "id" => "5029c440-85ee-c2a1-e9dd-b63e39364603", "template" => false } }, :datacenters => { "Solutions" => {:name => "Solutions", :status => "grey"} } } end end |
Instance Method Details
#add_vm_interface(vmid, options = {}) ⇒ Object
44 45 46 47 48 |
# File 'lib/fog/vsphere/requests/compute/modify_vm_interface.rb', line 44 def add_vm_interface(vmid, = {}) raise ArgumentError, "instance id is a required parameter" unless vmid raise ArgumentError, "interface is a required parameter" unless and [:interface] true end |
#create_vm(attributes = { }) ⇒ Object
123 124 125 |
# File 'lib/fog/vsphere/requests/compute/create_vm.rb', line 123 def create_vm attributes = { } 'vm-715' # this matches the mock data in get_virtual_machine.rb end |
#current_time ⇒ Object
15 16 17 |
# File 'lib/fog/vsphere/requests/compute/current_time.rb', line 15 def current_time { 'current_time' => Time.now.utc } end |
#data ⇒ Object
321 322 323 |
# File 'lib/fog/vsphere/compute.rb', line 321 def data self.class.data[@vsphere_username] end |
#destroy_vm_interface(vmid, options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/fog/vsphere/requests/compute/modify_vm_interface.rb', line 50 def destroy_vm_interface(vmid, = {}) raise ArgumentError, "instance id is a required parameter" unless vmid raise ArgumentError, "interface is a required parameter" unless and [:interface] true end |
#get_cluster(id) ⇒ Object
20 21 |
# File 'lib/fog/vsphere/requests/compute/get_cluster.rb', line 20 def get_cluster(id) end |
#get_datacenter(name) ⇒ Object
23 24 25 26 27 |
# File 'lib/fog/vsphere/requests/compute/get_datacenter.rb', line 23 def get_datacenter name dc = self.data[:datacenters][name] raise(Fog::Compute::Vsphere::NotFound) unless dc dc end |
#get_datastore(name, datacenter_name) ⇒ Object
25 26 |
# File 'lib/fog/vsphere/requests/compute/get_datastore.rb', line 25 def get_datastore(name, datacenter_name) end |
#get_folder(path, filters = { }) ⇒ Object
69 70 |
# File 'lib/fog/vsphere/requests/compute/get_folder.rb', line 69 def get_folder(path, filters = { }) end |
#get_folder_path(folder, root = nil) ⇒ Object
59 60 61 |
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 59 def get_folder_path(folder, root = nil) nil end |
#get_network(id) ⇒ Object
25 26 |
# File 'lib/fog/vsphere/requests/compute/get_network.rb', line 25 def get_network(id) end |
#get_resource_pool(name, cluster_name, datacenter_name) ⇒ Object
21 22 |
# File 'lib/fog/vsphere/requests/compute/get_resource_pool.rb', line 21 def get_resource_pool(name, cluster_name, datacenter_name) end |
#get_server_type(id) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/fog/vsphere/requests/compute/get_server_type.rb', line 22 def get_server_type(id) {:id=>"rhel6Guest", :name=>"rhel6Guest", :family=>"linuxGuest", :fullname=>"Red Hat Enterprise Linux 6 (32-Bit)", :datacenter=>"Solutions"} end |
#get_template(id, datacenter_name = nil) ⇒ Object
11 12 |
# File 'lib/fog/vsphere/requests/compute/get_template.rb', line 11 def get_template(id, datacenter_name = nil) end |
#get_virtual_machine(id, datacenter_name = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/vsphere/requests/compute/get_virtual_machine.rb', line 32 def get_virtual_machine(id, datacenter_name = nil) if is_uuid?(id) vm = list_virtual_machines({ 'instance_uuid' => id, 'datacenter' => datacenter_name }).first else # try to find based on VM name. May need to handle the path of the VM vm = list_virtual_machines({ 'name' => id, 'datacenter' => datacenter_name }).first end vm ? vm : raise(Fog::Compute::Vsphere::NotFound, "#{id} was not found") end |
#list_clusters(filters = { }) ⇒ Object
32 33 |
# File 'lib/fog/vsphere/requests/compute/list_clusters.rb', line 32 def list_clusters(filters = { }) end |
#list_datacenters(filters = {}) ⇒ Object
29 30 31 |
# File 'lib/fog/vsphere/requests/compute/list_datacenters.rb', line 29 def list_datacenters filters = {} [ {:name => "Solutions", :status => "grey"}, {:name => "Solutions2", :status => "green" }] end |
#list_datastores(datacenter_name) ⇒ Object
34 35 36 |
# File 'lib/fog/vsphere/requests/compute/list_datastores.rb', line 34 def list_datastores(datacenter_name) [] end |
#list_networks(datacenter_name) ⇒ Object
32 33 34 |
# File 'lib/fog/vsphere/requests/compute/list_networks.rb', line 32 def list_networks(datacenter_name) [] end |
#list_resource_pools(filters = { }) ⇒ Object
34 35 |
# File 'lib/fog/vsphere/requests/compute/list_resource_pools.rb', line 34 def list_resource_pools(filters = { }) end |
#list_server_types(datacenter_name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/vsphere/requests/compute/list_server_types.rb', line 39 def list_server_types(datacenter_name) [{:id=>"rhel6Guest", :name=>"rhel6Guest", :family=>"linuxGuest", :fullname=>"Red Hat Enterprise Linux 6 (32-Bit)", :datacenter=>"Solutions"}, {:id=>"rhel5_64Guest", :name=>"rhel5_64Guest", :family=>"linuxGuest", :fullname=>"Red Hat Enterprise Linux 5 (64-Bit)", :datacenter=>"Solutions"}] end |
#list_templates(filters = { }) ⇒ Object
44 45 |
# File 'lib/fog/vsphere/requests/compute/list_templates.rb', line 44 def list_templates(filters = { }) end |
#list_virtual_machines(options = { }) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 63 def list_virtual_machines( = { }) if ['instance_uuid'].nil? and ['mo_ref'].nil? self.data[:servers].values elsif !['instance_uuid'].nil? server = self.data[:servers][['instance_uuid']] server.nil? ? [] : [server] else self.data[:servers].values.select{|vm| vm['mo_ref'] == ['mo_ref']} end end |
#list_vm_customfields(vm_id) ⇒ Object
17 18 |
# File 'lib/fog/vsphere/requests/compute/list_customfields.rb', line 17 def list_vm_customfields() end |
#list_vm_interfaces(vm_id) ⇒ Object
60 61 |
# File 'lib/fog/vsphere/requests/compute/list_vm_interfaces.rb', line 60 def list_vm_interfaces(vm_id) end |
#list_vm_volumes(vm_id) ⇒ Object
46 47 |
# File 'lib/fog/vsphere/requests/compute/list_vm_volumes.rb', line 46 def list_vm_volumes(vm_id) end |
#reset_data ⇒ Object
325 326 327 |
# File 'lib/fog/vsphere/compute.rb', line 325 def reset_data self.class.data.delete(@vsphere_username) end |
#vm_clone(options = {}) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/fog/vsphere/requests/compute/vm_clone.rb', line 287 def vm_clone( = {}) # Option handling TODO Needs better method of checking = () notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Could not find VM template" } template = list_virtual_machines.find(notfound) do |vm| vm['name'] == ['template_path'].split("/")[-1] end # generate a random id id = [8,4,4,4,12].map{|i| Fog::Mock.random_hex(i)}.join("-") new_vm = template.clone.merge({ "name" => ['name'], "id" => id, "instance_uuid" => id, "path" => "/Datacenters/#{['datacenter']}/#{['dest_folder'] ? ['dest_folder']+"/" : ""}#{['name']}" }) self.data[:servers][id] = new_vm { 'vm_ref' => "vm-#{Fog::Mock.random_numbers(3)}", 'new_vm' => new_vm, 'task_ref' => "task-#{Fog::Mock.random_numbers(4)}", } end |
#vm_config_vnc(options = { }) ⇒ Object
36 37 38 39 |
# File 'lib/fog/vsphere/requests/compute/vm_config_vnc.rb', line 36 def vm_config_vnc( = { }) raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' { 'task_state' => 'success' } end |
#vm_destroy(options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/fog/vsphere/requests/compute/vm_destroy.rb', line 19 def vm_destroy( = {}) raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' { 'task_state' => 'success' } end |
#vm_get_vnc(uuid) ⇒ Object
41 42 43 |
# File 'lib/fog/vsphere/requests/compute/vm_config_vnc.rb', line 41 def vm_get_vnc uuid {:password => 'secret', :port => '5900', :enabled => 'true'} end |
#vm_migrate(options = {}) ⇒ Object
28 29 30 31 32 |
# File 'lib/fog/vsphere/requests/compute/vm_migrate.rb', line 28 def vm_migrate( = {}) priority = ['priority'].nil? ? 'defaultPriority' : ["priority"] raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' { 'task_state' => 'success' } end |
#vm_power_off(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/vsphere/requests/compute/vm_power_off.rb', line 30 def vm_power_off( = {}) raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' vm = get_virtual_machine(['instance_uuid']) vm["power_state"] = "poweredOff" { 'task_state' => "running", 'power_off_type' => ['force'] ? 'cut_power' : 'shutdown_guest', } end |
#vm_power_on(options = {}) ⇒ Object
22 23 24 25 |
# File 'lib/fog/vsphere/requests/compute/vm_power_on.rb', line 22 def vm_power_on( = {}) raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' { 'task_state' => 'success' } end |
#vm_reboot(options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/fog/vsphere/requests/compute/vm_reboot.rb', line 27 def vm_reboot( = {}) raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' { 'task_state' => "running", 'reboot_type' => ['force'] ? 'reset_power' : 'reboot_guest' } end |
#vm_reconfig_cpus(options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb', line 14 def vm_reconfig_cpus( = {}) raise ArgumentError, "cpus is a required parameter" unless .has_key? 'cpus' raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' hardware_spec={'numCPUs' => ['cpus']} vm_reconfig_hardware('instance_uuid' => ['instance_uuid'], 'hardware_spec' => hardware_spec ) end |
#vm_reconfig_hardware(options = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb', line 16 def vm_reconfig_hardware( = {}) raise ArgumentError, "hardware_spec is a required parameter" unless .has_key? 'hardware_spec' raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' { 'task_state' => 'success' } end |
#vm_reconfig_memory(options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb', line 14 def vm_reconfig_memory( = {}) raise ArgumentError, "memory is a required parameter" unless .has_key? 'memory' raise ArgumentError, "instance_uuid is a required parameter" unless .has_key? 'instance_uuid' hardware_spec={'memoryMB' => ['memory']} vm_reconfig_hardware('instance_uuid' => ['instance_uuid'], 'hardware_spec' => hardware_spec ) end |