cloudstack-cli 0.3.7 → 0.3.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack-cli (0.3.5)
4
+ cloudstack-cli (0.3.8)
5
5
  thor (~> 0.18.1)
6
6
 
7
7
  GEM
@@ -26,7 +26,7 @@ module CloudstackCli
26
26
  @config[:url],
27
27
  @config[:api_key],
28
28
  @config[:secret_key],
29
- opts
29
+ opts.merge({debug: options[:debug]})
30
30
  )
31
31
  end
32
32
 
@@ -14,6 +14,10 @@ module CloudstackCli
14
14
  aliases: '-e',
15
15
  desc: 'environment to load from the configuration file'
16
16
 
17
+ class_option :debug,
18
+ desc: 'enable debug output',
19
+ type: :boolean
20
+
17
21
  desc "version", "outputs the cloudstack-cli version"
18
22
  def version
19
23
  say "cloudstack-cli v#{CloudstackCli::VERSION}"
@@ -78,6 +82,9 @@ module CloudstackCli
78
82
  desc "cluster SUBCOMMAND ...ARGS", "List clusters"
79
83
  subcommand "cluster", Cluster
80
84
 
85
+ desc "host SUBCOMMAND ...ARGS", "List hosts"
86
+ subcommand "host", Host
87
+
81
88
  desc "project SUBCOMMAND ...ARGS", "Manage servers"
82
89
  subcommand "project", Project
83
90
 
@@ -0,0 +1,20 @@
1
+ class Host < CloudstackCli::Base
2
+
3
+ desc 'list', 'list hosts'
4
+ option :zone
5
+ def list
6
+ hosts = client.list_hosts(options)
7
+ if hosts.size < 1
8
+ say "No hosts found."
9
+ else
10
+ table = [["Zone", "Type", "Cluster", "Name"]]
11
+ hosts.each do |host|
12
+ table << [
13
+ host['zonename'], host['type'], host['clustername'], host['name']
14
+ ]
15
+ end
16
+ print_table table
17
+ end
18
+ end
19
+
20
+ end
@@ -1,19 +1,19 @@
1
1
  class Iso < CloudstackCli::Base
2
2
 
3
- desc 'list [TYPE]', "list iso's by type [featured|self|self-executable|executable|community]"
3
+ desc 'list [TYPE]', "list iso's by type [featured|self|self-executable|executable|community], default is featured"
4
4
  option :project
5
5
  option :zone
6
6
  option :account
7
7
  option :listall
8
8
  def list(type='featured')
9
9
  project = find_project if options[:project]
10
- unless %w(featured self self-executable executable community).include? type
10
+ unless %w(featured self self-executable executable community).include?(type)
11
11
  say "unsupported iso type '#{type}'", :red
12
12
  exit 1
13
13
  end
14
14
  zone = client.get_zone(options[:zone]) if options[:zone]
15
15
  isos = client.list_isos(
16
- type: type,
16
+ filter: type,
17
17
  project_id: project ? project['id'] : nil,
18
18
  zone_id: zone ? zone['id'] : nil
19
19
  )
@@ -20,6 +20,27 @@ class Network < CloudstackCli::Base
20
20
  end
21
21
  end
22
22
 
23
+ desc "show NAME", "show detailed infos about a network"
24
+ option :project
25
+ def show(name)
26
+ if options[:project]
27
+ if options[:project].downcase == "all"
28
+ options[:project_id] = -1
29
+ else
30
+ project = find_project
31
+ options[:project_id] = project['id']
32
+ end
33
+ end
34
+ unless server = client.get_network(name, options[:project_id])
35
+ puts "No network found."
36
+ else
37
+ server.each do |key, value|
38
+ say "#{key}: ", :yellow
39
+ say "#{value}"
40
+ end
41
+ end
42
+ end
43
+
23
44
  desc "list", "list networks"
24
45
  option :project
25
46
  option :account
@@ -58,14 +79,29 @@ class Network < CloudstackCli::Base
58
79
  end
59
80
  end
60
81
 
82
+ desc "restart NAME", "restart network"
83
+ option :cleanup, type: :boolean, default: true
84
+ def restart(name)
85
+ network = client.get_network(name)
86
+ network = client.get_network(name, -1) unless network
87
+ unless network
88
+ say "Network #{name} not found."
89
+ exit 1
90
+ end
91
+ if yes? "Restart network \"#{network['name']}\" (cleanup=#{options[:cleanup]})?"
92
+ p client.restart_network(network['id'], options[:cleanup])
93
+ end
94
+ end
95
+
61
96
  desc "delete NAME", "delete network"
62
97
  def delete(name)
63
- network = client.get_network(name, -1)
98
+ network = client.get_network(name)
99
+ network = client.get_network(name, -1) unless network
64
100
  unless network
65
- say "Network #{name} not found."
101
+ say "Network \"#{name}\" not found."
66
102
  exit 1
67
103
  end
68
- if yes? "Destroy network #{network['name']} - #{network['name']}?"
104
+ if yes? "Destroy network \"#{network['name']}\"?"
69
105
  p client.delete_network(network['id'])
70
106
  end
71
107
  end
@@ -1,5 +1,18 @@
1
1
  class Project < CloudstackCli::Base
2
2
 
3
+ desc "show NAME", "show detailed infos about a project"
4
+ option :project
5
+ def show(name)
6
+ unless project = client.get_project(name)
7
+ puts "No project with name #{name} found."
8
+ else
9
+ project.each do |key, value|
10
+ say "#{key}: ", :yellow
11
+ say "#{value}"
12
+ end
13
+ end
14
+ end
15
+
3
16
  desc "list", "list projects"
