Class: Chef::Knife::CsServerList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::CsServerList
- Includes:
- CsBase
- Defined in:
- lib/chef/knife/cs_server_list.rb
Instance Method Summary collapse
- #azcolor(az) ⇒ Object
- #fcolor(flavor) ⇒ Object
- #groups_with_ids(groups) ⇒ Object
- #private_ip_address(server) ⇒ Object
- #run ⇒ Object
- #vpc_with_name(vpc_id) ⇒ Object
Methods included from CsBase
#connection, included, #is_image_windows?, #locate_config_value, #msg_pair, #validate!
Methods inherited from Chef::Knife
Instance Method Details
#azcolor(az) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chef/knife/cs_server_list.rb', line 56 def azcolor(az) case az when /a$/ color = :blue when /b$/ color = :green when /c$/ color = :red when /d$/ color = :magenta else color = :cyan end end |
#fcolor(flavor) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chef/knife/cs_server_list.rb', line 41 def fcolor(flavor) case flavor when /.*micro.*/i fcolor = :blue when /.*small.*/i fcolor = :magenta when /.*medium.*/i fcolor = :cyan when /.*large.*/i fcolor = :green when /.*xlarge.*/i fcolor = :red end end |
#groups_with_ids(groups) ⇒ Object
71 72 73 74 75 |
# File 'lib/chef/knife/cs_server_list.rb', line 71 def groups_with_ids(groups) groups.map{|g| "#{g} (#{@group_id_hash[g]})" } end |
#private_ip_address(server) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/chef/knife/cs_server_list.rb', line 87 def private_ip_address(server) return nil if server.nics.empty? default_nic = server.nics.select {|n| n['isdefault'] == true }.first return nil if default_nic.nil? || default_nic.empty? default_nic['ipaddress'] end |
#run ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/chef/knife/cs_server_list.rb', line 95 def run $stdout.sync = true validate! server_list = [ if config[:id] ui.color('ID', :bold) else ui.color('Name', :bold) end, ui.color('Public IP', :bold), ui.color('Private IP', :bold), ui.color('Service', :bold), ui.color('Image', :bold), ui.color('Zone', :bold), ui.color('State', :bold) ].flatten.compact output_column_count = server_list.length connection.servers.all.each do |server| config[:id] ? server_list << server.id.to_s : server_list << server.name.to_s # Still need to fix the public IP's (need to call the API for all forwards and filter on ssh/winrm sessions or something) server_list << "pub_ip" # public_ip_address(server).to_s || "unknown" server_list << private_ip_address(server).to_s || "unknown" config[:id] ? server_list << server.flavor_id.to_s : server_list << server.flavor_name.to_s config[:id] ? server_list << server.image_id.to_s : server_list << server.image_name.to_s config[:id] ? server_list << server.zone_id.to_s : server_list << server.zone_name.to_s server_list << begin state = server.state.to_s.downcase case state when 'destroyed', 'expunging' ui.color(state, :purple) when 'shutting-down','terminated','stopping','stopped' ui.color(state, :red) when 'pending' ui.color(state, :yellow) else ui.color(state, :green) end end end puts ui.list(server_list, :uneven_columns_across, output_column_count) end |
#vpc_with_name(vpc_id) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/chef/knife/cs_server_list.rb', line 77 def vpc_with_name(vpc_id) this_vpc = @vpcs.select{|v| v.id == vpc_id }.first if this_vpc.["Name"] vpc_name = this_vpc.["Name"] "#{vpc_name} (#{vpc_id})" else vpc_id end end |