cloudstack-cli 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad30d2392877c54e681e2e916aac9ee73078e956
4
+ data.tar.gz: 8becb1fb0bc315c5f7d450ce6db62b48a14c63ff
5
+ SHA512:
6
+ metadata.gz: 4bd74f7c795a3edde19e4531b7925c3c8e39025db89639e85ad01bc9fd997ebeed105a3f89b7a5cedb0ce509147165019850b08ea376cbb3ffe9bf83d0690a4a
7
+ data.tar.gz: 79672ddb07f8e47bfb53c3c6b8d5c4c781d64e64fb513c4249145f18a5ff88d272839a982e5c8a064c240814fb3c91f9ab66c47a92eb114b1708f96e8bdbff33
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudstack-cli (0.2.1)
4
+ cloudstack-cli (0.2.2)
5
5
  thor (~> 0.18.1)
6
6
 
7
7
  GEM
data/LICENSE.txt CHANGED
@@ -1,7 +1,21 @@
1
- Copyright (c) 2013 Nik Wolfgramm
1
+ The MIT License (MIT)
2
2
 
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:
3
+ Copyright (c) 2013 Nik Wolfgramm
4
4
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
6
11
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -16,12 +16,19 @@ Create the initial configuration:
16
16
 
17
17
  cloudstack-cli expects to find a configuartion file with the API URL and your CloudStack credentials in your home directory named .cloudstack-cli.yml. If the file is located elsewhere you can specify the loaction using the --config option.
18
18
 
19
+ cloudstack-cli supports multiple environments using the --environment option.
20
+
19
21
  Example content of the configuration file:
20
22
 
21
23
  :url: "https://my-cloudstack-server/client/api/"
22
24
  :api_key: "cloudstack-api-key"
23
25
  :secret_key: "cloudstack-api-secret"
24
26
 
27
+ test:
28
+ :url: "http://my-cloudstack-testserver/client/api/"
29
+ :api_key: "cloudstack-api-key"
30
+ :secret_key: "cloudstack-api-secret"
31
+
25
32
  ## Usage
26
33
 
