Class: Pec::Director::Helper

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

Class Method Summary collapse

Class Method Details

.get_nics(ports) ⇒ Object



25
26
27
# File 'lib/pec/director/helper.rb', line 25

def get_nics(ports)
  { 'nics' =>  ports.map { |port| { port_id: port.id } }}
end

.get_security_group_id(security_groups) ⇒ Object



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

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



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

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
22
23
# File 'lib/pec/director/helper.rb', line 6

def ports_assign(host)
  host.networks.map do |ether|
    begin
      ip = IP.new(ether.ip_address)
    rescue ArgumentError => e
      raise(Pec::Errors::Port, "ip:#{ether.ip_address} #{e}")
    end

    port_subnet = Pec::Network::Subnet.fetch(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
end