cloudstack-cli 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -5
- data/README.md +6 -6
- data/cloudstack-cli.gemspec +0 -1
- data/lib/cloudstack-cli/base.rb +36 -0
- data/lib/cloudstack-cli/cli.rb +20 -19
- data/lib/cloudstack-cli/commands/account.rb +12 -5
- data/lib/cloudstack-cli/commands/capacity.rb +34 -0
- data/lib/cloudstack-cli/commands/domain.rb +6 -5
- data/lib/cloudstack-cli/commands/load_balancer.rb +24 -30
- data/lib/cloudstack-cli/commands/network.rb +28 -49
- data/lib/cloudstack-cli/commands/offering.rb +18 -29
- data/lib/cloudstack-cli/commands/project.rb +7 -5
- data/lib/cloudstack-cli/commands/publicip.rb +3 -4
- data/lib/cloudstack-cli/commands/router.rb +44 -62
- data/lib/cloudstack-cli/commands/server.rb +39 -32
- data/lib/cloudstack-cli/commands/stack.rb +3 -11
- data/lib/cloudstack-cli/commands/template.rb +10 -12
- data/lib/cloudstack-cli/commands/volume.rb +9 -10
- data/lib/cloudstack-cli/commands/zone.rb +6 -5
- data/lib/cloudstack-cli/helper.rb +8 -86
- data/lib/cloudstack-cli/version.rb +1 -1
- data/lib/cloudstack-client/client.rb +18 -11
- data/lib/cloudstack_cli.rb +2 -3
- metadata +23 -23
- checksums.yaml +0 -7
@@ -1,11 +1,9 @@
|
|
1
|
-
class Offering <
|
2
|
-
include CommandLineReporter
|
1
|
+
class Offering < CloudstackCli::Base
|
3
2
|
|
4
|
-
desc '
|
3
|
+
desc 'list', 'list offerings by type [compute|network|storage]'
|
5
4
|
option :domain
|
6
5
|
def list(type='compute')
|
7
|
-
|
8
|
-
offerings = cs_cli.server_offerings(options[:domain])
|
6
|
+
offerings = client.list_service_offerings(options[:domain])
|
9
7
|
|
10
8
|
offerings.group_by{|o| o["domain"]}.each_value do |offers|
|
11
9
|
offers.sort {
|
@@ -18,26 +16,20 @@ class Offering < Thor
|
|
18
16
|
if offerings.size < 1
|
19
17
|
puts "No offerings found"
|
20
18
|
else
|
21
|
-
table
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
row do
|
30
|
-
column offering["name"]
|
31
|
-
column offering["id"]
|
32
|
-
column offering["displaytext"]
|
33
|
-
column offering["domain"]
|
34
|
-
end
|
35
|
-
end
|
19
|
+
table = [["Name", "Displaytext", "Domain", "ID"]]
|
20
|
+
offerings.each do |offering|
|
21
|
+
table << [
|
22
|
+
offering["name"],
|
23
|
+
offering["displaytext"],
|
24
|
+
offering["domain"],
|
25
|
+
offering["id"]
|
26
|
+
]
|
36
27
|
end
|
28
|
+
print_table table
|
37
29
|
end
|
38
30
|
end
|
39
31
|
|
40
|
-
desc '
|
32
|
+
desc 'create NAME', 'create offering'
|
41
33
|
option :cpunumber, required: true
|
42
34
|
option :cpuspeed, required: true
|
43
35
|
option :displaytext, required: true
|
@@ -47,28 +39,25 @@ class Offering < Thor
|
|
47
39
|
option :tags
|
48
40
|
def create(name)
|
49
41
|
options[:name] = name
|
50
|
-
|
51
|
-
puts "OK" if cs_cli.create_offering(options)
|
42
|
+
puts "OK" if client.create_offering(options)
|
52
43
|
end
|
53
44
|
|
54
45
|
desc 'delete ID', 'delete offering'
|
55
46
|
def delete(id)
|
56
|
-
|
57
|
-
puts "OK" if cs_cli.delete_offering(id)
|
47
|
+
puts "OK" if client.delete_offering(id)
|
58
48
|
end
|
59
49
|
|
60
50
|
|
61
|
-
desc '
|
51
|
+
desc 'sort', 'sort by cpu and memory grouped by domain'
|
62
52
|
def sort
|
63
|
-
|
64
|
-
offerings = cs_cli.server_offerings(options[:domain])
|
53
|
+
offerings = client.list_service_offerings(options[:domain])
|
65
54
|
sortkey = -1
|
66
55
|
offerings.group_by{|o| o["domain"]}.each_value do |offers|
|
67
56
|
offers.sort {
|
68
57
|
|oa, ob| [oa["cpunumber"], oa["memory"]] <=> [ob["cpunumber"], ob["memory"]]
|
69
58
|
}.each do |offer|
|
70
59
|
puts "#{sortkey.abs} #{offer['domain']} - #{offer["displaytext"]}"
|
71
|
-
|
60
|
+
client.update_offering({
|
72
61
|
"id" => offer['id'],
|
73
62
|
'sortkey' => sortkey
|
74
63
|
})
|
@@ -1,15 +1,17 @@
|
|
1
|
-
class Project <
|
1
|
+
class Project < CloudstackCli::Base
|
2
2
|
|
3
|
-
desc "
|
3
|
+
desc "list", "list projects"
|
4
4
|
def list
|
5
|
-
|
6
|
-
projects = cs_cli.projects
|
5
|
+
projects = client.list_projects
|
7
6
|
if projects.size < 1
|
8
7
|
puts "No projects found"
|
9
8
|
else
|
9
|
+
table = [["Name", "Displaytext", "Domain"]]
|
10
10
|
projects.each do |project|
|
11
|
-
|
11
|
+
table << [project['name'], project['displaytext'], project['domain']]
|
12
12
|
end
|
13
|
+
print_table(table)
|
13
14
|
end
|
14
15
|
end
|
16
|
+
|
15
17
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
class Publicip <
|
1
|
+
class Publicip < CloudstackCli::Base
|
2
2
|
|
3
|
-
desc "
|
3
|
+
desc "remove ID", "remove public IP address"
|
4
4
|
def remove(id)
|
5
|
-
|
6
|
-
puts "OK" if cs_cli.remove_publicip(id)
|
5
|
+
puts "OK" if client.disassociate_ip_address(id)
|
7
6
|
end
|
8
7
|
|
9
8
|
end
|
@@ -1,83 +1,68 @@
|
|
1
|
-
class Router <
|
2
|
-
include Thor::Actions
|
3
|
-
include CommandLineReporter
|
1
|
+
class Router < CloudstackCli::Base
|
4
2
|
|
5
|
-
desc "
|
3
|
+
desc "list", "list virtual routers"
|
6
4
|
option :project
|
7
5
|
option :account
|
8
6
|
option :zone
|
9
7
|
option :status, desc: "Running or Stopped"
|
10
|
-
option :redundant_state, desc: "
|
8
|
+
option :redundant_state, desc: "master, backup, failed or unknown"
|
11
9
|
option :listall, type: :boolean
|
12
|
-
option :
|
10
|
+
option :showid, type: :boolean
|
13
11
|
option :command, desc: "command to execute for each router: START or STOP"
|
14
12
|
option :reverse, type: :boolean, default: false, desc: "reverse listing of routers"
|
15
13
|
def list
|
16
|
-
|
17
|
-
|
18
|
-
project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first
|
19
|
-
unless project
|
20
|
-
say "Error: Project '#{options[:project]}' not found", :red
|
21
|
-
exit 1
|
22
|
-
end
|
23
|
-
projectid = project['id']
|
24
|
-
end
|
25
|
-
|
26
|
-
routers = cs_cli.list_routers(
|
14
|
+
projectid = find_project['id'] if options[:project]
|
15
|
+
routers = client.list_routers(
|
27
16
|
{
|
28
17
|
account: options[:account],
|
29
18
|
projectid: projectid,
|
30
19
|
status: options[:status],
|
31
20
|
zone: options[:zone]
|
32
|
-
}
|
33
|
-
options[:redundant_state]
|
21
|
+
}
|
34
22
|
)
|
35
23
|
|
36
|
-
|
37
24
|
if options[:listall]
|
38
|
-
projects =
|
25
|
+
projects = client.list_projects
|
39
26
|
projects.each do |project|
|
40
|
-
routers = routers +
|
27
|
+
routers = routers + client.list_routers(
|
41
28
|
{
|
42
29
|
account: options[:account],
|
43
30
|
projectid: project['id'],
|
44
31
|
status: options[:status],
|
45
32
|
zone: options[:zone]
|
46
|
-
}
|
47
|
-
options[:redundant_state]
|
33
|
+
}
|
48
34
|
)
|
49
35
|
end
|
50
36
|
end
|
51
37
|
|
38
|
+
if options[:redundant_state]
|
39
|
+
routers = filter_by(routers, 'redundantstate', options[:redundant_state].downcase)
|
40
|
+
end
|
41
|
+
|
52
42
|
routers.reverse! if options[:reverse]
|
53
|
-
if
|
54
|
-
|
43
|
+
if routers.size < 1
|
44
|
+
say "No routers found."
|
55
45
|
else
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
column router["linklocalip"]
|
77
|
-
column router["state"]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
46
|
+
table = [[
|
47
|
+
'Name', 'Zone', 'Account', 'Project', 'Redundant-State', 'Linklocal IP', 'Status', 'ID'
|
48
|
+
]]
|
49
|
+
table[0].delete('ID') unless options[:showid]
|
50
|
+
routers.each do |router|
|
51
|
+
table << [
|
52
|
+
router["name"],
|
53
|
+
router["zonename"],
|
54
|
+
router["account"],
|
55
|
+
router["project"],
|
56
|
+
router["redundantstate"],
|
57
|
+
router["linklocalip"],
|
58
|
+
router["state"],
|
59
|
+
router["id"]
|
60
|
+
]
|
61
|
+
table[-1].delete_at(-1) unless table[0].index "ID"
|
62
|
+
end
|
63
|
+
print_table table
|
64
|
+
puts
|
65
|
+
say "Number of routers: #{routers.size}"
|
81
66
|
end
|
82
67
|
|
83
68
|
if options[:command]
|
@@ -86,14 +71,14 @@ class Router < Thor
|
|
86
71
|
exit unless yes?("Start the routers above? [y/N]:", :magenta)
|
87
72
|
routers.each do |router|
|
88
73
|
say "Start router #{router['name']}... "
|
89
|
-
say "job started ", :green if job =
|
74
|
+
say "job started ", :green if job = client.start_router(router['id'])
|
90
75
|
say "(jobid: #{job['jobid']})"
|
91
76
|
end
|
92
77
|
when "stop"
|
93
78
|
exit unless yes?("Stop the routers above? [y/N]:", :magenta)
|
94
79
|
routers.each do |router|
|
95
80
|
say "Stop router #{router['name']}... "
|
96
|
-
say "job started ", :green if job =
|
81
|
+
say "job started ", :green if job = client.stop_router(router['id'])
|
97
82
|
say "(jobid: #{job['jobid']})"
|
98
83
|
end
|
99
84
|
else
|
@@ -103,25 +88,22 @@ class Router < Thor
|
|
103
88
|
end
|
104
89
|
end
|
105
90
|
|
106
|
-
desc "
|
91
|
+
desc "stop ID", "stop virtual router"
|
107
92
|
def stop(id)
|
108
93
|
exit unless yes?("Stop the router with ID #{id}?", :magenta)
|
109
|
-
|
110
|
-
cs_cli.stop_router id
|
94
|
+
client.stop_router id
|
111
95
|
end
|
112
96
|
|
113
|
-
desc "
|
97
|
+
desc "start ID", "start virtual router"
|
114
98
|
def start(id)
|
115
99
|
exit unless yes?("Start the router with ID #{id}?", :magenta)
|
116
|
-
|
117
|
-
cs_cli.start_router id
|
100
|
+
client.start_router id
|
118
101
|
end
|
119
102
|
|
120
|
-
desc "
|
103
|
+
desc "destroy ID", "destroy virtual router"
|
121
104
|
def destroy(id)
|
122
105
|
exit unless yes?("Destroy the router with ID #{id}?", :magenta)
|
123
|
-
|
124
|
-
say "OK", :green if cs_cli.destroy_router(id)
|
106
|
+
say "OK", :green if client.destroy_router(id)
|
125
107
|
end
|
126
108
|
|
127
109
|
end
|
@@ -1,33 +1,37 @@
|
|
1
|
-
class Server <
|
1
|
+
class Server < CloudstackCli::Base
|
2
2
|
|
3
|
-
desc "
|
4
|
-
option :listall, :type => :boolean
|
5
|
-
option :text, :type => :boolean
|
3
|
+
desc "list", "list servers"
|
6
4
|
option :project
|
7
5
|
option :account
|
8
6
|
def list
|
9
|
-
cs_cli = CloudstackCli::Helper.new(options[:config])
|
10
7
|
if options[:project]
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
if options[:project].downcase == "all"
|
9
|
+
options[:project_id] = -1
|
10
|
+
else
|
11
|
+
project = find_project
|
12
|
+
options[:project_id] = project['id']
|
13
|
+
end
|
15
14
|
end
|
16
|
-
servers =
|
15
|
+
servers = client.list_servers(options)
|
17
16
|
if servers.size < 1
|
18
17
|
puts "No servers found"
|
19
18
|
else
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
table = [["Name", "State", "Offering", "Zone", options[:project] ? "Project" : "Account", "IP's"]]
|
20
|
+
servers.each do |server|
|
21
|
+
table << [
|
22
|
+
server['name'],
|
23
|
+
server['state'],
|
24
|
+
server['serviceofferingname'],
|
25
|
+
server['zonename'],
|
26
|
+
options[:project] ? server['project'] : server['account'],
|
27
|
+
server['nic'].map { |nic| nic['ipaddress']}.join(' ')
|
28
|
+
]
|
26
29
|
end
|
30
|
+
print_table table
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
|
-
desc "
|
34
|
+
desc "create NAME", "create a server"
|
31
35
|
option :zone, :required => true
|
32
36
|
option :template, :required => true
|
33
37
|
option :offering, :required => true
|
@@ -37,34 +41,37 @@ class Server < Thor
|
|
37
41
|
option :interactive, :type => :boolean
|
38
42
|
def create(name)
|
39
43
|
CloudstackCli::Helper.new(options[:config]).bootstrap_server(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
name,
|
45
|
+
options[:zone],
|
46
|
+
options[:template],
|
47
|
+
options[:offering],
|
48
|
+
options[:networks],
|
49
|
+
options[:port_forwarding],
|
50
|
+
options[:project]
|
51
|
+
)
|
48
52
|
end
|
49
53
|
|
50
|
-
desc "
|
54
|
+
desc "bootstrap", "interactive creation of a server with network access"
|
51
55
|
def bootstrap
|
52
56
|
CloudstackCli::Helper.new(options[:config]).bootstrap_server_interactive()
|
53
57
|
end
|
54
58
|
|
55
|
-
desc "
|
59
|
+
desc "stop NAME", "stop a server"
|
56
60
|
def stop(name)
|
57
|
-
|
61
|
+
client.stop_server(name)
|
62
|
+
puts
|
58
63
|
end
|
59
64
|
|
60
|
-
desc "
|
65
|
+
desc "start NAME", "start a server"
|
61
66
|
def start(name)
|
62
|
-
|
67
|
+
client.start_server(name)
|
68
|
+
puts
|
63
69
|
end
|
64
70
|
|
65
|
-
desc "
|
71
|
+
desc "reboot NAME", "reboot a server"
|
66
72
|
def restart(name)
|
67
|
-
|
73
|
+
client.reboot_server(name)
|
74
|
+
puts
|
68
75
|
end
|
69
76
|
|
70
77
|
end
|
@@ -1,16 +1,8 @@
|
|
1
|
-
class Stack <
|
1
|
+
class Stack < CloudstackCli::Base
|
2
2
|
|
3
|
-
desc "
|
3
|
+
desc "create STACKFILE", "create a stack of servers"
|
4
4
|
def create(stackfile)
|
5
|
-
|
6
|
-
name,
|
7
|
-
options[:zone],
|
8
|
-
options[:template],
|
9
|
-
options[:offering],
|
10
|
-
options[:networks],
|
11
|
-
options[:port_forwarding],
|
12
|
-
options[:project]
|
13
|
-
)
|
5
|
+
# TODO
|
14
6
|
end
|
15
7
|
|
16
8
|
end
|
@@ -1,24 +1,22 @@
|
|
1
|
-
class Template <
|
1
|
+
class Template < CloudstackCli::Base
|
2
2
|
|
3
|
-
desc '
|
3
|
+
desc 'list', 'list templates by type [featured|self|self-executable|executable|community]'
|
4
4
|
option :project
|
5
5
|
def list(type='featured')
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
exit_now! "Project '#{options[:project]}' not found" unless project
|
6
|
+
project = find_project if options[:project]
|
7
|
+
unless %w(featured self self-executable executable community).include? type
|
8
|
+
say "unsupported template type '#{type}'", :red
|
9
|
+
exit 1
|
11
10
|
end
|
12
|
-
|
13
|
-
exit_now! "unsupported template type '#{type}'" unless
|
14
|
-
%w(featured self self-executable executable community).include? type
|
15
|
-
templates = cs_cli.templates(type, project ? project['id'] : nil)
|
11
|
+
templates = client.list_templates(type, project ? project['id'] : nil)
|
16
12
|
if templates.size < 1
|
17
13
|
puts "No templates found"
|
18
14
|
else
|
15
|
+
table = [["Name", "Zone"]]
|
19
16
|
templates.each do |template|
|
20
|
-
|
17
|
+
table << [template['name'], template['zonename']]
|
21
18
|
end
|
19
|
+
print_table(table)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|