Class: Fog::Vsphere::Compute::Mock

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/vsphere/requests/compute/vm_clone.rb,
lib/fog/vsphere/compute.rb,
lib/fog/vsphere/requests/compute/create_vm.rb,
lib/fog/vsphere/requests/compute/update_vm.rb,
lib/fog/vsphere/requests/compute/vm_reboot.rb,
lib/fog/vsphere/requests/compute/vm_rename.rb,
lib/fog/vsphere/requests/compute/get_folder.rb,
lib/fog/vsphere/requests/compute/list_hosts.rb,
lib/fog/vsphere/requests/compute/list_rules.rb,
lib/fog/vsphere/requests/compute/vm_destroy.rb,
lib/fog/vsphere/requests/compute/vm_execute.rb,
lib/fog/vsphere/requests/compute/vm_migrate.rb,
lib/fog/vsphere/requests/compute/vm_suspend.rb,
lib/fog/vsphere/requests/compute/create_rule.rb,
lib/fog/vsphere/requests/compute/get_cluster.rb,
lib/fog/vsphere/requests/compute/get_network.rb,
lib/fog/vsphere/requests/compute/list_groups.rb,
lib/fog/vsphere/requests/compute/vm_power_on.rb,
lib/fog/vsphere/requests/compute/vm_relocate.rb,
lib/fog/vsphere/requests/compute/create_group.rb,
lib/fog/vsphere/requests/compute/current_time.rb,
lib/fog/vsphere/requests/compute/destroy_rule.rb,
lib/fog/vsphere/requests/compute/get_template.rb,
lib/fog/vsphere/requests/compute/list_folders.rb,
lib/fog/vsphere/requests/compute/vm_power_off.rb,
lib/fog/vsphere/requests/compute/create_folder.rb,
lib/fog/vsphere/requests/compute/destroy_group.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/folder_destroy.rb,
lib/fog/vsphere/requests/compute/get_datacenter.rb,
lib/fog/vsphere/requests/compute/list_processes.rb,
lib/fog/vsphere/requests/compute/list_templates.rb,
lib/fog/vsphere/requests/compute/list_vm_cdroms.rb,
lib/fog/vsphere/requests/compute/get_server_type.rb,
lib/fog/vsphere/requests/compute/get_storage_pod.rb,
lib/fog/vsphere/requests/compute/list_datastores.rb,
lib/fog/vsphere/requests/compute/list_vm_volumes.rb,
lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb,
lib/fog/vsphere/requests/compute/list_datacenters.rb,
lib/fog/vsphere/requests/compute/modify_vm_volume.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb,
lib/fog/vsphere/requests/compute/vm_take_snapshot.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_storage_pods.rb,
lib/fog/vsphere/requests/compute/list_vm_snapshots.rb,
lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb,
lib/fog/vsphere/requests/compute/list_vm_interfaces.rb,
lib/fog/vsphere/requests/compute/revert_to_snapshot.rb,
lib/fog/vsphere/requests/compute/set_vm_customvalue.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb,
lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb,
lib/fog/vsphere/requests/compute/vm_revert_snapshot.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/vm_reconfig_volumes.rb,
lib/fog/vsphere/requests/compute/get_compute_resource.rb,
lib/fog/vsphere/requests/compute/list_child_snapshots.rb,
lib/fog/vsphere/requests/compute/list_vm_customvalues.rb,
lib/fog/vsphere/requests/compute/modify_vm_controller.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb,
lib/fog/vsphere/requests/compute/list_virtual_machines.rb,
lib/fog/vsphere/requests/compute/list_compute_resources.rb,
lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb,
lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb,
lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb

Overview

rubocop:enable ClassLength

Instance Attribute Summary

Attributes included from Shared

#vsphere_is_vcenter, #vsphere_rev, #vsphere_server, #vsphere_username

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

rubocop:enable Metrics/MethodLength



591
592
593
594
595
596
597
598
599
# File 'lib/fog/vsphere/compute.rb', line 591

def initialize(options = {})
  require 'rbvmomi'
  @vsphere_username = options[:vsphere_username]
  @vsphere_password = 'REDACTED'
  @vsphere_server   = options[:vsphere_server]
  @vsphere_expected_pubkey_hash = options[:vsphere_expected_pubkey_hash]
  @vsphere_is_vcenter = true
  @vsphere_rev = '4.0'
end

Class Method Details

.dataObject

