cloudstack-cli 0.11.2 → 0.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b40125323297400e446ffdfd031ac259c5f5c428
4
- data.tar.gz: b0db8bf88f21e74971c31ae2ad144b9be78d7625
3
+ metadata.gz: b22ed0cd78d135de76f2016d9e4f9f6d0dae9b3a
4
+ data.tar.gz: 035f34a2d3a712a5b73ad5cead88ed593bb66ff9
5
5
  SHA512:
6
- metadata.gz: a2a21fadec443296a133fa8516ef4864555f86f6f322c5e0943cdd037ac80c507c00119f8353d7d4f6d06d631c99fdf3ed69011053885cecae9a171c417d2bc7
7
- data.tar.gz: 6906eb9f5c110208a8cb278ca6833b80c00b7781efa28a1fb2f8ff136283001c667689316257121887f33bb47d79ef7d2679dbd6f3e6c1404d7a221b186436dc
6
+ metadata.gz: e9f20c5f34ea889ec211c221c2399b920a9d7d52d99bb9b7f3f49562be89d57d32499755042b547f82d301f5df35cff436cc1bb0e0120a4f54db0b01f91876f7
7
+ data.tar.gz: 20e9ae88467b01b2912ee92daaf4fbaa188f43246fc9f195b74e818114daa044404c28c4cf93eecb04580287074fff1946074c4c5c5c8974e803f7115310f769
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- #gem 'cloudstack_client', git: 'git@github.com:niwo/cloudstack_client.git', branch: 'master'
4
- #gem 'thor', git: 'git@github.com:erikhuda/thor.git', branch: 'master'
3
+ gem 'cloudstack_client', git: 'git@github.com:niwo/cloudstack_client.git', branch: 'master'
5
4
 
6
5
  # Specify your gem's dependencies in cloudstack-cli.gemspec
7
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,15 +1,21 @@
1
+ GIT
2
+ remote: git@github.com:niwo/cloudstack_client.git
3
+ revision: 7e6e2af2299cbb681b2fff8a065c8e91c06ea7ae
4
+ branch: master
5
+ specs:
6
+ cloudstack_client (0.8.0)
7
+
1
8
  PATH
2
9
  remote: .
3
10
  specs:
4
- cloudstack-cli (0.11.2)
5
- cloudstack_client (~> 0.7, >= 0.7.1)
11
+ cloudstack-cli (0.12.0)
12
+ cloudstack_client (~> 0.8.0)
6
13
  thor (~> 0.19.1)
7
14
 
8
15
  GEM
9
16
  remote: https://rubygems.org/
10
17
  specs:
11
- cloudstack_client (0.7.1)
12
- json (1.8.1)
18
+ json (1.8.2)
13
19
  rake (10.4.2)
14
20
  rdoc (4.2.0)
15
21
  json (~> 1.4)
@@ -20,5 +26,6 @@ PLATFORMS
20
26
 
21
27
  DEPENDENCIES
22
28
  cloudstack-cli!
23
- rake (~> 10.3)
24
- rdoc (~> 4.1)
29
+ cloudstack_client!
30
+ rake (~> 10.4)
31
+ rdoc (~> 4.2)
data/README.md CHANGED
@@ -27,7 +27,7 @@ cloudstack-cli expects to find a configuartion file with the API URL and your Cl
27
27
 
28
28
  cloudstack-cli supports multiple environments using the --environment option.
29
29
 
30
- see `cs help environment` for more options.
30
+ see `cs help environment` for more options.
31
31
 
32
32
  Example content of the configuration file:
33
33
 
@@ -81,45 +81,42 @@ $ cs command listAlerts type=8
81
81
 
82
82
  ### Example: Creating a complete stack of servers
83
83
 
