Revision e3b9eb63 src/cloud/occi/lib/VirtualNetworkOCCI.rb

View differences:

src/cloud/occi/lib/VirtualNetworkOCCI.rb
23 23
        <NETWORK href="<%= base_url %>/network/<%= self.id.to_s  %>">
24 24
            <ID><%= self.id.to_s %></ID>
25 25
            <NAME><%= self.name %></NAME>
26
            <ADDRESS><%= template['NETWORK_ADDRESS'] %></ADDRESS>
27
            <% if template['NETWORK_SIZE'] %>
28
            <SIZE><%= template['NETWORK_SIZE'] %></SIZE>
26
            <ADDRESS><%= self['TEMPLATE/NETWORK_ADDRESS'] %></ADDRESS>
27
            <% if self['TEMPLATE/NETWORK_SIZE'] %>
28
            <SIZE><%= self['TEMPLATE/NETWORK_SIZE'] %></SIZE>
29 29
            <% end %>
30 30
        </NETWORK>
31 31
    }
32 32

  
33 33
    ONE_NETWORK = %q{
34
        NAME            = <%= vnet_info['NAME'] %>
34
        NAME            = <%= @vnet_info.elements['NAME'].text %>
35 35
        TYPE            = RANGED
36
        BRIDGE          = <%= vnet_info['BRIDGE'] %>
37
        NETWORK_ADDRESS = <%= vnet_info['ADDRESS'] %>
38
        NETWORK_SIZE    = <%= vnet_info['SIZE'] %>
36
        BRIDGE          = <%= @vnet_info.elements['BRIDGE'].text %>
37
        NETWORK_ADDRESS = <%= @vnet_info.elements['ADDRESS'].text %>
38
        NETWORK_SIZE    = <%= @vnet_info.elements['SIZE'].text %>
39 39
    }.gsub(/^        /, '')
40 40

  
41 41
    # Class constructor
42
    def initialize(vnet_info, xml, client)
42
    def initialize(xml, client, xml_info=nil, bridge=nil)
43 43
        super(xml, client)
44 44

  
45
        @vnet_info = vnet_info
45
        if xml_info != nil and bridge != nil
46
            @vnet_info = REXML::Document.new(xml_info).root
47

  
48
            bridge_element = REXML::Element.new("BRIDGE")
49
            bridge_element.add_text(bridge)
50

  
51
            @vnet_info.add(bridge_element)
52
        else
53
            @vnet_info = nil
54
        end
46 55
    end
47
    
48
    # Creates the OCCI representation of a Virtual Network
49
    def to_occi(base_url)        
50
        vn_hash = self.to_hash
51
        return vn_hash, 500 if OpenNebula.is_error?(vn_hash)
52
        
53
        template = vn_hash['VNET']['TEMPLATE']
54 56

  
57
    # Creates the OCCI representation of a Virtual Network
58
    def to_occi(base_url)
55 59
        begin
56 60
            occi = ERB.new(OCCI_NETWORK)
57
            occi_text = occi.result(binding) 
61
            occi_text = occi.result(binding)
58 62
        rescue Exception => e
59 63
            error = OpenNebula::Error.new(e.message)
60 64
            return error
61
        end    
65
        end
62 66

  
63 67
        return occi_text.gsub(/\n\s*/,'')
64 68
    end
65
    
69

  
66 70
    def to_one_template()
67
        if @vnet_info['NETWORK']
68
            vnet_info = @vnet_info['NETWORK']
69
        else            
70
            error_msg = "Missing STORAGE section in the XML body"
71
        if @vnet_info.name != 'NETWORK'
72
            error_msg = "Missing NETWORK section in the XML body"
71 73
            error = OpenNebula::Error.new(error_msg)
72 74
            return error
73 75
        end
74
            
76

  
75 77
        one = ERB.new(ONE_NETWORK)
76 78
        return one.result(binding)
77 79
    end

Also available in: Unified diff