rubocop:disable Metrics/MethodLength



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# File 'lib/fog/vsphere/compute.rb', line 321

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'      => 8_388_608,
              'thin'      => true,
              'name'      => 'Hard disk 1',
              'filename'  => '[Storage1] rhel6-mfojtik/rhel6-mfojtik.vmdk',
              'size_gb'   => 8
            }],
          'scsi_controllers' =>
            [{ 'shared_bus' => 'noSharing',
               'type'        => 'VirtualLsiLogicController',
               'unit_number' => 7,
               'key'         => 1000 }],
          'interfaces'       =>
            [{ 'mac' => '00:50:56:a9:00:28',
               'network' => 'dvportgroup-123456',
               'name'    => 'Network adapter 1',
               'status'  => 'ok',
               'summary' => 'VM Network' }],
          'cdroms' =>
            [{
              'name'                => 'CD-/DVD-Drive 1',
              'filename'            => nil,
              'key'                 => 3000,
              'controller_key'      => 200,
              'unit_number'         => 0,
              'start_connected'     => false,
              'allow_guest_control' => true,
              'connected'           => false
            }],
          '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'      => 10_485_762,
               'name'      => 'Hard disk 1',
               'mode'      => 'persistent',
               'id'        => '6000C29b-f364-d073-8316-8e98ac0a0eae' }],
          'scsi_controllers' =>
            [{ 'shared_bus' => 'noSharing',
               'type'        => 'VirtualLsiLogicController',
               'unit_number' => 7,
               'key'         => 1000 }],
          'interfaces'       =>
            [{ 'summary' => 'VM Network',
               'mac'     => '00:50:56:a9:00:00',
               'status'  => 'ok',
               'network' => 'dvportgroup-123456',
               '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'             => '/Solutions/wibble',
          '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', path: ['Solutions'] }
      },
      datastores: {
        'Storage1' => {
          'id' => 'datastore-123456',
          'name' => 'Storage1',
          'datacenter' => 'Solutions',
          'type' => 'VMFS',
          'freespace' => 697_471_860_736,
          'accessible' => true,
          'capacity' => 1_099_243_192_320,
          'uncommitted' => 977_158_537_741,
          'cluster' => []
        },
        'datastore1' => {
          'id' => 'datastore-789123',
          'name' => 'datastore1',
          'datacenter' => 'Solutions',
          'type' => 'VMFS',
          'freespace' => 697_471_860_736,
          'accessible' => true,
          'capacity' => 1_099_243_192_320,
          'uncommitted' => 977_158_537_741,
          'cluster' => ['Solutionscluster']
        }
      },
      networks: {
        'network1' => {
          'id' => 'dvportgroup-123456',
          'name' => 'network1',
          'datacenter' => 'Solutions',
          'accessible' => true,
          'virtualswitch' => nil,
          'cluster' => ['Solutionscluster']
        },
        'network2' => {
          'id' => 'dvportgroup-789123',
          'name' => 'network2',
          'datacenter' => 'Solutions',
          'accessible' => true,
          'virtualswitch' => nil,
          'cluster' => []
        }
      },
      folders: {
        'wibble' => {
          'name' => 'wibble',
          'datacenter' => 'Solutions',
          'path' => '/Solutions/wibble',
          'type' => 'vm'
        },
        'empty' => {
          'name' => 'empty',
          'datacenter' => 'Solutions',
          'path' => '/Solutions/empty',
          'type' => 'vm'
        }
      },
      storage_pods:                 [{ id: 'group-p123456',
                                       name: 'Datastore Cluster 1',
                                       freespace: '4856891834368',
                                       capacity: '7132061630464',
                                       datacenter: 'Solutions' }],
      clusters:                 [{ id: '1d4d9a3f-e4e8-4c40-b7fc-263850068fa4',
                                   name: 'Solutionscluster',
                                   num_host: '4',
                                   num_cpu_cores: '16',
                                   overall_status: 'green',
                                   datacenter: 'Solutions',
                                   full_path: 'Solutionscluster',
                                   klass: 'RbVmomi::VIM::ComputeResource' },
                                 { id: 'e4195973-102b-4096-bbd6-5429ff0b35c9',
                                   name: 'Problemscluster',
                                   num_host: '4',
                                   num_cpu_cores: '32',
                                   overall_status: 'green',
                                   datacenter: 'Solutions',
                                   full_path: 'Problemscluster',
                                   klass: 'RbVmomi::VIM::ComputeResource' },
                                 {
                                   klass: 'RbVmomi::VIM::Folder',
                                   clusters: [{ id: '03616b8d-b707-41fd-b3b5-The first',
                                                name: 'Problemscluster',
                                                num_host: '4',
                                                num_cpu_cores: '32',
                                                overall_status: 'green',
                                                datacenter: 'Solutions',
                                                full_path: 'Nested/Problemscluster',
                                                klass: 'RbVmomi::VIM::ComputeResource' },
                                              { id: '03616b8d-b707-41fd-b3b5-the Second',
                                                name: 'Lastcluster',
                                                num_host: '8',
                                                num_cpu_cores: '32',
                                                overall_status: 'green',
                                                datacenter: 'Solutions',
                                                full_path: 'Nested/Lastcluster',
                                                klass: 'RbVmomi::VIM::ComputeResource' }]
                                 }],
      rules: {
        'anti-affinity-foo' => {
          datacenter: 'Solutions',
          cluster: 'Solutionscluster',
          key: 4242,
          name: 'anti-affinity-foo',
          enabled: true,
          type: RbVmomi::VIM::ClusterAntiAffinityRuleSpec,
          vm_ids: ['5032c8a5-9c5e-ba7a-3804-832a03e16381', '502916a3-b42e-17c7-43ce-b3206e9524dc']
        }
      },
      hosts: {
        'Host1' => {
          datacenter: 'Solutions',
          cluster: 'Solutionscluster',
          name: 'host1.example.com',
          model: 'PowerEdge R730',
          vendor: 'Dell Inc.',
          ipaddress: '1.2.3.4',
          ipaddress6: nil,
          hostname: 'host1',
          domainname: 'example.com',
          product_name: 'VMware ESXi',
          uuid: '4c4c4544-0051-3610-8046-c4c44f584a32',
          cpu_cores: 20,
          cpu_sockets: 2,
          cpu_threads: 40,
          cpu_hz: 2_599_999_534,
          memory: 824_597_241_856,
          product_version: '6.0.0',
          vm_ids: ['5032c8a5-9c5e-ba7a-3804-832a03e16381', '502916a3-b42e-17c7-43ce-b3206e9524dc']
        }
      }
    }
  end
