Class: VCloudCloud::Steps::AddNetworks

Inherits:
VCloudCloud::Step show all
Defined in:
lib/cloud/vcloud/steps/add_networks.rb

Instance Attribute Summary

Attributes inherited from VCloudCloud::Step

#client, #state

Instance Method Summary collapse

Methods inherited from VCloudCloud::Step

#cleanup, #initialize, #rollback

Constructor Details

This class inherits a constructor from VCloudCloud::Step

Instance Method Details

#perform(networks, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cloud/vcloud/steps/add_networks.rb', line 4

def perform(networks, &block)
  vapp = client.reload state[:vapp]
  org_networks = client.vdc.available_networks
  networks.each do |name|
    @logger.debug "NETWORK ADD #{name}"
    # find the corresponding accessible network object in org
    org_net = org_networks.find { |n| n.name == name }
    raise "Network #{name} not accesible to VDC #{client.vdc.name}" unless org_net
    # clone the configuration
    config = VCloudSdk::Xml::WrapperFactory.create_instance 'NetworkConfig'
    copy_network_settings client.reload(org_net), config, org_net.name, VCloudSdk::Xml::FENCE_MODES[:BRIDGED]
    vapp.network_config_section.add_network_config config
    client.invoke_and_wait :put, vapp.network_config_section,
            :payload => vapp.network_config_section,
            :headers => { :content_type => VCloudSdk::Xml::MEDIA_TYPE[:NETWORK_CONFIG_SECTION] }
  end
  state[:vapp] = client.reload vapp
end