Skip to content

Commit

Permalink
Merge pull request #178 from chef/vj/issue_server_list_ip_address
Browse files Browse the repository at this point in the history
Fixed ip addresses not visible issue
  • Loading branch information
JJ Asghar committed Sep 15, 2015
2 parents 01da556 + 641ef18 commit 7e946c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
15 changes: 14 additions & 1 deletion lib/chef/knife/openstack_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 5 additions & 11 deletions lib/chef/knife/openstack_server_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/chef/knife/openstack_server_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down

0 comments on commit 7e946c5

Please sign in to comment.