end

Instance Method Details

#add_vm_cdrom(cdrom) ⇒ Object



15
16
17
# File 'lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb', line 15

def add_vm_cdrom(cdrom)
  vm_reconfig_hardware('instance_uuid' => cdrom.server.instance_uuid, 'hardware_spec' => { 'deviceChange' => [create_cdrom(cdrom, cdrom.unit_number, :add)] })
end

#add_vm_controller(controller) ⇒ Object



11
12
13
# File 'lib/fog/vsphere/requests/compute/modify_vm_controller.rb', line 11

def add_vm_controller(controller)
  vm_reconfig_hardware('instance_uuid' => controller.server_id, 'hardware_spec' => { 'deviceChange' => [create_controller(controller)] })
end

#add_vm_interface(vmid, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


73
74
75
76
77
# File 'lib/fog/vsphere/requests/compute/modify_vm_interface.rb', line 73

def add_vm_interface(vmid, options = {})
  raise ArgumentError, 'instance id is a required parameter' unless vmid
  raise ArgumentError, 'interface is a required parameter' unless options && options[:interface]
  true
end

#add_vm_volume(volume) ⇒ Object



21
22
23
# File 'lib/fog/vsphere/requests/compute/modify_vm_volume.rb', line 21

def add_vm_volume(volume)
  vm_reconfig_hardware('instance_uuid' => volume.server_id, 'hardware_spec' => { 'deviceChange' => [create_cdrom(volume, :add)] })
end

#cloudinit_to_customspec(user_data) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb', line 46

def cloudinit_to_customspec(user_data)
  raise ArgumentError, "user_data can't be nil" if user_data.nil?
  custom_spec = { 'customization_spec' => {} }
  user_data = YAML.safe_load(user_data)
  custom_spec['encryptionKey']                = user_data['encryptionKey'] if user_data.key?('encryptionKey')
  custom_spec['globalIPSettings']             = user_data['globalIPSettings'] if user_data.key?('globalIPSettings')
  custom_spec['identity']                     = user_data['identity'] if user_data.key?('identity')
  custom_spec['nicSettingMap']                = user_data['nicSettingMap'] if user_data.key?('nicSettingMap')
  custom_spec['options']                      = user_data['options'] if user_data.key?('options')
  custom_spec['extraConfig']                  = user_data['extraConfig'] if user_data.key?('extraConfig')
  custom_spec['hostname']                     =  user_data['hostname'] if user_data.key?('hostname')
  custom_spec['ipsettings']                   =  { 'ip' => user_data['ip'] } if user_data.key?('ip')
  custom_spec['ipsettings']['subnetMask']     =  user_data['netmask'] if user_data.key?('netmask')
  custom_spec['ipsettings']['dnsServerList']  =  user_data['dns'] if user_data.key?('dns')
  custom_spec['ipsettings']['gateway']        =  user_data['gateway'] if user_data.key?('gateway')
  custom_spec['domain']                       =  user_data['domain'] if user_data.key?('domain')
  custom_spec['dnsSuffixList']                =  user_data['domainsuffixlist'] if user_data.key?('domainsuffixlist')
  custom_spec['time_zone']                    =  user_data['timezone'] if user_data.key?('timezone')
  custom_spec
end

#create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/fog/vsphere/requests/compute/create_vm.rb', line 350

def create_cdrom(cdrom, index = 0, operation = :add, controller_key = 200)
  {
    operation: operation,
    device: {
      key: cdrom.key || index,
      backing: { deviceName: '' },
      controllerKey: controller_key,
      connectable: {
        startConnected: false,
        connected: false,
        allowGuestControl: true
      }
    }
  }
end

#create_folder(datacenter, path, name) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/fog/vsphere/requests/compute/create_folder.rb', line 19

def create_folder(datacenter, path, name)
  data[:folders][name] = {
    'name'       => name,
    'datacenter' => datacenter,
    'path'       => "#{path}/#{name}",
    'type'       => 'vm'
  }
end

#create_group(attributes = {}) ⇒ Object



46
47
48
# File 'lib/fog/vsphere/requests/compute/create_group.rb', line 46

def create_group(attributes = {})
  data[:groups][attributes[:name]] = attributes
end

#create_rule(attributes = {}) ⇒ Object



51
52
53
54
55
# File 'lib/fog/vsphere/requests/compute/create_rule.rb', line 51

