58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
|
# File 'lib/chef/knife/cosmic_server_list.rb', line 58
def run
validate_base_options
columns = [
'Name :name',
'Public IP :ipaddress',
'Service :serviceofferingname',
'Template :templatename',
'State :state',
'Instance :instancename',
'Hypervisor :hostname'
]
params = { 'command' => "listVirtualMachines" }
params['filter'] = locate_config_value(:filter) if locate_config_value(:filter)
params['listall'] = locate_config_value(:listall) if locate_config_value(:listall)
params['keyword'] = locate_config_value(:keyword) if locate_config_value(:keyword)
params['name'] = locate_config_value(:name) if locate_config_value(:name)
params['expunge'] = locate_config_value(:expunge) if locate_config_value(:expunge)
params['expunge'] = false if params['expunge'].nil?
rules = connection.list_port_forwarding_rules(nil, true)
public_list = connection.list_public_ip_addresses(true)
result = connection.list_object(params, "virtualmachine")
result.each do |n|
public_ip = connection.get_server_public_ip(n, rules, public_list) if locate_config_value(:public_ip)
private_ip = (n['nic'].select { |k| k['isdefault'] }).first
public_ip ? n['ipaddress'] = public_ip : n['ipaddress'] = private_ip['ipaddress'] || "N/A"
end
list_object(columns, result)
if locate_config_value(:action)
result.each do |r|
hostname = r['name']
case locate_config_value(:action).downcase
when "start" then
show_object_details(r, connection, rules)
result = confirm_action("Do you really want to start this server ")
if result then
print "#{ui.color("Waiting for startup", :magenta)}"
connection.start_server(hostname)
puts "\n"
ui.msg("Started server #{hostname}")
end
when "stop" then
show_object_details(r, connection, rules)
result = confirm_action("Do you really want to stop this server ")
if result then
print "#{ui.color("Waiting for shutdown", :magenta)}"
connection.stop_server(hostname)
puts "\n"
ui.msg("Shutdown server #{hostname}")
end
when "destroy" then
show_object_details(r, connection, rules)
result = confirm_action("Do you really want to destroy this server ")
if result then
print "#{ui.color("Waiting for demolition", :magenta)}"
connection.delete_server(hostname, params['expunge'])
puts "\n"
ui.msg("Destroyed server #{hostname}")
end
end
end
end
end
|