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
- #catalog(name) ⇒ Object
- #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
- #template(catalog_name, template_name) ⇒ Object
- #vdc(name) ⇒ Object
Constructor Details
#initialize(fog = FogFacade.new) ⇒ ServiceInterface
Returns a new instance of ServiceInterface.
167 168 169 |
# File 'lib/vcloud/fog/service_interface.rb', line 167 def initialize (fog = FogFacade.new) @fog = fog end |
Instance Method Details
#catalog(name) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/vcloud/fog/service_interface.rb', line 183 def catalog(name) link = org[:Link].select { |l| l[:rel] == RELATION::CHILD }.detect do |l| l[:type] == ContentTypes::CATALOG && l[:name] == name end raise "catalog #{name} cannot be found" unless link @fog.get_catalog(extract_id(link)) end |
#find_networks(network_names, vdc_name) ⇒ Object
224 225 226 227 228 229 230 |
# File 'lib/vcloud/fog/service_interface.rb', line 224 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
178 179 180 181 |
# File 'lib/vcloud/fog/service_interface.rb', line 178 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
171 172 173 174 175 176 |
# File 'lib/vcloud/fog/service_interface.rb', line 171 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
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/vcloud/fog/service_interface.rb', line 232 def put_guest_customization_section(vm_id, vm_name, script) begin Vcloud::Core.logger.info("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 Vcloud::Core.logger.info("=== interpolated preamble:") Vcloud::Core.logger.info(script) raise end end |
#put_network_connection_system_section_vapp(vm_id, section) ⇒ Object
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/vcloud/fog/service_interface.rb', line 213 def put_network_connection_system_section_vapp(vm_id, section) begin Vcloud::Core.logger.info("adding NIC into VM #{vm_id}") @fog.put_network_connection_system_section_vapp(vm_id, section) rescue Vcloud::Core.logger.info("failed to put_network_connection_system_section_vapp for vm : #{vm_id} ") Vcloud::Core.logger.info("requested network section : #{section.inspect}") raise end end |
#template(catalog_name, template_name) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/vcloud/fog/service_interface.rb', line 200 def template(catalog_name, template_name) link = catalog(catalog_name)[:CatalogItems][:CatalogItem].detect do |l| l[:type] == ContentTypes::CATALOG_ITEM && l[:name].match(template_name) end if link.nil? Vcloud::Core.logger.warn("Template #{template_name} not found in catalog #{catalog_name}") return nil end catalog_item = @fog.get_catalog_item(extract_id(link)) catalog_item[:Entity] end |
#vdc(name) ⇒ Object
191 192 193 194 195 196 197 198 |
# File 'lib/vcloud/fog/service_interface.rb', line 191 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 |