def create_rule(attributes = {})
  attributes[:key] = rand(9999)
  data[:rules][attributes[:name]] = attributes
  attributes[:key]
end

#create_vm(attributes = {}) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/fog/vsphere/requests/compute/create_vm.rb', line 331

def create_vm(attributes = {})
  id = SecureRandom.uuid
  vm = {
    'id'                => id,
    'uuid'              => id,
    'instance_uuid'     => id,
    'mo_ref'            => "vm-#{rand 99_999}",
    'datacenter'        => attributes[:datacenter],
    'name'              => attributes[:name],
    'interfaces'        => attributes[:interfaces].map do
      {
        'mac' => 'f2:b5:46:b5:d8:d7'
      }
    end
  }
  data[:servers][id] = vm
  id
end

#current_timeObject



12
13
14
# File 'lib/fog/vsphere/requests/compute/current_time.rb', line 12

def current_time
  { 'current_time' => Time.now.utc }
end

#dataObject



601
602
603
# File 'lib/fog/vsphere/compute.rb', line 601

def data
  self.class.data[@vsphere_username]
end

#destroy_group(attributes = {}) ⇒ Object

Raises:

  • (Fog::Vsphere::Error::NotFound)


19
20
21
22
23
# File 'lib/fog/vsphere/requests/compute/destroy_group.rb', line 19

def destroy_group(attributes = {})
  group = data[:groups][attributes[:name]]
  raise Fog::Vsphere::Error::NotFound unless group
  data[:groups].delete(attributes[:name])
end

#destroy_rule(attributes = {}) ⇒ Object

Raises:

  • (Fog::Vsphere::Error::NotFound)


19
20
21
22
23
# File 'lib/fog/vsphere/requests/compute/destroy_rule.rb', line 19

def destroy_rule(attributes = {})
  rule = data[:rules][attributes[:name]]
  raise Fog::Vsphere::Error::NotFound unless rule
  data[:rules].delete(attributes[:name])
end

#destroy_vm_cdrom(cdrom) ⇒ Object



19
20
21
# File 'lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb', line 19

def destroy_vm_cdrom(cdrom)
  vm_reconfig_hardware('instance_uuid' => cdrom.server.instance_uuid, 'hardware_spec' => { 'deviceChange' => [create_cdrom(cdrom, cdrom.unit_number, :remove)] })
end

#destroy_vm_interface(vmid, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


79
80
81
82
83
# File 'lib/fog/vsphere/requests/compute/modify_vm_interface.rb', line 79

def destroy_vm_interface(vmid, options = {})
  raise ArgumentError, 'instance id is a required parameter' unless vmid
  raise ArgumentError, 'interface is a required parameter' unless options && options[:interface]
  true
end

#destroy_vm_volume(_volume) ⇒ Object



29
30
31
# File 'lib/fog/vsphere/requests/compute/modify_vm_volume.rb', line 29

def destroy_vm_volume(_volume)
  true
end

#folder_destroy(path, datacenter_name) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/fog/vsphere/requests/compute/folder_destroy.rb', line 16

def folder_destroy(path, datacenter_name)
  vms = list_virtual_machines(folder: path, datacenter: datacenter_name)
  unless vms.empty?
    raise Fog::Vsphere::Errors::ServiceError, "Folder #{path} is not empty"
  end
  { 'task_state' => 'success' }
end

#get_cluster(name, datacenter_name) ⇒ Object Also known as: get_raw_cluster



24
25
26
27
# File 'lib/fog/vsphere/requests/compute/get_cluster.rb', line 24

def get_cluster(name, datacenter_name)
  data[:clusters].find { |c| c[:name] == name && c[:datacenter] == datacenter_name } ||
    raise(Fog::Vsphere::Compute::NotFound)
end

#get_compute_resource(_name, _datacenter_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/vsphere/requests/compute/get_compute_resource.rb', line 19

def get_compute_resource(_name, _datacenter_name)
  {
    id: 'domain-s7',
    name: 'fake-host',
    totalCpu: 33_504,
    totalMemory: 154_604_142_592,
    numCpuCores: 12,
    numCpuThreads: 24,
    effectiveCpu: 32_247,
    effectiveMemory: 135_733,
    numHosts: 1,
    numEffectiveHosts: 1,
    overallStatus: 'gray',
    overallCpuUsage: 15_682,
    overallMemoryUsage: 132_755,
    effective: true,
    isSingleHost: true
  }
end

#get_datacenter(name) ⇒ Object

Raises:

  • (Fog::Vsphere::Compute::NotFound)


24
25
26
27
28
# File 'lib/fog/vsphere/requests/compute/get_datacenter.rb', line 24

def get_datacenter(name)
  dc = data[:datacenters][name]
  raise(Fog::Vsphere::Compute::NotFound) unless dc
  dc
end

#get_datastore(name, datacenter_name) ⇒ Object



23
# File 'lib/fog/vsphere/requests/compute/get_datastore.rb', line 23

def get_datastore(name, datacenter_name); end

#get_folder(path, datacenter_name, _type = nil) ⇒ Object



76
77
78
79
# File 'lib/fog/vsphere/requests/compute/get_folder.rb', line 76

