Class: Vcloud::Fog::ServiceInterface
- Inherits:
-
Object
- Object
- Vcloud::Fog::ServiceInterface
- Extended by:
- Forwardable
- Defined in:
- lib/vcloud/fog/service_interface.rb
Defined Under Namespace
Classes: FogFacade
Instance Method Summary collapse
- #find_networks(network_names, vdc_name) ⇒ Object
- #get_vapp_by_name_and_vdc_name(name, vdc_name) ⇒ Object
-
#initialize(fog = FogFacade.new) ⇒ ServiceInterface
constructor
A new instance of ServiceInterface.
- #org ⇒ Object
- #put_guest_customization_section(vm_id, vm_name, script) ⇒ Object
- #put_network_connection_system_section_vapp(vm_id, section) ⇒ Object
- #vdc(name) ⇒ Object
Constructor Details
#initialize(fog = FogFacade.new) ⇒ ServiceInterface
Returns a new instance of ServiceInterface.
179 180 181 |
# File 'lib/vcloud/fog/service_interface.rb', line 179 def initialize (fog = FogFacade.new) @fog = fog end |
Instance Method Details
#find_networks(network_names, vdc_name) ⇒ Object
215 216 217 218 219 220 221 |
# File 'lib/vcloud/fog/service_interface.rb', line 215 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
190 191 192 193 |
# File 'lib/vcloud/fog/service_interface.rb', line 190 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 |
#org ⇒ Object
183 184 185 186 187 188 |
# File 'lib/vcloud/fog/service_interface.rb', line 183 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
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/vcloud/fog/service_interface.rb', line 223 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
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/vcloud/fog/service_interface.rb', line 204 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
195 196 197 198 199 200 201 202 |
# File 'lib/vcloud/fog/service_interface.rb', line 195 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 |