84
- An example stackfile looks like this (my_stackfile.json)
85
-
86
- ```json
87
- {
88
- "name": "web_stack-a",
89
- "description": "Web Application Stack",
90
- "version": "1.0",
91
- "zone": "DC-BIE-1",
92
- "group": "my_web_stack",
93
- "keypair": "mykeypair",
94
- "servers": [
95
- {
96
- "name": "web-d1, web-d2",
97
- "description": "Web nodes",
98
- "template": "CentOS-6.4-x64-v1.2",
99
- "offering": "1cpu_1gb",
100
- "networks": "server_network",
101
- "port_rules": ":80, :443"
102
- },
103
- {
104
- "name": "db-01",
105
- "description": "PostgreSQL Master",
106
- "iso": "CentOS-6.4-x86_64-swisstxt-v15",
107
- "disk_offering": "Perf Storage",
108
- "disk_size": "5",
109
- "offering": "2cpu_4gb",
110
- "networks": [
111
- "server_network",
112
- "storage_network"
113
- ]
114
- }
115
- ]
116
- }
84
+ Cloudstack-CLI does support stack files in YAML or JSON.
85
+
86
+ An example stackfile could look like this (my_stackfile.yml):
87
+
88
+ ```yaml
89
+ ---
90
+ name: "web_stack-a"
91
+ description: "Web Application Stack"
92
+ version: "1.0"
93
+ zone: "DC-ZRH-1"
94
+ group: "my_web_stack"
95
+ keypair: "mykeypair"
96
+ servers:
97
+ -
98
+ name: "web-d1, web-d2"
99
+ description: "Web nodes"
100
+ template: "CentOS-7-x64"
101
+ offering: "1cpu_1gb"
102
+ networks: "server_network"
103
+ port_rules: ":80, :443"
104
+ -
105
+ name: "db-01"
106
+ description: "PostgreSQL Master"
107
+ iso: "CentOS-7-x64"
108
+ disk_offering: "Perf Storage"
109
+ disk_size: "5"
110
+ offering: "2cpu_4gb"
111
+ networks:
112
+ - "server_network"
113
+ - "storage_network"
117
114
  ```
118
115
 
119
116
  Create the stack of servers from above:
120
117
 
121
118
  ```sh
