Class: Vcloud::Core::Fog::ServiceInterface Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vcloud/core/fog/service_interface.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Private interface to the fog service layer. You should not use this directly. Expose required functionality in ApiInterface

Defined Under Namespace

Classes: FogFacade

Instance Method Summary collapse

Constructor Details

#initialize(fog = FogFacade.new) ⇒ ServiceInterface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ServiceInterface.



221
222
223
# File 'lib/vcloud/core/fog/service_interface.rb', line 221

def initialize (fog = FogFacade.new)
  @fog = fog
end

Instance Method Details

#find_networks(network_names, vdc_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



257
258
259
260
261
262
263
# File 'lib/vcloud/core/fog/service_interface.rb', line 257

def find_networks(network_names, vdc_name)
  network_names.collect do |network|
    vdc(vdc_name)[:AvailableNetworks][:Network].detect do |l|
      l[:type] == ContentTypes::NETWORK && l[:name] == network
    end
  end
end

#get_vapp_by_name_and_vdc_name(name, vdc_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



232
233
234
235
# File 'lib/vcloud/core/fog/service_interface.rb', line 232

def get_vapp_by_name_and_vdc_name name, vdc_name
  response_body = @fog.get_vapps_in_lease_from_query({:filter => "name==#{name}"})
  response_body[:VAppRecord].detect { |record| record[:vdcName] == vdc_name }
end

#orgObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



225
226
227
228
229
230
# File 'lib/vcloud/core/fog/service_interface.rb', line 225

def org
  link = session[:Link].select { |l| l[:rel] == RELATION::CHILD }.detect do |l|
    l[:type] == ContentTypes::ORG
  end
  @fog.get_organization(link[:href].split('/').last)
end

#put_guest_customization_section(vm_id, vm_name, script) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/vcloud/core/fog/service_interface.rb', line 265

def put_guest_customization_section(vm_id, vm_name, script)
  begin
    Vcloud::Core.logger.debug("configuring guest customization section for vm : #{vm_id}")
    customization_req = {
      :Enabled             => true,
      :CustomizationScript => script,
      :ComputerName        => vm_name
    }
    @fog.put_guest_customization_section_vapp(vm_id, customization_req)
  rescue => ex
    Vcloud::Core.logger.error("Failed to update guest customization section: #{ex}")
    Vcloud::Core.logger.debug("=== interpolated preamble:")
    Vcloud::Core.logger.debug(script)
    raise
  end
end

#put_network_connection_system_section_vapp(vm_id, section) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



246
247
248
249
250
251
252
253
254
255
# File 'lib/vcloud/core/fog/service_interface.rb', line 246

def put_network_connection_system_section_vapp(vm_id, section)
  begin
    Vcloud::Core.logger.debug("adding NIC into VM #{vm_id}")
    @fog.put_network_connection_system_section_vapp(vm_id, section)
  rescue => ex
    Vcloud::Core.logger.error("failed to put_network_connection_system_section_vapp for vm #{vm_id}: #{ex}")
    Vcloud::Core.logger.debug("requested network section : #{section.inspect}")
    raise
  end
end

#vdc(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



237
238
239
240
241
242
243
244
# File 'lib/vcloud/core/fog/service_interface.rb', line 237

def vdc(name)
  link = org[:Link].select { |l| l[:rel] == RELATION::CHILD }.detect do |l|
    l[:type] == ContentTypes::VDC && l[:name] == name
  end
  raise "vdc #{name} cannot be found" unless link
  @fog.get_vdc(link[:href].split('/').last)

end