cloudstack-cli 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +40 -15
- data/bin/cs +2 -3
- data/cloudstack-cli.gemspec +3 -1
- data/lib/cloudstack-cli/cli.rb +14 -2
- data/lib/cloudstack-cli/commands/account.rb +1 -1
- data/lib/cloudstack-cli/commands/domain.rb +1 -1
- data/lib/cloudstack-cli/commands/load_balancer.rb +4 -3
- data/lib/cloudstack-cli/commands/network.rb +2 -3
- data/lib/cloudstack-cli/commands/offering.rb +3 -3
- data/lib/cloudstack-cli/commands/project.rb +1 -1
- data/lib/cloudstack-cli/commands/publicip.rb +1 -1
- data/lib/cloudstack-cli/commands/router.rb +16 -12
- data/lib/cloudstack-cli/commands/server.rb +14 -9
- data/lib/cloudstack-cli/commands/stack.rb +1 -1
- data/lib/cloudstack-cli/commands/template.rb +1 -1
- data/lib/cloudstack-cli/commands/volume.rb +1 -1
- data/lib/cloudstack-cli/commands/zone.rb +1 -1
- data/lib/cloudstack-cli/helper.rb +6 -6
- data/lib/cloudstack-cli/version.rb +1 -1
- data/lib/cloudstack-client/client.rb +6 -9
- data/lib/cloudstack_cli.rb +0 -2
- data/lib/cloudstack_client.rb +0 -2
- metadata +6 -4
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cloudstack-cli (0.0.
|
4
|
+
cloudstack-cli (0.0.3)
|
5
5
|
command_line_reporter (~> 3.2.1)
|
6
6
|
net-ssh (~> 2.6.7)
|
7
7
|
rainbow (~> 1.1.4)
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
command_line_reporter (3.2.1)
|
15
15
|
colored (>= 1.2)
|
16
16
|
json (1.8.0)
|
17
|
-
net-ssh (2.6.
|
17
|
+
net-ssh (2.6.8)
|
18
18
|
rainbow (1.1.4)
|
19
19
|
rake (10.0.4)
|
20
20
|
rdoc (4.0.1)
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2013
|
1
|
+
Copyright (c) 2013 Nik Wolfgramm
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
data/README.md
CHANGED
@@ -4,15 +4,7 @@ Cloudstack CLI gives command line access to the CloudStack API commands.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
gem "cloudstack-cli"
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
7
|
+
Install the cloudstack-cli gem:
|
16
8
|
|
17
9
|
$ gem install cloudstack-cli
|
18
10
|
|
@@ -32,17 +24,43 @@ Example content of the configuration file:
|
|
32
24
|
|
33
25
|
## Usage
|
34
26
|
|
35
|
-
See the help screen
|
27
|
+
See the help screen:
|
28
|
+
|
29
|
+
$ cs
|
30
|
+
|
31
|
+
### Example 1
|
32
|
+
|
33
|
+
Bootsrap a server:
|
34
|
+
|
35
|
+
$ cs server create server01 --zone ZUERICH_IX --port-forwarding 193.218.104.10:22 193.218.104.10:80 --template CentOS-6.4-x64-v1.4 --offering 1cpu_1gb --networks M_Demo
|
36
|
+
|
37
|
+
### Example 2
|
38
|
+
|
39
|
+
Run a custom API command:
|
36
40
|
|
37
|
-
|
41
|
+
cs command listAlerts type=8
|
38
42
|
|
39
|
-
Example
|
43
|
+
### Example 3
|
40
44
|
|
41
|
-
|
45
|
+
Sort all computing offerings by CPU and Memory grouped my Domain:
|
42
46
|
|
43
|
-
|
47
|
+
cs offering sort
|
44
48
|
|
45
|
-
|
49
|
+
### Example 4
|
50
|
+
|
51
|
+
Stop all virtual routers of project Demo (you could filter by Zone too):
|
52
|
+
(This command is helpful if you have to deploy new versions of Cloudstack when using redumdant routers)
|
53
|
+
|
54
|
+
cs router list --project Demo --status running --redundant-state BACKUP --command stop
|
55
|
+
|
56
|
+
Hint: You can watch the status of the command with watch.
|
57
|
+
|
58
|
+
watch -n cs router list --project Demo
|
59
|
+
|
60
|
+
|
61
|
+
## References
|
62
|
+
- [Cloudstack API documentation](http://cloudstack.apache.org/docs/api/apidocs-4.1/TOC_Root_Admin.html)
|
63
|
+
- This tool was inspired by the Knife extension for Cloudstack: [knife-cloudstack](https://github.com/CloudStack-extras/knife-cloudstack)
|
46
64
|
|
47
65
|
|
48
66
|
## Contributing
|
@@ -52,3 +70,10 @@ Example: Run a custom API command
|
|
52
70
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
71
|
4. Push to the branch (`git push origin my-new-feature`)
|
54
72
|
5. Create new Pull Request
|
73
|
+
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
Released under the MIT License. See the [LICENSE][] file for further details.
|
78
|
+
|
79
|
+
[license]: LICENSE.txt
|
data/bin/cs
CHANGED
data/cloudstack-cli.gemspec
CHANGED
@@ -12,10 +12,12 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{cloudstack-cli CloudStack API client}
|
13
13
|
gem.homepage = "https://bitbucket.org/swisstxt/cloudstack-cli"
|
14
14
|
|
15
|
+
gem.required_ruby_version = '1.9.3'
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = ['cs']
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
20
|
+
gem.rdoc_options = %w[--line-numbers --inline-source]
|
19
21
|
|
20
22
|
gem.add_development_dependency('rdoc')
|
21
23
|
gem.add_development_dependency('rake', '~> 10.0.4')
|
@@ -24,4 +26,4 @@ Gem::Specification.new do |gem|
|
|
24
26
|
gem.add_dependency('net-ssh', '~> 2.6.7')
|
25
27
|
gem.add_dependency('rainbow', '~> 1.1.4')
|
26
28
|
gem.add_dependency('command_line_reporter', '~> 3.2.1')
|
27
|
-
end
|
29
|
+
end
|
data/lib/cloudstack-cli/cli.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
module CloudstackCli
|
2
|
+
trap("TERM") { puts "SIGTERM received"; exit }
|
3
|
+
|
2
4
|
class Cli < Thor
|
3
5
|
include Thor::Actions
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
package_name "cloudstack-cli"
|
8
|
+
map %w(-v --version) => :version
|
9
|
+
|
10
|
+
class_option :config,
|
11
|
+
default: File.join(Dir.home, '.cloudstack-cli.yml'),
|
12
|
+
aliases: '-c',
|
13
|
+
desc: 'localition of your cloudstack-cli configuration file'
|
14
|
+
|
15
|
+
desc "version", "outputs the cloudstack-cli version"
|
16
|
+
def version
|
17
|
+
say "cloudstack-cli v#{CloudstackCli::VERSION}"
|
18
|
+
end
|
7
19
|
|
8
20
|
desc "setup", "initial setup of the Cloudstack connection"
|
9
21
|
option :url
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class Lb < Thor
|
2
|
-
|
2
|
+
|
3
|
+
desc "lb list", "list load balancer rules"
|
3
4
|
option :project
|
4
5
|
def list
|
5
6
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
@@ -18,7 +19,7 @@ class Lb < Thor
|
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
desc "create NAME", "create load balancer rule"
|
22
|
+
desc "lb create NAME", "create load balancer rule"
|
22
23
|
option :project
|
23
24
|
option :ip, :required => true
|
24
25
|
option :public_port, :required => true
|
@@ -40,7 +41,7 @@ class Lb < Thor
|
|
40
41
|
)
|
41
42
|
end
|
42
43
|
|
43
|
-
desc "add NAME", "assign servers to balancer rule"
|
44
|
+
desc "lb add NAME", "assign servers to balancer rule"
|
44
45
|
option :project
|
45
46
|
option :servers, required: true, type: :array, description: 'server names'
|
46
47
|
def add(name)
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class Network < Thor
|
2
2
|
include CommandLineReporter
|
3
3
|
|
4
|
-
desc "create NAME", "create network"
|
4
|
+
desc "network create NAME", "create network"
|
5
5
|
def create(name)
|
6
6
|
|
7
7
|
|
8
8
|
end
|
9
9
|
|
10
|
-
desc "list", "list networks"
|
10
|
+
desc "network list", "list networks"
|
11
11
|
option :project
|
12
12
|
option :physical, type: :boolean
|
13
13
|
def list
|
@@ -67,6 +67,5 @@ class Network < Thor
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
70
|
end
|
72
71
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Offering < Thor
|
2
2
|
include CommandLineReporter
|
3
3
|
|
4
|
-
desc 'list', 'list offerings by type [compute|network|storage]'
|
4
|
+
desc 'offering list', 'list offerings by type [compute|network|storage]'
|
5
5
|
option :domain
|
6
6
|
def list(type='compute')
|
7
7
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
@@ -37,7 +37,7 @@ class Offering < Thor
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
desc 'create NAME', 'create offering'
|
40
|
+
desc 'offering create NAME', 'create offering'
|
41
41
|
option :cpunumber, required: true
|
42
42
|
option :cpuspeed, required: true
|
43
43
|
option :displaytext, required: true
|
@@ -58,7 +58,7 @@ class Offering < Thor
|
|
58
58
|
end
|
59
59
|
|
60
60
|
|
61
|
-
desc 'sort', 'sort by cpu and memory grouped by domain'
|
61
|
+
desc 'offering sort', 'sort by cpu and memory grouped by domain'
|
62
62
|
def sort
|
63
63
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
64
64
|
offerings = cs_cli.server_offerings(options[:domain])
|
@@ -2,7 +2,7 @@ class Router < Thor
|
|
2
2
|
include Thor::Actions
|
3
3
|
include CommandLineReporter
|
4
4
|
|
5
|
-
desc "list", "list virtual routers"
|
5
|
+
desc "router list", "list virtual routers"
|
6
6
|
option :project
|
7
7
|
option :account
|
8
8
|
option :zone
|
@@ -16,7 +16,10 @@ class Router < Thor
|
|
16
16
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
17
17
|
if options[:project]
|
18
18
|
project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first
|
19
|
-
|
19
|
+
unless project
|
20
|
+
say "Error: Project '#{options[:project]}' not found", :red
|
21
|
+
exit 1
|
22
|
+
end
|
20
23
|
projectid = project['id']
|
21
24
|
end
|
22
25
|
|
@@ -82,16 +85,16 @@ class Router < Thor
|
|
82
85
|
when "start"
|
83
86
|
exit unless yes?("Start the routers above? [y/N]:", :magenta)
|
84
87
|
routers.each do |router|
|
85
|
-
|
86
|
-
cs_cli.start_router
|
87
|
-
|
88
|
+
say "Start router #{router['name']}... "
|
89
|
+
say "job started ", :green if job = cs_cli.start_router(router['id'])
|
90
|
+
say "(jobid: #{job['jobid']})"
|
88
91
|
end
|
89
92
|
when "stop"
|
90
93
|
exit unless yes?("Stop the routers above? [y/N]:", :magenta)
|
91
94
|
routers.each do |router|
|
92
|
-
|
93
|
-
cs_cli.stop_router
|
94
|
-
|
95
|
+
say "Stop router #{router['name']}... "
|
96
|
+
say "job started ", :green if job = cs_cli.stop_router(router['id'])
|
97
|
+
say "(jobid: #{job['jobid']})"
|
95
98
|
end
|
96
99
|
else
|
97
100
|
say "Command #{options[:command]} not supported", :red
|
@@ -100,24 +103,25 @@ class Router < Thor
|
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
103
|
-
desc "stop ID", "stop virtual router"
|
106
|
+
desc "router stop ID", "stop virtual router"
|
104
107
|
def stop(id)
|
105
108
|
exit unless yes?("Stop the router with ID #{id}?", :magenta)
|
106
109
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
107
110
|
cs_cli.stop_router id
|
108
111
|
end
|
109
112
|
|
110
|
-
desc "start ID", "start virtual router"
|
113
|
+
desc "router start ID", "start virtual router"
|
111
114
|
def start(id)
|
112
115
|
exit unless yes?("Start the router with ID #{id}?", :magenta)
|
113
116
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
114
117
|
cs_cli.start_router id
|
115
118
|
end
|
116
119
|
|
117
|
-
desc "destroy ID", "destroy virtual router"
|
120
|
+
desc "router destroy ID", "destroy virtual router"
|
118
121
|
def destroy(id)
|
122
|
+
exit unless yes?("Destroy the router with ID #{id}?", :magenta)
|
119
123
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
120
|
-
|
124
|
+
say "OK", :green if cs_cli.destroy_router(id)
|
121
125
|
end
|
122
126
|
|
123
127
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Server < Thor
|
2
2
|
|
3
|
-
desc "list", "list servers"
|
3
|
+
desc "server list", "list servers"
|
4
4
|
option :listall, :type => :boolean
|
5
5
|
option :text, :type => :boolean
|
6
6
|
option :project
|
@@ -27,7 +27,7 @@ class Server < Thor
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
desc "create NAME", "create a server"
|
30
|
+
desc "server create NAME", "create a server"
|
31
31
|
option :zone, :required => true
|
32
32
|
option :template, :required => true
|
33
33
|
option :offering, :required => true
|
@@ -36,7 +36,7 @@ class Server < Thor
|
|
36
36
|
option :port_forwarding, :type => :array, :aliases => :pf, :default => [], :description => "public_ip:port"
|
37
37
|
option :interactive, :type => :boolean
|
38
38
|
def create(name)
|
39
|
-
CloudstackCli::
|
39
|
+
CloudstackCli::Helper.new(options[:config]).bootstrap_server(
|
40
40
|
name,
|
41
41
|
options[:zone],
|
42
42
|
options[:template],
|
@@ -47,19 +47,24 @@ class Server < Thor
|
|
47
47
|
)
|
48
48
|
end
|
49
49
|
|
50
|
-
desc "
|
50
|
+
desc "server bootstrap", "interactive creation of a server with network access"
|
51
|
+
def bootstrap
|
52
|
+
CloudstackCli::Helper.new(options[:config]).bootstrap_server_interactive()
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "server stop NAME", "stop a server"
|
51
56
|
def stop(name)
|
52
|
-
CloudstackCli::
|
57
|
+
CloudstackCli::Helper.new(options[:config]).stop_server(name)
|
53
58
|
end
|
54
59
|
|
55
|
-
desc "start NAME", "start a server"
|
60
|
+
desc "server start NAME", "start a server"
|
56
61
|
def start(name)
|
57
|
-
CloudstackCli::
|
62
|
+
CloudstackCli::Helper.new(options[:config]).start_server(name)
|
58
63
|
end
|
59
64
|
|
60
|
-
desc "reboot NAME", "reboot a server"
|
65
|
+
desc "server reboot NAME", "reboot a server"
|
61
66
|
def restart(name)
|
62
|
-
CloudstackCli::
|
67
|
+
CloudstackCli::Helper.new(options[:config]).reboot_server(name)
|
63
68
|
end
|
64
69
|
|
65
70
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Template < Thor
|
2
2
|
|
3
|
-
desc 'list', 'list templates by type [featured|self|self-executable|executable|community]'
|
3
|
+
desc 'template list', 'list templates by type [featured|self|self-executable|executable|community]'
|
4
4
|
option :project
|
5
5
|
def list(type='featured')
|
6
6
|
cs_cli = CloudstackCli::Helper.new(options[:config])
|
@@ -37,7 +37,7 @@ module CloudstackCli
|
|
37
37
|
@cs.update_offering(args)
|
38
38
|
end
|
39
39
|
|
40
|
-
def templates(type = 'featured', project_id)
|
40
|
+
def templates(type = 'featured', project_id = -1)
|
41
41
|
@templates ||= @cs.list_templates(type, project_id)
|
42
42
|
end
|
43
43
|
|
@@ -194,13 +194,13 @@ module CloudstackCli
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
def
|
197
|
+
def bootstrap_server_interactive
|
198
198
|
ARGV.clear
|
199
199
|
puts
|
200
|
-
puts
|
201
|
-
|
202
|
-
|
203
|
-
|
200
|
+
puts "We are going to deploy a new server and..."
|
201
|
+
puts "- assign a public IP address"
|
202
|
+
puts "- create a firewall rule for SSH and HTTP access"
|
203
|
+
puts "- connect to the server and install the puppet client}"
|
204
204
|
puts
|
205
205
|
|
206
206
|
print "Please provide a name for the new server".background(:blue)
|
@@ -756,37 +756,34 @@ module CloudstackClient
|
|
756
756
|
##
|
757
757
|
# Destroy virtual router.
|
758
758
|
|
759
|
-
def destroy_router(id)
|
759
|
+
def destroy_router(id, async = false)
|
760
760
|
params = {
|
761
761
|
'command' => 'destroyRouter',
|
762
762
|
'id' => id
|
763
763
|
}
|
764
|
-
|
765
|
-
json['router'].first
|
764
|
+
async ? send_async_request(params) : send_request(params)
|
766
765
|
end
|
767
766
|
|
768
767
|
##
|
769
768
|
# Start virtual router.
|
770
769
|
|
771
|
-
def start_router(id)
|
770
|
+
def start_router(id, async = false)
|
772
771
|
params = {
|
773
772
|
'command' => 'startRouter',
|
774
773
|
'id' => id
|
775
774
|
}
|
776
|
-
|
777
|
-
json = send_async_request(params)
|
775
|
+
async ? send_async_request(params) : send_request(params)
|
778
776
|
end
|
779
777
|
|
780
778
|
##
|
781
779
|
# Stop virtual router.
|
782
780
|
|
783
|
-
def stop_router(id)
|
781
|
+
def stop_router(id, async = false)
|
784
782
|
params = {
|
785
783
|
'command' => 'stopRouter',
|
786
784
|
'id' => id
|
787
785
|
}
|
788
|
-
|
789
|
-
json = send_async_request(params)
|
786
|
+
async ? send_async_request(params) : send_request(params)
|
790
787
|
end
|
791
788
|
|
792
789
|
##
|
data/lib/cloudstack_cli.rb
CHANGED
data/lib/cloudstack_client.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudstack-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -147,15 +147,17 @@ files:
|
|
147
147
|
homepage: https://bitbucket.org/swisstxt/cloudstack-cli
|
148
148
|
licenses: []
|
149
149
|
post_install_message:
|
150
|
-
rdoc_options:
|
150
|
+
rdoc_options:
|
151
|
+
- --line-numbers
|
152
|
+
- --inline-source
|
151
153
|
require_paths:
|
152
154
|
- lib
|
153
155
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
156
|
none: false
|
155
157
|
requirements:
|
156
|
-
- -
|
158
|
+
- - '='
|
157
159
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
160
|
+
version: 1.9.3
|
159
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
162
|
none: false
|
161
163
|
requirements:
|