Method: KnifeCloudstack::CsServerCreate#find_or_create_public_ip

Defined in:
lib/chef/knife/cs_server_create.rb

#find_or_create_public_ip(server, connection) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/chef/knife/cs_server_create.rb', line 251

def find_or_create_public_ip(server, connection)
  nic = connection.get_server_default_nic(server) || {}
  puts "#{ui.color("Not allocating public IP for server", :red)}" unless config[:public_ip]

  if (config[:public_ip] == false) || (nic['type'] != 'Virtual') then
    nic['ipaddress']
  else
    # create ip address, ssh forwarding rule and optional forwarding rules
    ip_address = connection.associate_ip_address(server['zoneid'])
    ssh_rule = connection.create_port_forwarding_rule(ip_address['id'], "22", "TCP", "22", server['id'])
    create_port_forwarding_rules(ip_address['id'], server['id'], connection)
    ssh_rule['ipaddress']
  end
end