Module: Backends::Opennebula::Helpers::NetworkParseHelper

Included in:
Network
Defined in:
lib/backends/opennebula/helpers/network_parse_helper.rb

Instance Method Summary collapse

Instance Method Details

#parse_backend_obj(backend_network) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/backends/opennebula/helpers/network_parse_helper.rb', line 5

def parse_backend_obj(backend_network)
  network = ::Occi::Infrastructure::Network.new

  # include some basic mixins
  network.mixins << 'http://schemas.ogf.org/occi/infrastructure/network#ipnetwork'
  network.mixins << 'http://schemas.opennebula.org/occi/infrastructure#network'

  # include mixins stored in ON's VN template
  unless backend_network['TEMPLATE/OCCI_NETWORK_MIXINS'].blank?
    backend_network_mixins = backend_network['TEMPLATE/OCCI_NETWORK_MIXINS'].split(' ')
    backend_network_mixins.each do |mixin|
      network.mixins << mixin unless mixin.blank?
    end
  end

  # include basic OCCI attributes
  basic_attrs = parse_basic_attrs(backend_network)
  network.attributes.merge! basic_attrs

  # include ONE-specific attributes
  one_attrs = parse_one_attrs(backend_network)
  network.attributes.merge! one_attrs

  # include state information and available actions
  result = parse_state(backend_network)
  network.state = result.state
  result.actions.each { |a| network.actions << a }

  network
end

#parse_basic_attrs(backend_network) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/backends/opennebula/helpers/network_parse_helper.rb', line 36

def parse_basic_attrs(backend_network)
  basic_attrs = ::Occi::Core::Attributes.new

  basic_attrs['occi.core.id']    = backend_network['ID']
  basic_attrs['occi.core.title'] = backend_network['NAME'] if backend_network['NAME']
  basic_attrs['occi.core.summary'] = backend_network['TEMPLATE/DESCRIPTION'] unless backend_network['TEMPLATE/DESCRIPTION'].blank?

  basic_attrs['occi.network.gateway'] = backend_network['TEMPLATE/GATEWAY'] if backend_network['TEMPLATE/GATEWAY']
  basic_attrs['occi.network.vlan'] = backend_network['VLAN_ID'].to_i unless backend_network['VLAN_ID'].blank?

  if backend_network.type_str == 'RANGED'
    basic_attrs['occi.network.allocation'] = 'dynamic'
    basic_attrs['occi.network.address'] = calculate_cidr(backend_network)
  else
    basic_attrs['occi.network.allocation'] = 'static'
  end

  basic_attrs
end

#parse_one_attrs(backend_network) ⇒ Object


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/backends/opennebula/helpers/network_parse_helper.rb', line 56

def parse_one_attrs(backend_network)
  one_attrs = ::Occi::Core::Attributes.new

  one_attrs['org.opennebula.network.id'] = backend_network['ID']

  if backend_network['VLAN'].blank? || backend_network['VLAN'].to_i == 0
    one_attrs['org.opennebula.network.vlan'] = 'NO'
  else
    one_attrs['org.opennebula.network.vlan'] = 'YES'
  end

  one_attrs['org.opennebula.network.phydev'] = backend_network['PHYDEV'] unless backend_network['PHYDEV'].blank?
  one_attrs['org.opennebula.network.bridge'] = backend_network['BRIDGE'] unless backend_network['BRIDGE'].blank?

  unless backend_network['RANGE'].blank?
    one_attrs['org.opennebula.network.ip_start'] = backend_network['RANGE/IP_START'] if backend_network['RANGE/IP_START']
    one_attrs['org.opennebula.network.ip_end'] = backend_network['RANGE/IP_END'] if backend_network['RANGE/IP_END']
  end

  one_attrs
end

#parse_state(backend_network) ⇒ Object


78
79
80
81
82
83
84
85
86
# File 'lib/backends/opennebula/helpers/network_parse_helper.rb', line 78

def parse_state(backend_network)
  result = Hashie::Mash.new

  # ON doesn't implement actions on networks
  result.actions = []
  result.state = 'active'

  result
end