Module: Backends::Ec2::Helpers::NetworkParseHelper

Included in:
Network
Defined in:
lib/backends/ec2/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
# File 'lib/backends/ec2/helpers/network_parse_helper.rb', line 5

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

  network.mixins << 'http://schemas.ec2.aws.amazon.com/occi/infrastructure/network#aws_ec2_vpc'

  network.attributes['occi.core.id'] = backend_network[:vpc_id]
  network.attributes['occi.core.title'] = if backend_network[:tags].select { |tag| tag[:key] == 'Name' }.any?
    backend_network[:tags].select { |tag| tag[:key] == 'Name' }.first[:value]
  else
    "rOCCI-server VPC #{backend_network[:cidr_block]}"
  end
  network.address = backend_network[:cidr_block] unless backend_network[:cidr_block].blank?
  network.attributes['occi.network.label'] = "AWS VPC #{backend_network[:vpc_id]}"

  network.attributes['com.amazon.aws.ec2.instance_tenancy'] = backend_network[:instance_tenancy] if backend_network[:instance_tenancy]
  network.attributes['com.amazon.aws.ec2.state'] = backend_network[:state] if backend_network[:state]
  network.attributes['com.amazon.aws.ec2.is_default'] = backend_network[:is_default] unless backend_network[:is_default].nil?

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

  network
end