def get_folder(path, datacenter_name, _type = nil)
  data[:folders].values.find { |f| (f['datacenter'] == datacenter_name) && f['path'].end_with?(path) } ||
    raise(Fog::Vsphere::Compute::NotFound)
end

#get_folder_path(_folder, _root = nil) ⇒ Object



75
76
77
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 75

def get_folder_path(_folder, _root = nil)
  nil
end

#get_network(id) ⇒ Object



60
# File 'lib/fog/vsphere/requests/compute/get_network.rb', line 60

def get_network(id); end

#get_raw_clusters_from_folder(folder) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/fog/vsphere/requests/compute/list_clusters.rb', line 63

def get_raw_clusters_from_folder(folder)
  folder.map do |child|
    if child[:klass] == 'RbVmomi::VIM::ComputeResource'
      child
    elsif child[:klass] == 'RbVmomi::VIM::Folder'
      get_raw_clusters_from_folder(child[:clusters])
    end
  end.flatten
end

#get_resource_pool(name, cluster_name, datacenter_name) ⇒ Object



21
# 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_storage_pod(name, datacenter_name) ⇒ Object



23
24
25
# File 'lib/fog/vsphere/requests/compute/get_storage_pod.rb', line 23

def get_storage_pod(name, datacenter_name)
  list_storage_pods(datacenter: datacenter_name).detect { |h| h[:name] == name }
end

#get_template(id, datacenter_name = nil) ⇒ Object



11
# 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, _folder = nil, _recursive = false) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/fog/vsphere/requests/compute/get_virtual_machine.rb', line 63

def get_virtual_machine(id, datacenter_name = nil, _folder = nil, _recursive = false)
  vm = if is_uuid?(id)
         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
         list_virtual_machines('name' => id, 'datacenter' => datacenter_name).first
       end
  vm ? vm : raise(Fog::Vsphere::Compute::NotFound, "#{id} was not found")
end

#get_vm_first_scsi_controller(vm_id) ⇒ Object



21
# File 'lib/fog/vsphere/requests/compute/get_vm_first_scsi_controller.rb', line 21

def get_vm_first_scsi_controller(vm_id); end

#list_child_snapshots(_snapshot, _opts = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/vsphere/requests/compute/list_child_snapshots.rb', line 39

def list_child_snapshots(_snapshot, _opts = {})
  [
    {
      name: 'clean',
      quiesced: false,
      description: '',
      create_time: Time.now.utc,
      power_state: 'poweredOn',
      ref: 'snapshot-0101',
      mo_ref: nil,
      tree_node: nil,
      snapshot_name_chain: '123/clean',
      ref_chain: '123/snap-0101'
    },
    {
      name: 'dirty',
      quiesced: false,
      description: '',
      create_time: Time.now.utc,
      power_state: 'poweredOn',
      ref: 'snapshot-0102',
      mo_ref: nil,
      tree_node: nil,
      snapshot_name_chain: '123/dirty',
      ref_chain: '123/snap-0102'
    }
  ]
end

#list_clustersObject



52
53
54
55
56
# File 'lib/fog/vsphere/requests/compute/list_clusters.rb', line 52

def list_clusters(*)
  raw_clusters.map do |cluster|
    cluster
  end
end

#list_compute_resources(_filters = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fog/vsphere/requests/compute/list_compute_resources.rb', line 52

def list_compute_resources(_filters = {})
  [
    {
      id: 'domain-s7',
      name: 'fake-host',
      totalCpu: 33_504,
      totalMemory: 154_604_142_592,
      numCpuCores: 12,
      numCpuThreads: 24,
      effectiveCpu: 32_247,
      effectiveMemory: 135_733,
      numHosts: 1,
      numEffectiveHosts: 1,
      overallStatus: 'gray',
      overallCpuUsage: 15_682,
      overallMemoryUsage: 132_755,
      effective: true,
      isSingleHost: true
    }, {
      id: 'domain-s74',
      name: 'fake-cluster',
      totalCpu: 41_484,
      totalMemory: 51_525_996_544,
      numCpuCores: 12,
      numCpuThreads: 24,
      effectiveCpu: 37_796,
      effectiveMemory: 45_115,
      numHosts: 2,
      numEffectiveHosts: 2,
      overallStatus: 'gray',
      overallCpuUsage: 584,
      overallMemoryUsage: 26_422,
      effective: true,
      isSingleHost: false
    }
  ]
end

#list_datacenters(_filters = {}) ⇒ Object



47
48
49
# File 'lib/fog/vsphere/requests/compute/list_datacenters.rb', line 47

def list_datacenters(_filters = {})
  data[:datacenters].values
end

#list_datastores(filters) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fog/vsphere/requests/compute/list_datastores.rb', line 84

def list_datastores(filters)
  datacenter_name = filters[:datacenter]
  cluster_name = filters.fetch(:cluster, nil)
  if cluster_name.nil?
    data[:datastores].values.select { |d| d['datacenter'] == datacenter_name } ||
      raise(Fog::Vsphere::Compute::NotFound)
  else
    data[:datastores].values.select { |d| d['datacenter'] == datacenter_name && d['cluster'].include?(cluster_name) } ||
      raise(Fog::Vsphere::Compute::NotFound)
  end