122
- $ cs stack create my_stackfile.json
119
+ $ cs stack create my_stackfile.yml
123
120
  ```
124
121
 
125
122
  ### Example: Sort computing offerings
@@ -21,9 +21,9 @@ Gem::Specification.new do |gem|
21
21
  gem.require_paths = %w(lib)
22
22
  gem.rdoc_options = %w[--line-numbers --inline-source]
23
23
 
24
- gem.add_development_dependency('rdoc', '~> 4.1')
25
- gem.add_development_dependency('rake', '~> 10.3')
24
+ gem.add_development_dependency('rdoc', '~> 4.2')
25
+ gem.add_development_dependency('rake', '~> 10.4')
26
26
 
27
27
  gem.add_dependency('thor', '~> 0.19.1')
28
- gem.add_dependency('cloudstack_client', '~> 0.7', '>= 0.7.1')
28
+ gem.add_dependency('cloudstack_client', '~> 0.8.0')
29
29
  end
@@ -7,29 +7,29 @@ module CloudstackCli
7
7
  class_option :config_file,
8
8
  default: File.join(Dir.home, '.cloudstack-cli.yml'),
9
9
  aliases: '-c',
10
- desc: 'location of your cloudstack-cli configuration file'
10
+ desc: 'Location of your cloudstack-cli configuration file'
11
11
 
12
12
  class_option :env,
13
13
  aliases: '-e',
14
- desc: 'environment to use'
14
+ desc: 'Environment to use'
15
15
 
16
16
  class_option :debug,
17
- desc: 'enable debug output',
17
+ desc: 'Enable debug output',
18
18
  type: :boolean
19
19
 
20
- desc "version", "print cloudstack-cli version number"
20
+ desc "version", "Print cloudstack-cli version number"
21
21
  def version
22
22
  say "cloudstack-cli version #{CloudstackCli::VERSION}"
23
23
  end
24
24
  map %w(-v --version) => :version
25
25
 
26
- desc "setup", "initial configuration of Cloudstack connection settings"
26
+ desc "setup", "Initial configuration of Cloudstack connection settings"
27
27
  def setup(env = options[:environment])
28
28
  invoke "environment:add", [env],
29
29
  :config_file => options[:config_file]
30
30
  end
31
31
 
32
- desc "completion", "loads the shell scripts for <tab> auto-completion"
32
+ desc "completion", "Load the shell scripts for <tab> auto-completion"
33
33
  option :shell, default: 'bash'
34
34
  def completion
35
35
  shell_script = File.join(
@@ -43,7 +43,7 @@ module CloudstackCli
43
43
  puts File.read shell_script
44
44
  end
45
45
 
46
- desc "command COMMAND [arg1=val1 arg2=val2...]", "run a custom api command"
46
+ desc "command COMMAND [arg1=val1 arg2=val2...]", "Run a custom api command"
47
47
  def command(command, *args)
48
48
  params = {'command' => command}
49
49
  args.each do |arg|
@@ -153,5 +153,8 @@ module CloudstackCli
153
153
 
154
154
  desc "configuration SUBCOMMAND ...ARGS", "List cloudstack configuration values"
155
155
  subcommand :configuration, Configuration
156
+
157
+ desc "resource_limit SUBCOMMAND ...ARGS", "Show cloudstack resource limits"
158
+ subcommand :resource_limit, ResourceLimit
156
159
  end
157
160
  end
@@ -6,6 +6,21 @@ class Account < CloudstackCli::Base
6
6
  2 => 'admin'
7
7
  }
8
8
 
9
+ desc "show NAME", "show detailed infos about an account"
10
+ def show(name)
11
+ unless account = client.list_accounts({name: name})
12
+ puts "No account with name #{name} found."
13
+ else
14
+ account = account.first
15
+ account.delete 'user'
16
+ account['accounttype'] = "#{account['accounttype']} (#{TYPES[account['accounttype']]})"
17
+ table = account.map do |key, value|
18
+ [ set_color("#{key}", :yellow), "#{value}" ]
19
+ end
20
+ print_table table
21
+ end
22
+ end
23
+
9
24
  desc 'list [NAME]', 'list accounts (by name)'
10
25
  def list(name = nil)
11
26
  accounts = client.list_accounts({name: name})
@@ -20,5 +35,5 @@ class Account < CloudstackCli::Base
20
35
  say "Total number of accounts: #{accounts.size}"
21
36
  end
22
37
  end
23
-
24
- end
38
+
39
+ end
@@ -1,7 +1,6 @@
1
1
  class Project < CloudstackCli::Base
2
2
 
3
3
  desc "show NAME", "show detailed infos about a project"
4
- option :project
5
4
  def show(name)
6
5
  unless project = client.get_project(name)
7
6
  puts "No project with name #{name} found."
@@ -27,5 +26,5 @@ class Project < CloudstackCli::Base
27
26
  say "Total number of projects: #{projects.count}"
28
27
  end
29
28
  end
30
-
31
- end
29
+
30
+ end
@@ -0,0 +1,61 @@
1
+ class ResourceLimit < CloudstackCli::Base
2
+ RESOURCE_TYPES = {
3
+ 0 => {name: "Instances"},
4
+ 1 => {name: "IP Addresses"},
5
+ 2 => {name: "Volumes"},
6
+ 3 => {name: "Snapshots"},
7
+ 4 => {name: "Templates"},
8
+ 5 => {name: "Projects"},
9
+ 6 => {name: "Networks"},
10
+ 7 => {name: "VPC's"},
11
+ 8 => {name: "CPU's"},
12
+ 9 => {name: "Memory", unit: "GB", divider: 1024.0},
13
+ 10 => {name: "Primary Storage", unit: "TB", divider: 1024.0},
14
+ 11 => {name: "Secondary Storage", unit: "TB", divider: 1024.0}
15
+ }
16
+
17
+ desc "list", "list resource limits"
18
+ option :account
19
+ option :project
20
+ option :type, desc: "specify type, see types for a list of types"
21
+ def list
22
+ limits = client.list_resource_limits(options)
23
+ table = []
24
+ header = options[:project] ? ["Project"] : ["Account"]
25
+ header += ["Type", "Resource Name", "Max"]
26
+ limits.each do |limit|
27
+ limit['resourcetype'] = limit['resourcetype'].to_i
28
+ table << [
29
+ options[:project] ? limit['project'] : limit['account'],
30
+ limit['resourcetype'],
31
+ RESOURCE_TYPES[limit['resourcetype']][:name],
32
+ resource_to_s(limit, 'max')
33
+ ]
34
+ end
35
+ table = table.insert(0, header)
36
+ print_table table
37
+ end
38
+
39
+ desc "types", "show resource types"
40
+ def types
41
+ table = [['type', 'name']]
42
+ RESOURCE_TYPES.each_pair do |type, data|
43
+ table << [type, data[:name]]
44
+ end
45
+ print_table table
46
+ end
47
+
48
+ no_commands do
49
+
50
+ def resource_to_s(limit, entity)
51
+ value = RESOURCE_TYPES[limit['resourcetype']][:divider] ?
52
+ (limit[entity] / RESOURCE_TYPES[limit['resourcetype']][:divider]).round(1) :
53
+ limit[entity]
54
+ RESOURCE_TYPES[limit['resourcetype']][:unit] ?
55
+ "#{value} #{RESOURCE_TYPES[limit['resourcetype']][:unit]}" :
56
+ value.to_s
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -1,8 +1,8 @@
1
1
  class Stack < CloudstackCli::Base
2
2
 
3
- desc "create STACKFILE", "create a stack of servers"
3
+ desc "create STACKFILE", "create a stack of servers"
4
4
  def create(stackfile)
5
- stack = parse_stackfile(stackfile)
5
+ stack = parse_stackfile(stackfile)
6
6
  say "Create stack #{stack["name"]}...", :green
7
7
  projectid = find_project(stack["project"])['id'] if stack["project"]
8
8
  jobs = []
@@ -42,7 +42,7 @@ class Stack < CloudstackCli::Base
42
42
  end
43
43
  end
44
44
  watch_jobs(jobs)
45
-
45
+
46
46
  say "Check for port forwarding rules...", :green
47
47
  jobs = []
48
48
  stack["servers"].each do |instance|
@@ -105,13 +105,24 @@ class Stack < CloudstackCli::Base
105
105
 
106
106
  no_commands do
107
107
  def parse_stackfile(stackfile)
108
+ handler = case File.extname(stackfile)
109
+ when ".json"
110
+ Object.const_get "JSON"
111
+ when ".yaml", ".yml"
112
+ Object.const_get "YAML"
113
+ else
114
+ say "File extension #{File.extname(stackfile)} not supported. Supported extensions are .json, .yaml or .yml", :red
115
+ exit
116
+ end
108
117
  begin
109
- return JSON.parse File.read(stackfile)
118
+ return handler.load File.read(stackfile)
110
119
  rescue SystemCallError
111
- $stderr.puts "Can't find the stack file #{stackfile}."
112
- rescue JSON::ParserError => e
113
- $stderr.puts "Error parsing json file.\n#{e.message}."
114
- exit
120
+ say "Can't find the stack file #{stackfile}.", :red
121
+ exit 1
122
+ rescue => e
123
+ say "Error parsing #{File.extname(stackfile)} file:", :red
124
+ say e.message
125
+ exit 1
115
126
  end
116
127
  end
117
128
 
@@ -3,7 +3,7 @@ module CloudstackCli
3
3
  def print_options(options, attr = 'name')
4
4
  options.to_enum.with_index(1).each do |option, i|
5
5
  puts "#{i}: #{option[attr]}"
6
- end
6
+ end
7
7
  end
8
8
 
9
9
  def ask_number(question)
@@ -60,7 +60,8 @@ module CloudstackCli
60
60
  puts job[:status] == 0 ? spinner.first : ""
61
61
  end
62
62
  t_elapsed = opts[:t_start] ? (Time.now - opts[:t_start]).round(1) : 0
63
- puts "Runtime: #{t_elapsed}s"
63
+ completed = jobs.select{|j| j[:status] == 1}.size
64
+ say "Completed: #{completed}/#{jobs.size} (#{t_elapsed}s)", :magenta
64
65
  sleep opts[:sleeptime] || 0.1
65
66
  spinner.push spinner.shift
66
67
  spinner
@@ -119,7 +120,7 @@ module CloudstackCli
119
120
  )
120
121
  end
121
122
  port = pf_rule.split(":")[1]
122
- if async
123
+ if async
123
124
  say "Create port forwarding rule #{ip_addr['ipaddress']}:#{port} for server #{server["name"]}.", :yellow
124
125
  client.create_port_forwarding_rule(ip_addr["id"], port, 'TCP', port, server["id"])
125
126
  return
@@ -199,4 +200,4 @@ module CloudstackCli
199
200
  end
200
201
 
201
202
  end
202
- end
203
+ end
@@ -1,3 +1,3 @@
1
1
  module CloudstackCli
2
- VERSION = "0.11.2"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -9,7 +9,7 @@
9
9
  {
10
10
  "name": "web-001, web-002",
11
11
  "description": "Web nodes",
12
- "template": "CentOS-6.4-x64-v1.2",
12
+ "template": "CentOS-6.5-x64-v1.3",
13
13
  "offering": "1cpu_1gb",
14
14
  "networks": "M_PLAY",
15
15
  "port_rules": ":80, :443"
@@ -17,11 +17,11 @@
17
17
  {
18
18
  "name": "db-001",
19
19
  "description": "PostgreSQL Master",
20
- "iso": "CentOS-6.4-x86_64-swisstxt-v15",
20
+ "iso": "CentOS-7.0 x64",
21
21
  "disk_offering": "Perf Storage",
22
22
  "disk_size": "5",
23
23
  "offering": "2cpu_4gb",
24
24
  "networks": "M_PLAY"
25
25
  }
26
26
  ]
27
- }
27
+ }
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: "web_stack_a"
3
+ description: "Web Application Stack"
4
+ version: "1.0"
5
+ zone: "BIEL_CU01"
6
+ project: "Playground"
7
+ group: "my_web_stack"
8
+ servers:
9
+ -
10
+ name: "web-001, web-002"
11
+ description: "Web nodes"
12
+ template: "CentOS-6.5-x64-v1.3"
13
+ offering: "1cpu_1gb"
14
+ networks: "M_PLAY"
15
+ port_rules: ":80, :443"
16
+ -
17
+ name: "db-001"
18
+ description: "PostgreSQL Master"
19
+ iso: "CentOS-7.0 x64"
20
+ disk_offering: "Perf Storage"
21
+ disk_size: "5"
22
+ offering: "2cpu_4gb"
23
+ networks: "M_PLAY"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nik Wolfgramm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '4.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.1'
26
+ version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.3'
33
+ version: '10.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.3'
40
+ version: '10.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.7'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 0.7.1
61
+ version: 0.8.0
65
62
  type: :runtime
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - "~>"
70
67
  - !ruby/object:Gem::Version
71
- version: '0.7'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 0.7.1
68
+ version: 0.8.0
75
69
  description: cloudstack-cli is a CloudStack API command line client written in Ruby.
76
70
  email:
77
71
  - nik.wolfgramm@gmail.com
@@ -115,6 +109,7 @@ files:
115
109
  - lib/cloudstack-cli/commands/port_rule.rb
116
110
  - lib/cloudstack-cli/commands/project.rb
117
111
  - lib/cloudstack-cli/commands/region.rb
112
+ - lib/cloudstack-cli/commands/resource_limit.rb
118
113
  - lib/cloudstack-cli/commands/router.rb
119
114
  - lib/cloudstack-cli/commands/server.rb
120
115
  - lib/cloudstack-cli/commands/snapshot.rb
@@ -129,6 +124,7 @@ files:
129
124
  - lib/cloudstack-cli/helper.rb
130
125
  - lib/cloudstack-cli/version.rb
131
126
  - test/stack_example.json
127
+ - test/stack_example.yml
132
128
  homepage: http://niwo.github.io/cloudstack-cli/
133
129
  licenses:
134
130
  - MIT
@@ -157,3 +153,4 @@ specification_version: 4
157
153
  summary: cloudstack-cli CloudStack API client
158
154
  test_files:
159
155
  - test/stack_example.json
156
+ - test/stack_example.yml