4
17
  def list
5
18
  projects = client.list_projects
@@ -31,9 +31,9 @@ class Server < CloudstackCli::Base
31
31
  end
32
32
  end
33
33
 
34
- desc "info NAME", "show detailed infos about a server"
34
+ desc "show NAME", "show detailed infos about a server"
35
35
  option :project
36
- def info(name)
36
+ def show(name)
37
37
  if options[:project]
38
38
  if options[:project].downcase == "all"
39
39
  options[:project_id] = -1
@@ -1,6 +1,6 @@
1
1
  class Template < CloudstackCli::Base
2
2
 
3
- desc 'list [TYPE]', 'list templates by type [featured|self|self-executable|executable|community]'
3
+ desc 'list [TYPE]', 'list templates by type [featured|self|self-executable|executable|community], default is featured'
4
4
  option :project
5
5
  option :zone
6
6
  def list(type='featured')
@@ -11,7 +11,7 @@ class Template < CloudstackCli::Base
11
11
  end
12
12
  zone = client.get_zone(options[:zone]) if options[:zone]
13
13
  templates = client.list_templates(
14
- type: type,
14
+ filter: type,
15
15
  project_id: project ? project['id'] : nil,
16
16
  zone_id: zone ? zone['id'] : nil
17
17
  )
@@ -1,3 +1,3 @@
1
1
  module CloudstackCli
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -28,6 +28,7 @@ module CloudstackClient
28
28
  @secret_key = secret_key
29
29
  @use_ssl = api_url.start_with? "https"
30
30
  @verbose = opts[:quiet] ? false : true
31
+ @debug = opts[:debug] ? true : false
31
32
  end
32
33
 
33
34
  ##
@@ -44,6 +45,9 @@ module CloudstackClient
44
45
  params.sort.each { |elem|
45
46
  params_arr << elem[0].to_s + '=' + CGI.escape(elem[1].to_s).gsub('+', '%20').gsub(' ','%20')
46
47
  }
48
+
49
+ debug_output JSON.pretty_generate(params) if @debug
50
+
47
51
  data = params_arr.join('&')
48
52
  signature = OpenSSL::HMAC.digest('sha1', @secret_key, data.downcase)
49
53
  signature = Base64.encode64(signature).chomp
@@ -118,5 +122,15 @@ module CloudstackClient
118
122
  exit 1
119
123
  end
120
124
 
125
+ private
126
+
127
+ def debug_output(output, seperator = '-' * 80)
128
+ puts
129
+ puts seperator
130
+ puts output
131
+ puts seperator
132
+ puts
133
+ end
134
+
121
135
  end # class
122
136
  end
@@ -0,0 +1,28 @@
1
+ module CloudstackClient
2
+
3
+ module Host
4
+
5
+ ##
6
+ # Lists hosts.
7
+
8
+ def list_hosts(args = {})
9
+ params = {
10
+ 'command' => 'listHosts'
11
+ }
12
+
13
+ if args[:zone]
14
+ zone = get_zone(args[:zone])
15
+ unless zone
16
+ puts "Error: zone #{args[:project]} not found."
17
+ exit 1
18
+ end
19
+ params['zoneid'] = zone['id']
20
+ end
21
+
22
+ json = send_request(params)
23
+ json['host'] || []
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -17,7 +17,7 @@ module CloudstackClient
17
17
  filter = args[:filter] || 'featured'
18
18
  params = {
19
19
  'command' => 'listIsos',
20
- 'isoFilter' => filter
20
+ 'isofilter' => filter
21
21
  }
22
22
  params['projectid'] = args[:project_id] if args[:project_id]
23
23
  params['zoneid'] = args[:zone_id] if args[:zone_id]
@@ -99,6 +99,19 @@ module CloudstackClient
99
99
  json['network']
100
100
  end
101
101
 
102
+ ##
103
+ # Restart network.
104
+
105
+ def restart_network(id, cleanup = false)
106
+ params = {
107
+ 'command' => 'restartNetwork',
108
+ 'id' => id,
109
+ 'cleanup' => cleanup,
110
+ }
111
+ p json = send_async_request(params)
112
+ json['network']
113
+ end
114
+
102
115
  ##
103
116
  # Lists all physical networks.
104
117
 
@@ -1,3 +1,3 @@
1
1
  module CloudstackClient
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
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.3.7
4
+ version: 0.3.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-23 00:00:00.000000000 Z
12
+ date: 2013-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -81,6 +81,7 @@ files:
81
81
  - lib/cloudstack-cli/commands/cluster.rb
82
82
  - lib/cloudstack-cli/commands/disk_offering.rb
83
83
  - lib/cloudstack-cli/commands/domain.rb
84
+ - lib/cloudstack-cli/commands/host.rb
84
85
  - lib/cloudstack-cli/commands/ip_address.rb
85
86
  - lib/cloudstack-cli/commands/iso.rb
86
87
  - lib/cloudstack-cli/commands/job.rb
@@ -108,6 +109,7 @@ files:
108
109
  - lib/cloudstack-client/commands/cluster.rb
109
110
  - lib/cloudstack-client/commands/disk_offering.rb
110
111
  - lib/cloudstack-client/commands/domain.rb
112
+ - lib/cloudstack-client/commands/host.rb
111
113
  - lib/cloudstack-client/commands/ip_address.rb
112
114
  - lib/cloudstack-client/commands/iso.rb
113
115
  - lib/cloudstack-client/commands/job.rb