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

Inherits:
Object
  • Object
show all
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/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_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_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/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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



161
162
163
164
165
166
167
168
169
# File 'lib/fog/vsphere/compute.rb', line 161

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

Instance Method Details

#create_vm(attributes = { }) ⇒ Object



108
109
# File 'lib/fog/vsphere/requests/compute/create_vm.rb', line 108

def create_vm attributes = { }
end

#current_timeObject



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

def current_time
  { 'current_time' => Time.now.utc }
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
# File 'lib/fog/vsphere/requests/compute/get_datacenter.rb', line 23

def get_datacenter name
  {:name => "Solutions", :status => "grey"}
end

#get_datastore(name, datacenter_name) ⇒ Object



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

def get_datastore(name, datacenter_name)
end

#get_folder(path, filters = { }) ⇒ Object



67
68
# File 'lib/fog/vsphere/requests/compute/get_folder.rb', line 67

def get_folder(path, filters = { })
end

#get_folder_path(folder, root = nil) ⇒ Object



50
51
52
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 50

def get_folder_path(folder, root = nil)
  nil
end

#get_network(id) ⇒ Object



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

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_virtual_machine(id, datacenter_name = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/vsphere/requests/compute/get_virtual_machine.rb', line 29

def get_virtual_machine(id, datacenter_name = nil)
  case id
  when "5032c8a5-9c5e-ba7a-3804-832a03e16381", 'vm-715'
    { :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",
      :instance_uuid    => "5029c440-85ee-c2a1-e9dd-b63e39364603",
      :hypervisor       => "gunab.puppetlabs.lan",
      :guest_id         => "rhel6_64Guest",
      :cluster          => "virtlabcluster",
      :tools_state      => "toolsOk",
      :name             => "jefftest",
      :operatingsystem  => "Red Hat Enterprise Linux 6 (64-bit)",
      :path             => "/",
      :tools_version    => "guestToolsUnmanaged",
      :ipaddress        => "192.168.100.187",
      :id               => "5032c8a5-9c5e-ba7a-3804-832a03e16381",
      :uuid             => "42329da7-e8ab-29ec-1892-d6a4a964912a"
    }
  end
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



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

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_virtual_machines(options = { }) ⇒ Object



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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 54

def list_virtual_machines(options = { })
  case options['instance_uuid']
    when nil

      [
        { :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)",
          :uuid             => "4229f0e9-bfdc-d9a7-7bac-12070772e6dc",
          :path             => "/Datacenters/Solutions/vm",
          :id               => "5029c440-85ee-c2a1-e9dd-b63e39364603",
          :tools_version    => "guestToolsUnmanaged",
          :ipaddress        => "192.168.100.184",
        },
        { :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" }],
          :instance_uuid    => "502916a3-b42e-17c7-43ce-b3206e9524dc",
          :hypervisor       => "gunab.puppetlabs.lan",
          :guest_id         => nil,
          :cluster          => "Solutionscluster",
          :tools_state      => "toolsNotInstalled",
          :uuid             => "4229e0de-30cb-ceb2-21f9-4d8d8beabb52",
          :name             => "i-1342439683",
          :operatingsystem  => nil,
          :path             => "/",
          :tools_version    => "guestToolsNotInstalled",
          :id               => "502916a3-b42e-17c7-43ce-b3206e9524dc",
          :ipaddress        => nil }


      ]
    when '5032c8a5-9c5e-ba7a-3804-832a03e16381'
      [{ :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",
         :instance_uuid    => "5029c440-85ee-c2a1-e9dd-b63e39364603",
         :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",
         :id               => "5032c8a5-9c5e-ba7a-3804-832a03e16381",
         :uuid             => "42329da7-e8ab-29ec-1892-d6a4a964912a"

       }

      ]
    when 'does-not-exist-and-is-not-a-uuid', '50323f93-6835-1178-8b8f-9e2109890e1a'
      []
  end
end

#list_vm_interfaces(vm_id) ⇒ Object



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

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

#vm_clone(options = {}) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/fog/vsphere/requests/compute/vm_clone.rb', line 192

def vm_clone(options = {})
  # Option handling
  options = vm_clone_check_options(options)
  notfound = lambda { raise Fog::Compute::Vsphere::NotFound, "Could not find VM template" }
  list_virtual_machines.find(notfound) do |vm|
    vm[:name] == options['path'].split("/")[-1]
  end
  {
    'vm_ref'   => 'vm-123',
    'task_ref' => 'task-1234',
  }
end

#vm_config_vnc(options = { }) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#vm_destroy(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

def vm_destroy(options = {})
  raise ArgumentError, "instance_uuid is a required parameter" unless options.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

Raises:

  • (ArgumentError)


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

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

#vm_power_off(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#vm_power_on(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#vm_reboot(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

def vm_reboot(options = {})
  raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
  { 'task_state'     => "running", 'reboot_type' => options['force'] ? 'reset_power' : 'reboot_guest' }
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.has_key? 'cpus'
  raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
  hardware_spec={'numCPUs' => options['cpus']}
  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.has_key? 'hardware_spec'
  raise ArgumentError, "instance_uuid is a required parameter" unless options.has_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.has_key? 'memory'
  raise ArgumentError, "instance_uuid is a required parameter" unless options.has_key? 'instance_uuid'
  hardware_spec={'memoryMB' => options['memory']}
  vm_reconfig_hardware('instance_uuid' => options['instance_uuid'], 'hardware_spec' => hardware_spec )
end