end

#list_folders(options = {}) ⇒ Object



160
161
162
163
# File 'lib/fog/vsphere/requests/compute/list_folders.rb', line 160

def list_folders(options = {})
  options.reject! { |_k, v| v.nil? } # ignore options with nil value
  data[:folders].values.select { |folder| options.all? { |k, v| folder[k.to_s] == v.to_s } }
end

#list_groups(filters = {}) ⇒ Object



24
25
26
# File 'lib/fog/vsphere/requests/compute/list_groups.rb', line 24

def list_groups(filters = {})
  data[:groups].values.select { |g| g[:datacenter] == filters[:datacenter] && g[:cluster] == filters[:cluster] }
end

#list_hosts(filters = {}) ⇒ Object



95
96
97
# File 'lib/fog/vsphere/requests/compute/list_hosts.rb', line 95

def list_hosts(filters = {})
  data[:hosts].values.select { |r| r[:datacenter] == filters[:datacenter] && r[:cluster] == filters[:cluster] }
end

#list_networks(filters) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fog/vsphere/requests/compute/list_networks.rb', line 105

def list_networks(filters)
  datacenter_name = filters[:datacenter]
  cluster_name = filters.fetch(:cluster, nil)
  if cluster_name.nil?
    data[:networks].values.select { |d| d['datacenter'] == datacenter_name } ||
      raise(Fog::Vsphere::Compute::NotFound)
  else
    data[:networks].values.select { |d| d['datacenter'] == datacenter_name && d['cluster'].include?(cluster_name) } ||
      raise(Fog::Vsphere::Compute::NotFound)
  end
end

#list_processes(_vm_id, _opts = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/fog/vsphere/requests/compute/list_processes.rb', line 31

def list_processes(_vm_id, _opts = {})
  [
    Process.new(name: 'winlogon'),
    Process.new(name: 'init')
  ]
end

#list_resource_pools(filters = {}) ⇒ Object



53
# File 'lib/fog/vsphere/requests/compute/list_resource_pools.rb', line 53

def list_resource_pools(filters = {}); end

#list_rules(filters = {}) ⇒ Object



31
32
33
# File 'lib/fog/vsphere/requests/compute/list_rules.rb', line 31

def list_rules(filters = {})
  data[:rules].values.select { |r| r[:datacenter] == filters[:datacenter] && r[:cluster] == filters[:cluster] }
end