27
34
  For additional documentation find the RubyDoc [here](http://rubydoc.info/gems/cloudstack-cli/).
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{cloudstack-cli is a CloudStack API client written in Ruby.}
12
12
  gem.summary = %q{cloudstack-cli CloudStack API client}
13
13
  gem.homepage = "https://bitbucket.org/swisstxt/cloudstack-cli"
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.required_ruby_version = '>= 1.9.3'
16
17
  gem.files = `git ls-files`.split($/)
@@ -19,7 +19,7 @@ module CloudstackCli
19
19
 
20
20
  no_commands do
21
21
  def client(opts = {})
22
- @config ||= CloudstackClient::ConnectionHelper.load_configuration(options[:config])
22
+ @config ||= load_configuration
23
23
  @client ||= CloudstackClient::Connection.new(
24
24
  @config[:url],
25
25
  @config[:api_key],
@@ -28,6 +28,24 @@ module CloudstackCli
28
28
  )
29
29
  end
30
30
 
31
+ def load_configuration(config_file = options[:config], env = options[:environment])
32
+ begin
33
+ config = YAML::load(IO.read(config_file))
34
+ rescue
35
+ error "Can't load configuration from file #{config_file}."
36
+ error "To create a new configuration file run \"cs setup\"."
37
+ exit 1
38
+ end
39
+ if env
40
+ config = config[env]
41
+ unless config
42
+ error "Can't find environment #{env} in configuration file."
43
+ exit 1
44
+ end
45
+ end
46
+ config
47
+ end
48
+
31
49
  def find_project(project_name = options[:project])
32
50
  return nil unless project_name
33
51
  unless project = client.get_project(project_name)
@@ -38,7 +56,7 @@ module CloudstackCli
38
56
  end
39
57
 
40
58
  def filter_by(objects, tag_name, tag)
41
- objects.select {|r| r[tag_name].downcase == tag.downcase }
59
+ objects.select {|r| r[tag_name].downcase == tag.downcase}
42
60
  end
43
61
  end
44
62
  end
@@ -8,7 +8,11 @@ module CloudstackCli
8
8
  class_option :config,
9
9
  default: File.join(Dir.home, '.cloudstack-cli.yml'),
10
10
  aliases: '-c',
11
- desc: 'localition of your cloudstack-cli configuration file'
11
+ desc: 'location of your cloudstack-cli configuration file'
12
+
13
+ class_option :environment,
14
+ aliases: '-e',
15
+ desc: 'environment to load from the configuration file'
12
16
 
13
17
  desc "version", "outputs the cloudstack-cli version"
14
18
  def version
@@ -22,8 +26,9 @@ module CloudstackCli
22
26
  def setup(file = options[:config])
23
27
  config = {}
24
28
  unless options[:url]
29
+ say "Configuring #{options[:environment] || 'default'} environment."
25
30
  say "What's the URL of your Cloudstack API?", :yellow
26
- say "Example: https://my-cloudstack-server/client/api/", :yellow
31
+ say "Example: https://my-cloudstack-service/client/api/"
27
32
  config[:url] = ask("URL:", :magenta)
28
33
  end
29
34
  unless options[:api_key]
@@ -32,9 +37,20 @@ module CloudstackCli
32
37
  unless options[:secret_key]
33
38
  config[:secret_key] = ask("Secret Key:", :magenta)
34
39
  end
40
+ if options[:environment]
41
+ config = {options[:environment] => config}
42
+ end
35
43
  if File.exists? file
44
+ begin
45
+ old_config = YAML::load(IO.read(file))
46
+ rescue
47
+ error "Can't load configuration from file #{config_file}."
48
+ error "To create a new configuration file run \"cs setup\"."
49
+ exit 1
50
+ end
36
51
  say "Warning: #{file} already exists.", :red
37
- exit unless yes?("Overwrite [y/N]", :red)
52
+ exit unless yes?("Do you want to merge your settings? [y/N]", :red)
53
+ config = old_config.merge(config)
38
54
  end
39
55
  File.open(file, 'w+') {|f| f.write(config.to_yaml) }
40
56
  end
@@ -1,3 +1,3 @@
1
1
  module CloudstackCli
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -69,7 +69,12 @@ module CloudstackClient
69
69
  exit 1
70
70
  end
71
71
 
72
- json = JSON.parse(response.body)
72
+ begin
73
+ json = JSON.parse(response.body)
74
+ rescue JSON::ParserError
75
+ puts "Error parsing response from server."
76
+ exit 1
77
+ end
73
78
  json[params['command'].downcase + 'response']
74
79
  end
75
80
 
@@ -1,3 +1,2 @@
1
1
  require "cloudstack-client/version"
2
- require "cloudstack-client/client"
3
- require "cloudstack-client/helper"
2
+ require "cloudstack-client/client"
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudstack-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nik Wolfgramm
@@ -14,23 +13,20 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rdoc
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: thor
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -114,13 +107,14 @@ files:
114
107
  - lib/cloudstack-client/commands/template.rb
115
108
  - lib/cloudstack-client/commands/volumes.rb
116
109
  - lib/cloudstack-client/commands/zone.rb
117
- - lib/cloudstack-client/helper.rb
118
110
  - lib/cloudstack-client/version.rb
119
111
  - lib/cloudstack_cli.rb
120
112
  - lib/cloudstack_client.rb
121
113
  - test/stack_example.json
122
114
  homepage: https://bitbucket.org/swisstxt/cloudstack-cli
123
- licenses: []
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
124
118
  post_install_message:
125
119
  rdoc_options:
126
120
  - --line-numbers
@@ -128,22 +122,20 @@ rdoc_options:
128
122
  require_paths:
129
123
  - lib
130
124
  required_ruby_version: !ruby/object:Gem::Requirement
131
- none: false
132
125
  requirements:
133
- - - ! '>='
126
+ - - '>='
134
127
  - !ruby/object:Gem::Version
135
128
  version: 1.9.3
136
129
  required_rubygems_version: !ruby/object:Gem::Requirement
137
- none: false
138
130
  requirements:
139
- - - ! '>='
131
+ - - '>='
140
132
  - !ruby/object:Gem::Version
141
133
  version: '0'
142
134
  requirements: []
143
135
  rubyforge_project:
144
- rubygems_version: 1.8.23
136
+ rubygems_version: 2.0.2
145
137
  signing_key:
146
- specification_version: 3
138
+ specification_version: 4
147
139
  summary: cloudstack-cli CloudStack API client
148
140
  test_files:
149
141
  - test/stack_example.json
@@ -1,13 +0,0 @@
1
- module CloudstackClient
2
- module ConnectionHelper
3
- def self.load_configuration(config_file)
4
- begin
5
- return YAML::load(IO.read(config_file))
6
- rescue Exception => e
7
- $stderr.puts "Can't find the config file #{config_file}."
8
- $stderr.puts "To create a new configuration file run \"cs setup\"."
9
- exit 1
10
- end
11
- end
12
- end
13
- end