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_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/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



87
88
89
90
91
92
93
94
95
# File 'lib/fog/vsphere/compute.rb', line 87

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

#vm_clone(options = {}) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/fog/vsphere/requests/compute/vm_clone.rb', line 120

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_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