Class: Vcloud::Core::OrgVdcNetwork

Inherits:
Object
  • Object
show all
Defined in:
lib/vcloud/core/org_vdc_network.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Vcloud::Core::OrgVdcNetwork

Return an object referring to a particular OrgVdcNetwork

Parameters:

  • id (String)

    The ID of the network



11
12
13
14
15
16
# File 'lib/vcloud/core/org_vdc_network.rb', line 11

def initialize(id)
  unless id =~ /^[-0-9a-f]+$/
    raise "orgVdcNetwork id : #{id} is not in correct format"
  end
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/vcloud/core/org_vdc_network.rb', line 5

def id
  @id
end

Class Method Details

.construct_network_options(config) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/vcloud/core/org_vdc_network.rb', line 84

def self.construct_network_options(config)
  opts = {}
  opts[:Description] = config[:description] if config.key?(:description)
  opts[:IsShared] = config[:is_shared]

  ip_scope = {}
  ip_scope[:IsInherited] = config[:is_inherited] || false
  ip_scope[:Gateway]     = config[:gateway] if config.key?(:gateway)
  ip_scope[:Netmask]     = config[:netmask] if config.key?(:netmask)
  ip_scope[:Dns1]        = config[:dns1] if config.key?(:dns1)
  ip_scope[:Dns2]        = config[:dns2] if config.key?(:dns2)
  ip_scope[:DnsSuffix]   = config[:dns_suffix] if config.key?(:dns_suffix)
  ip_scope[:IsEnabled]   = config[:is_enabled] || true

  if config.key?(:ip_ranges) && config[:ip_ranges].size > 0
    ip_scope[:IpRanges] = []
    config[:ip_ranges].each do |range|
      ip_scope[:IpRanges] << {
        :IpRange => {
          :StartAddress => range[:start_address],
          :EndAddress   => range[:end_address]
        }
      }
    end
  end

  opts[:Configuration] = {
    :FenceMode => config[:fence_mode],
    :IpScopes => {
      :IpScope => ip_scope
    },
  }

  opts
end

.provision(config) ⇒ Vcloud::Core::OrgVdcNetwork

Configure OrgVdcNetwork

Parameters:

  • config (Hash)

    the configuration to apply to network

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vcloud/core/org_vdc_network.rb', line 22

def self.provision(config)
  raise "Must specify a name" unless config[:name]
  raise "Must specify a vdc_name" unless config[:vdc_name]
  unless config[:fence_mode] == 'isolated' || config[:fence_mode] == 'natRouted'
    raise "fence_mode #{config[:fence_mode]} not supported. Must be 'isolated' or 'natRouted'"
  end

  name = config[:name]
  vdc_name = config[:vdc_name]

  config[:is_shared] = false unless config[:is_shared]

  if config[:fence_mode] == 'natRouted'
    raise "Must specify an edge_gateway to connect to" unless config.key?(:edge_gateway)
    edgegw = Vcloud::Core::EdgeGateway.get_by_name(config[:edge_gateway])
  end

  vdc = Vcloud::Core::Vdc.get_by_name(vdc_name)

  options = construct_network_options(config)
  options[:EdgeGateway] = { :href => edgegw.href } if edgegw

  begin
    Vcloud::Core.logger.info("Provisioning new OrgVdcNetwork #{name} in vDC '#{vdc_name}'")
    attrs = Vcloud::Core::Fog::ServiceInterface.new.post_create_org_vdc_network(vdc.id, name, options)
  rescue RuntimeError => e
    Vcloud::Core.logger.error("Could not provision orgVdcNetwork: #{e.message}")
  end

  raise "Did not successfully create orgVdcNetwork" unless attrs && attrs.key?(:href)
  self.new(attrs[:href].split('/').last)

end

Instance Method Details

#deletevoid

This method returns an undefined value.

Delete OrgVdcNetwork



80
81
82
# File 'lib/vcloud/core/org_vdc_network.rb', line 80

def delete
  Vcloud::Core::Fog::ServiceInterface.new.delete_network(id)
end

#hrefString

Return the href of OrgVdcNetwork

Returns:

  • (String)

    the href of instance



73
74
75
# File 'lib/vcloud/core/org_vdc_network.rb', line 73

def href
  vcloud_attributes[:href]
end

#nameString

Return the name of OrgVdcNetwork

Returns:

  • (String)

    the name of instance



66
67
68
# File 'lib/vcloud/core/org_vdc_network.rb', line 66

def name
  vcloud_attributes[:name]
end

#vcloud_attributesHash

Return all the vcloud attributes of OrgVdcNetwork

Returns:

  • (Hash)

    a hash describing all the attributes of OrgVdcNetwork



59
60
61
# File 'lib/vcloud/core/org_vdc_network.rb', line 59

def vcloud_attributes
  Vcloud::Core::Fog::ServiceInterface.new.get_network_complete(id)
end