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/vm_create.rb,
lib/fog/vsphere/requests/compute/vm_reboot.rb,
lib/fog/vsphere/requests/compute/vm_destroy.rb,
lib/fog/vsphere/requests/compute/datacenters.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/find_vm_by_ref.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_cpus.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_memory.rb,
lib/fog/vsphere/requests/compute/vm_reconfig_hardware.rb,
lib/fog/vsphere/requests/compute/list_virtual_machines.rb

Constant Summary

Constants included from Shared

Shared::ATTR_TO_PROP

Instance Attribute Summary

Attributes included from Shared

#vsphere_is_vcenter, #vsphere_rev, #vsphere_server, #vsphere_username

Instance Method Summary collapse

Methods included from Shared

#convert_vm_mob_ref_to_attr_hash, #find_vm_by_ref

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



91
92
93
94
95
96
97
98
99
# File 'lib/fog/vsphere/compute.rb', line 91

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

#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

#datacentersObject



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

def datacenters
  [ "Solutions", "Solutions2", "Solutions3" ]
end

#get_folder_path(folder, root = nil) ⇒ Object



133
134
135
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 133

def get_folder_path(folder, root = nil)
  nil
end

#list_virtual_machines(options = {}) ⇒ Object



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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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
# File 'lib/fog/vsphere/requests/compute/list_virtual_machines.rb', line 137

def list_virtual_machines(options = {})
  case options['instance_uuid']
  when nil
    rval = YAML.load <<-'ENDvmLISTING'
---
virtual_machines:
- name: centos56gm
  hypervisor: gunab.puppetlabs.lan
  tools_version: guestToolsCurrent
  ipaddress:
  mo_ref: vm-698
  power_state: poweredOff
  uuid: 42322347-d791-cd34-80b9-e25fe28ad37c
  is_a_template: true
  id: 50323f93-6835-1178-8b8f-9e2109890e1a
  tools_state: toolsNotRunning
  connection_state: connected
  instance_uuid: 50323f93-6835-1178-8b8f-9e2109890e1a
  hostname:
  mac_addresses:
    Network adapter 1: 00:50:56:b2:00:a1
  operatingsystem:
- name: centos56gm2
  hypervisor: gunab.puppetlabs.lan
  tools_version: guestToolsCurrent
  ipaddress:
  mo_ref: vm-640
  power_state: poweredOff
  uuid: 564ddcbe-853a-d29a-b329-a0a3693a004d
  is_a_template: true
  id: 5257dee8-050c-cbcd-ae25-db0e582ab530
  tools_state: toolsNotRunning
  connection_state: connected
  instance_uuid: 5257dee8-050c-cbcd-ae25-db0e582ab530
  hostname:
  mac_addresses:
    Network adapter 1: 00:0c:29:3a:00:4d
  operatingsystem:
- name: dashboard_gm
  hypervisor: gunab.puppetlabs.lan
  tools_version: guestToolsCurrent
  ipaddress: 192.168.100.184
  mo_ref: vm-669
  power_state: poweredOn
  uuid: 564d3f91-3452-a509-a678-1246f7897979
  is_a_template: false
  id: 5032739c-c871-c0d2-034f-9700a0b5383e
  tools_state: toolsOk
  connection_state: connected
  instance_uuid: 5032739c-c871-c0d2-034f-9700a0b5383e
  hostname: compliance.puppetlabs.vm
  mac_addresses:
    Network adapter 1: 00:50:56:b2:00:96
  operatingsystem: Red Hat Enterprise Linux 6 (64-bit)
- name: jefftest
  hypervisor: gunab.puppetlabs.lan
  tools_version: guestToolsCurrent
  ipaddress: 192.168.100.187
  mo_ref: vm-715
  power_state: poweredOn
  uuid: 42329da7-e8ab-29ec-1892-d6a4a964912a
  is_a_template: false
  id: 5032c8a5-9c5e-ba7a-3804-832a03e16381
  tools_state: toolsOk
  connection_state: connected
  instance_uuid: 5032c8a5-9c5e-ba7a-3804-832a03e16381
  hostname: centos56gm.localdomain
  mac_addresses:
    Network adapter 1: 00:50:56:b2:00:af
  operatingsystem: CentOS 4/5 (32-bit)
ENDvmLISTING
  when '5032c8a5-9c5e-ba7a-3804-832a03e16381'
    YAML.load <<-'5032c8a5-9c5e-ba7a-3804-832a03e16381'
---
virtual_machines:
- name: jefftest
  hypervisor: gunab.puppetlabs.lan
  tools_version: guestToolsCurrent
  ipaddress: 192.168.100.187
  mo_ref: vm-715
  power_state: poweredOn
  uuid: 42329da7-e8ab-29ec-1892-d6a4a964912a
  is_a_template: false
  id: 5032c8a5-9c5e-ba7a-3804-832a03e16381
  tools_state: toolsOk
  connection_state: connected
  instance_uuid: 5032c8a5-9c5e-ba7a-3804-832a03e16381
  hostname: centos56gm.localdomain
  mac_addresses:
    Network adapter 1: 00:50:56:b2:00:af
  operatingsystem: CentOS 4/5 (32-bit)
    5032c8a5-9c5e-ba7a-3804-832a03e16381
  when 'does-not-exist-and-is-not-a-uuid', '50323f93-6835-1178-8b8f-9e2109890e1a'
    { 'virtual_machines' => [] }
  end
end

#vm_clone(options = {}) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/fog/vsphere/requests/compute/vm_clone.rb', line 155

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

#vm_create(options = {}) ⇒ Object



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

def vm_create(options = {})
  # Option handling
  options = vm_create_check_options(options)
  {
    'vm_ref'   => 'vm-123',
    'task_ref' => 'task-1234'
  }
end

#vm_destroy(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

def vm_destroy(options = {})
  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)


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

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