From 641ef18a501fb96e7ed6321ec61aba70a3dec994 Mon Sep 17 00:00:00 2001 From: Vasu1105 Date: Tue, 8 Sep 2015 19:52:09 +0530 Subject: [PATCH] Fixed ip addresses not visible issue --- lib/chef/knife/openstack_helpers.rb | 15 ++++++++++++++- lib/chef/knife/openstack_server_list.rb | 16 +++++----------- lib/chef/knife/openstack_server_show.rb | 3 +-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/chef/knife/openstack_helpers.rb b/lib/chef/knife/openstack_helpers.rb index 5f3f9ffa..0b91ebe8 100644 --- a/lib/chef/knife/openstack_helpers.rb +++ b/lib/chef/knife/openstack_helpers.rb @@ -14,7 +14,7 @@ def primary_public_ip_address(addresses) end def primary_network_ip_address(addresses, network_name) - return addresses[network_name].last['addr'] if addresses[network_name] && !addresses[network_name].empty? + addresses[network_name].last['addr'] if addresses[network_name] && !addresses[network_name].empty? end def create_service_instance @@ -24,6 +24,19 @@ def create_service_instance def validate! super(:openstack_username, :openstack_password, :openstack_auth_url) end + + def instance_addresses(addresses) + info = [] + if addresses[addresses.keys[0]] && addresses[addresses.keys[0]].size > 0 + ips = addresses[addresses.keys[0]] + ips.each do |ip| + version = 'IPv6' if ip['version'] == 6 + version = 'IPv4' if ip['version'] == 4 + info << "#{addresses.keys[0]}:#{version}: #{ip['addr']}" + end + end + info.join(' ') + end end end end diff --git a/lib/chef/knife/openstack_server_list.rb b/lib/chef/knife/openstack_server_list.rb index b68866f1..d7ae2100 100644 --- a/lib/chef/knife/openstack_server_list.rb +++ b/lib/chef/knife/openstack_server_list.rb @@ -35,34 +35,28 @@ class OpenstackServerList < ServerListCommand banner "knife openstack server list (options)" def before_exec_command - #set columns_with_info map + # set columns_with_info map @columns_with_info = [ {:label => 'Name', :key => 'name'}, {:label => 'Instance ID', :key => 'id'}, - {:label => 'Public IP', :key => 'addresses', :value_callback => method(:get_public_ip_address)}, - {:label => 'Private IP', :key => 'addresses', :value_callback => method(:get_private_ip_address)}, + {:label => 'Addresses', :key => 'addresses', :value_callback => method(:addresses)}, {:label => 'Flavor', :key => 'flavor', :value_callback => method(:get_id)}, {:label => 'Image', :key => 'image', :value_callback => method(:get_id)}, {:label => 'Keypair', :key => 'key_name'}, {:label => 'State', :key => 'state'}, {:label => 'Availability Zone', :key => 'availability_zone'} ] - @sort_by_field = "name" + @sort_by_field = 'name' super end - def get_public_ip_address (addresses) - primary_public_ip_address(addresses) - end - - def get_private_ip_address (addresses) - primary_private_ip_address(addresses) + def addresses(addresses) + instance_addresses(addresses) end def get_id(value) value['id'] end - end end end diff --git a/lib/chef/knife/openstack_server_show.rb b/lib/chef/knife/openstack_server_show.rb index 5f9d0cd0..24f11ef2 100644 --- a/lib/chef/knife/openstack_server_show.rb +++ b/lib/chef/knife/openstack_server_show.rb @@ -37,8 +37,7 @@ def before_exec_command @columns_with_info = [ {:label => 'Instance ID', :key => 'id'}, {:label => 'Name', :key => 'name'}, - {:label => 'Public IP', :key => 'addresses', :value_callback => method(:primary_public_ip_address)}, - {:label => 'Private IP', :key => 'addresses', :value_callback => method(:primary_private_ip_address)}, + {:label => 'Addresses', :key => 'addresses', :value_callback => method(:instance_addresses)}, {:label => 'Flavor', :key => 'flavor', :value_callback => method(:get_id)}, {:label => 'Image', :key => 'image', :value_callback => method(:get_id)}, {:label => 'Keypair', :key => 'key_name'},