Class: Pec::Director::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/pec/director/helper.rb

Class Method Summary collapse

Class Method Details

.get_security_group_id(security_groups) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/pec/director/helper.rb', line 27

def get_security_group_id(security_groups)
  security_groups.map do |sg_name|
    sg = Pec::Compute::Security_Group.fetch(sg_name)
    raise(Pec::Errors::SecurityGroup, "security_group:#{sg_name} is not found!") unless sg
    sg["id"]
  end if security_groups
end

.parse_from_addresses(addresses) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/pec/director/helper.rb', line 35

def parse_from_addresses(addresses)
  addresses.map do |net, ethers|
    ethers.map do |ether|
      ether["addr"]
    end
  end.flatten
end

.ports_assign(host) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pec/director/helper.rb', line 6

def ports_assign(host)
  host.networks.map do |ether|
    ip = IP.new(ether.ip_address)

    port_subnet = Pec::Network::Subnet.fetch_by_cidr(ip.network.to_s)
    raise(Pec::Errors::Subnet, "subnet:#{ip.network.to_s} is not fond!") unless port_subnet

    port = Pec::Network::Port.assign(ether.name, ip, port_subnet, get_security_group_id(host.security_group))
    raise(Pec::Errors::Port, "ip addess:#{ip.to_addr} can't create port!") unless port

    puts "#{host.name}: assingn ip #{port.ip_address}".green
    port
  end if host.networks
  rescue ArgumentError => e
    raise(Pec::Errors::Port, "ip:#{ether.ip_address} #{e}")
end

.set_nics(options, ports) ⇒ Object



23
24
25
# File 'lib/pec/director/helper.rb', line 23

def set_nics(options, ports)
  ports ? options.merge({ 'nics' =>  ports.map { |port| { port_id: port.id } } }) : options
end