Class: Fog::Generators::Compute::VcloudDirector::OrgVdcNetwork

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/vcloud_director/generators/compute/org_vdc_network.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OrgVdcNetwork

Returns a new instance of OrgVdcNetwork


9
10
11
# File 'lib/fog/vcloud_director/generators/compute/org_vdc_network.rb', line 9

def initialize(options={})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


7
8
9
# File 'lib/fog/vcloud_director/generators/compute/org_vdc_network.rb', line 7

def options
  @options
end

Instance Method Details

#generate_xmlObject


13
14
15
16
17
18
19
20
21
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/vcloud_director/generators/compute/org_vdc_network.rb', line 13

def generate_xml
  body = Nokogiri::XML::Builder.new do
    attrs = {
      :xmlns => 'http://www.vmware.com/vcloud/v1.5',
      :name  => options[:name]
    }
    OrgVdcNetwork(attrs) {
      Description options[:Description] if options.key?(:Description)
      if configuration = options[:Configuration]
        Configuration {
          if ip_scopes = configuration[:IpScopes]
            IpScopes {
              if ip_scope = ip_scopes[:IpScope]
                IpScope {
                  IsInherited  ip_scope[:IsInherited] if ip_scope.key?(:IsInherited)
                  Gateway      ip_scope[:Gateway]     if ip_scope.key?(:Gateway)
                  Netmask      ip_scope[:Netmask]     if ip_scope.key?(:Netmask)
                  Dns1         ip_scope[:Dns1]        if ip_scope.key?(:Dns1)
                  Dns2         ip_scope[:Dns2]        if ip_scope.key?(:Dns2)
                  DnsSuffix    ip_scope[:DnsSuffix]   if ip_scope.key?(:DnsSuffix)
                  IsEnabled    ip_scope[:IsEnabled]   if ip_scope.key?(:IsEnabled)
                  if ip_ranges = ip_scope[:IpRanges]
                    IpRanges {
                      ip_ranges.each do |h|
                        if h.key?(:IpRange)
                          IpRange {
                            StartAddress h[:IpRange][:StartAddress]
                            EndAddress   h[:IpRange][:EndAddress]
                          }
                        end
                      end
                    }
                  end
                }
              end
            }
          end
          FenceMode    configuration[:FenceMode]
          if router_info = configuration[:RouterInfo]
            RouterInfoType {
              ExternalIp router_info[:ExternalIp]
            }
          end
        }
      end # Configuration

      if edgegw = options[:EdgeGateway] and configuration[:FenceMode] != 'isolated'
        EdgeGateway(edgegw)
      elsif options[:Configuration] && options[:Configuration][:FenceMode] == 'isolated'
        # isolated networks can specify ServiceConfig
        if sc = options[:ServiceConfig]
          ServiceConfig {
            if dhcp = sc[:GatewayDhcpService]
              IsEnabled dhcp[:IsEnabled] if dhcp[:IsEnabled]
              if pool = dhcp[:Pool]
                IsEnabled        pool[:IsEnabled]
                DefaultLeaseTime pool[:DefaultLeaseTime]
                MaxLeaseTime     pool[:MaxLeaseTime]
                LowIpAddress     pool[:LowIpAddress]
                HighIpAddress    pool[:HighIpAddress]
              end
            end
          }
        end
      end

      IsShared       options[:IsShared] if options.key?(:IsShared)

    }
  end.to_xml
end