#list_server_types(_datacenter_name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/vsphere/requests/compute/list_server_types.rb', line 37

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_storage_pods(filters = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/fog/vsphere/requests/compute/list_storage_pods.rb', line 50

def list_storage_pods(filters = {})
  if filters.key?(:datacenter)
    data[:storage_pods].select { |h| h[:datacenter] == filters[:datacenter] }
  else
    data[:storage_pods]
  end
end

#list_templates(filters = {}) ⇒ Object



39
# File 'lib/fog/vsphere/requests/compute/list_templates.rb', line 39

def list_templates(filters = {}); end

#list_virtual_machines(options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 79

def list_virtual_machines(options = {})
  if options['instance_uuid']
    server = data[:servers][options['instance_uuid']]
    server.nil? ? [] : [server]
  elsif options['mo_ref']
    data[:servers].values.select { |vm| vm['mo_ref'] == options['mo_ref'] }
  elsif options[:folder] && options[:datacenter]
    data[:servers].values.select { |vm| vm['path'] == options[:folder] && vm['datacenter'] == options[:datacenter] }
  else
    options.delete('datacenter') # real code iterates if this is missing
    options.reject! { |_k, v| v.nil? } # ignore options with nil value
    data[:servers].values.select { |vm| options.all? { |k, v| vm[k.to_s] == v.to_s } }
  end
end

#list_vm_cdroms(vm_id) ⇒ Object

Raises:

  • (Fog::Vsphere::Compute::NotFound)


27
28
29
30
31
# File 'lib/fog/vsphere/requests/compute/list_vm_cdroms.rb', line 27

def list_vm_cdroms(vm_id)
  raise Fog::Vsphere::Compute::NotFound, 'VM not Found' unless data[:servers].key?(vm_id)
  return [] unless data[:servers][vm_id].key?('cdroms')
  data[:servers][vm_id]['cdroms'].map { |h| h.merge(instance_uuid: vm_id) }
end

#list_vm_customfields(vm_id) ⇒ Object



16
# File 'lib/fog/vsphere/requests/compute/list_customfields.rb', line 16

def list_vm_customfields; end

#list_vm_interfaces(vm_id) ⇒ Object



88
# File 'lib/fog/vsphere/requests/compute/list_vm_interfaces.rb', line 88

def list_vm_interfaces(vm_id); end

#list_vm_scsi_controllers(vm_id) ⇒ Object

Raises:

  • (Fog::Vsphere::Compute::NotFound)


23
24
25
26
27
# File 'lib/fog/vsphere/requests/compute/list_vm_scsi_controllers.rb', line 23

def list_vm_scsi_controllers(vm_id)
  raise Fog::Vsphere::Compute::NotFound, 'VM not Found' unless data[:servers].key?(vm_id)
  return [] unless data[:servers][vm_id].key?('scsi_controllers')
  data[:servers][vm_id]['scsi_controllers'].map { |h| h.merge(server_id: vm_id) }
end

#list_vm_snapshots(vm_id, _opts = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/vsphere/requests/compute/list_vm_snapshots.rb', line 40

def list_vm_snapshots(vm_id, _opts = {})
  [
    {
      name: 'clean',
      quiesced: false,
      description: '',
      create_time: Time.now.utc,
      power_state: 'poweredOn',
      ref: 'snapshot-0101',
      mo_ref: nil,
      tree_node: nil,
      snapshot_name_chain: '123/clean',
      ref_chain: "#{vm_id}/snapshot-0101"
    },
    {
      name: 'dirty',
      quiesced: false,
      description: '',
      create_time: Time.now.utc,
      power_state: 'poweredOn',
      ref: 'snapshot-0102',
      mo_ref: nil,
      tree_node: nil,
      snapshot_name_chain: '123/dirty',
      ref_chain: "#{vm_id}/snapshot-0102"
    }
  ]
end

#list_vm_volumes(vm_id) ⇒ Object



57
# File 'lib/fog/vsphere/requests/compute/list_vm_volumes.rb', line 57

def list_vm_volumes(vm_id); end

#raw_clustersObject



58
59
60
61
# File 'lib/fog/vsphere/requests/compute/list_clusters.rb', line 58

def raw_clusters
  folder = data[:clusters]
  @raw_clusters = get_raw_clusters_from_folder(folder)
end

#remove_vm_volume(_volume) ⇒ Object



25
26
27
# File 'lib/fog/vsphere/requests/compute/modify_vm_volume.rb', line 25

def remove_vm_volume(_volume)
  true
end

#reset_dataObject



605
606
607
# File 'lib/fog/vsphere/compute.rb', line 605

def reset_data
  self.class.data.delete(@vsphere_username)
end

#revert_to_snapshot(snapshot) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/fog/vsphere/requests/compute/revert_to_snapshot.rb', line 20

def revert_to_snapshot(snapshot)
  raise ArgumentError, 'snapshot is a required parameter' if snapshot.nil?

  {
    'state' => 'success'
  }
end

#set_vm_customvalue(_vm_id, _key, _value) ⇒ Object



11
12
13
# File 'lib/fog/vsphere/requests/compute/set_vm_customvalue.rb', line 11

def set_vm_customvalue(_vm_id, _key, _value)
  nil
end

#update_vm(_server) ⇒ Object



111
112
113
114
# File 'lib/fog/vsphere/requests/compute/update_vm.rb', line 111

def update_vm(_server)
  # TODO: - currently useless and tests need to be re-though on a whole.
  { 'task_state' => 'success' }
end

#update_vm_interface(_vmid, options = {}) ⇒ Object



85
86
87
88
89
# File 'lib/fog/vsphere/requests/compute/modify_vm_interface.rb', line 85

def update_vm_interface(_vmid, options = {})
  return unless options[:interface]
  options[:interface].network = options[:network]
  options[:interface].type    = options[:type]
end

#vm_acquire_ticket(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
# File 'lib/fog/vsphere/requests/compute/vm_acquire_ticket.rb', line 22

def vm_acquire_ticket(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key?('instance_uuid')
  {
    'ticket' => 'fdsfdsf',
    'host' => 'esxi.example.com',
    'port' => 443,
    'ssl_thumbprint' => '1C:63:E1:BD:56:03:EB:44:85:12:12:FC:DA:40:11:65:0E:30:A1:B8'
  }
end

#vm_clone(options = {}) ⇒ Object



883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
# File 'lib/fog/vsphere/requests/compute/vm_clone.rb', line 883

def vm_clone(options = {})
  # Option handling TODO Needs better method of checking
  options = vm_clone_check_options(options)
  notfound = -> { raise Fog::Vsphere::Compute::NotFound, 'Could not find VM template' }
  template = list_virtual_machines.find(notfound) do |vm|
    vm['name'] == options['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' => options['name'],
                                'id' => id,
                                'instance_uuid' => id,
                                'path' => "/Datacenters/#{options['datacenter']}/#{options['dest_folder'] ? options['dest_folder'] + '/' : ''}#{options['name']}")
  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

Raises:

  • (ArgumentError)


34
35
36
37
# File 'lib/fog/vsphere/requests/compute/vm_config_vnc.rb', line 34

def vm_config_vnc(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_destroy(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/fog/vsphere/requests/compute/vm_destroy.rb', line 16

def vm_destroy(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_execute(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
# File 'lib/fog/vsphere/requests/compute/vm_execute.rb', line 37

def vm_execute(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  raise ArgumentError, 'command is a required parameter' unless options.key? 'command'
  raise ArgumentError, 'user is a required parameter' unless options.key? 'user'
  raise ArgumentError, 'password is a required parameter' unless options.key? 'password'
  12_345
end

#vm_get_vnc(_uuid) ⇒ Object



39
40
41
# File 'lib/fog/vsphere/requests/compute/vm_config_vnc.rb', line 39

def vm_get_vnc(_uuid)
  { password: 'secret', port: '5900', enabled: 'true' }
end

#vm_migrate(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/fog/vsphere/requests/compute/vm_migrate.rb', line 34

def vm_migrate(options = {})
  priority = options['priority'].nil? ? 'defaultPriority' : options['priority']
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_power_off(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
# File 'lib/fog/vsphere/requests/compute/vm_power_off.rb', line 27

def vm_power_off(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  vm = get_virtual_machine(options['instance_uuid'])
  vm['power_state'] = 'poweredOff'
  {
    'task_state'     => 'running',
    'power_off_type' => options['force'] ? 'cut_power' : 'shutdown_guest'
  }
end

#vm_power_on(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
# File 'lib/fog/vsphere/requests/compute/vm_power_on.rb', line 19

def vm_power_on(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_reboot(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/fog/vsphere/requests/compute/vm_reboot.rb', line 24

def vm_reboot(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'running', 'reboot_type' => options['force'] ? 'reset_power' : 'reboot_guest' }
end

#vm_reconfig_cdrom(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_cdrom.rb', line 37

def vm_reconfig_cdrom(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  if options.key?('iso')
    raise ArgumentError, 'datastore is a required parameter' unless options.key? 'datastore'
    backing = {
      fileName: "[#{options['datastore']}] #{options['iso']}"
    }
  else
    backing = { deviceName: '' }
  end
  cdrom_obj = list_vm_cdroms(options['instance_uuid']).first
  hardware_spec = {
    deviceChange: [{
      operation: :edit,
      device: {
        backing: backing,
        key: cdrom_obj['key'],
        controllerKey: cdrom_obj['controllerKey'],
        connectable: {
          startConnected: options['start_connected'] || false,
          connected: options['connected'] || false,
          allowGuestControl: options['allow_guest_control'] || true
        }
      }
    }]
  }
  vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec)
end

#vm_reconfig_cpus(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb', line 14

def vm_reconfig_cpus(options = {})
  raise ArgumentError, 'cpus is a required parameter' unless options.key? 'cpus'
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  hardware_spec = { 'numCPUs' => options['cpus'], 'numCoresPerSocket' => options['corespersocket'] }
  vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec)
end

#vm_reconfig_hardware(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb', line 16

def vm_reconfig_hardware(options = {})
  raise ArgumentError, 'hardware_spec is a required parameter' unless options.key? 'hardware_spec'
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_reconfig_memory(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb', line 14

def vm_reconfig_memory(options = {})
  raise ArgumentError, 'memory is a required parameter' unless options.key? 'memory'
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  hardware_spec = { 'memoryMB' => options['memory'] }
  vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec)
end

#vm_reconfig_volumes(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fog/vsphere/requests/compute/vm_reconfig_volumes.rb', line 19

def vm_reconfig_volumes(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  raise ArgumentError, 'volumes is a required parameter' unless options.key? 'volumes'
  hardware_spec = {
    deviceChange: []
  }
  options['volumes'].each do |volume|
    hardware_spec[:deviceChange].push(operation: :edit,
                                      device: {
                                        backing: { diskMode: volume.mode, fileName: volume.filename },
                                        unitNumber: volume.unit_number,
                                        key: volume.key,
                                        controllerKey: volume.controller_key,
                                        capacityInKB: volume.size
                                      })
  end
  vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec)
end

#vm_relocate(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


95
96
97
98
# File 'lib/fog/vsphere/requests/compute/vm_relocate.rb', line 95

def vm_relocate(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_remove_snapshot(_vm_id, _snapshot_id) ⇒ Object



20
21
22
23
24
25
# File 'lib/fog/vsphere/requests/compute/vm_remove_snapshot.rb', line 20

def vm_remove_snapshot(_vm_id, _snapshot_id)
  {
    'task_state' => 'success',
    'was_cancelled' => false
  }
end

#vm_rename(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/fog/vsphere/requests/compute/vm_rename.rb', line 16

def vm_rename(options = {})
  raise ArgumentError, 'name is a required parameter' unless options.key? 'name'
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  { 'task_state' => 'success' }
end

#vm_revert_snapshot(_vm_id, _snapshot_id) ⇒ Object



20
21
22
23
24
25
# File 'lib/fog/vsphere/requests/compute/vm_revert_snapshot.rb', line 20

def vm_revert_snapshot(_vm_id, _snapshot_id)
  {
    'task_state' => 'success',
    'was_cancelled' => false
  }
end

#vm_suspend(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/vsphere/requests/compute/vm_suspend.rb', line 40

def vm_suspend(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'

  vm = get_virtual_machine(options['instance_uuid'])
  vm['power_state'] = 'suspended'

  {
    'task_state'   => 'running',
    'suspend_type' => options['force'] ? 'suspend' : 'standby_guest'
  }
end

#vm_take_snapshot(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
# File 'lib/fog/vsphere/requests/compute/vm_take_snapshot.rb', line 26

def vm_take_snapshot(options = {})
  raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
  raise ArgumentError, 'name is a required parameter' unless options.key? 'name'
  {
    'task_state' => 'success',
    'was_cancelled' => false
  }
end