/
openstack_floating_ip_allocate.rb
38 lines (32 loc) · 1.42 KB
/
openstack_floating_ip_allocate.rb
1
2
3
4
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
35
36
37
38
# Author:: Vasundhara Jagdale (<vasundhara.jagdale@clogeny.com>)
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
require 'chef/knife/openstack_helpers'
require 'chef/knife/cloud/openstack_service_options'
class Chef
class Knife
class Cloud
class OpenstackFloatingIpAllocate < Command
include OpenstackHelpers
include OpenstackServiceOptions
banner 'knife openstack floating_ip allocate (options)'
option :pool,
:short => '-p POOL',
:long => '--pool POOL',
:description => 'Floating IP pool to allocate from.',
:proc => Proc.new { |key| Chef::Config[:knife][:pool] = key }
def execute_command
@resource = @service.allocate_address(locate_config_value(:pool))
end
def after_exec_command
@columns_with_info = [{ label: 'ID', value: @resource['floating_ip']['id'].to_s },
{ label: 'Instance ID', value: @resource['floating_ip']['instance_id'].to_s },
{ label: 'Floating IP', value: @resource['floating_ip']['ip'].to_s },
{ label: 'Fixed IP', value: @resource['floating_ip']['fixed_ip'].to_s },
{ label: 'Pool', value: @resource['floating_ip']['pool'].to_s }
]
@service.server_summary(nil, @columns_with_info)
end
end
end
end
end