rightscale-cli 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4bb058deb48db44d302717cb5975b254c4d4914
4
- data.tar.gz: 5e826a2b5d6a6b68823a61dde906f36f47cace1b
3
+ metadata.gz: 8d2ce2baf29c81d2b85a867713659c964d26f890
4
+ data.tar.gz: 35ae05487225b689a25e6c8b709e487ce02504b7
5
5
  SHA512:
6
- metadata.gz: 2f16f06941398b9ad84b3f06121879c549e67dc532195c411cb34af7ca469b097077089438382edead30d7cddf728325c48b9ce07975a15c4ce2f674eef103e0
7
- data.tar.gz: 2747385386f8dedd7863e41512e164f8c7684da80fad870a9170c5aa24b3ebf2a7cea9a2344d045381741dd76dafd9e5970f356af709c09d2bfd20f1764b0957
6
+ metadata.gz: 7ee7e7330c4a4b1aa5be4cf4a11d56156398462b8e14cdfdb0eb7e0bc4935d451a27c73d89a342efbf3c7824bc80a7aeaa5272b7cae602f3b8371fe1baf6c39e
7
+ data.tar.gz: d706e6fc89434481e328bbcd6cfec740abc74b001e16c415871d2997fe59bb2ad96f075fb2d8134d2bdeb4ec9e906f3368e8d43582f0ed8c8329c41612818365
data/README.md CHANGED
@@ -25,7 +25,7 @@ As a result, to avoid overwriting the `/usr/bin/rs` binary, use a different loca
25
25
  ## Configuration
26
26
 
27
27
  Setup `~/.rightscale/right_api_client.yml` with your RightScale credentials.
28
- Ensure the correct shard is for your account is set with `:api_url`.
28
+ Ensure the correct shard for your account is set with `:api_url`.
29
29
 
30
30
  An example file is available, https://github.com/rightscale/right_api_client/blob/master/config/login.yml.example.
31
31
 
@@ -20,10 +20,16 @@ require 'rightscale_cli/logger'
20
20
 
21
21
  class RightScaleCLI
22
22
  class Client
23
+ attr_accessor :client
23
24
  attr_accessor :render
24
25
 
25
- def initialize(*args)
26
- @client = RightApi::Client.new(RightScaleCLI::Config::API)
26
+ def initialize(options)
27
+ config = RightScaleCLI::Config::API
28
+ config[:account_id] = options['account'] if options[:account]
29
+ config[:api_version] = options['api'] if options[:api]
30
+
31
+ @options = options
32
+ @client = RightApi::Client.new(config)
27
33
  @logger = RightScaleCLI::Logger.new()
28
34
  end
29
35
 
@@ -35,6 +41,20 @@ class RightScaleCLI
35
41
  return result
36
42
  end
37
43
 
44
+ def show(resource, resource_id, *args)
45
+ if args.count > 0
46
+ result = []
47
+ records = @client.send(resource).index({ :id => resource_id }).show.send(args[0]).index
48
+ records.each { |record|
49
+ result.push(record.raw)
50
+ }
51
+ @logger.info("Resource count: #{result.count}.")
52
+ else
53
+ result = @client.send(resource).index({ :id => resource_id }).show.raw
54
+ end
55
+ return result
56
+ end
57
+
38
58
  def create(resource, params)
39
59
  resource = @client.send("#{resource}s").create(resource => params)
40
60
  @logger.info("Created #{resource.href}.")
@@ -46,8 +66,8 @@ class RightScaleCLI
46
66
  @logger.info("Deleted #{resource.href}.")
47
67
  end
48
68
 
49
- def render(data, root_element, options)
50
- RightScaleCLI::Output.render(data, root_element, options)
69
+ def render(data, root_element)
70
+ RightScaleCLI::Output.render(data, root_element, @options)
51
71
  end
52
72
  end
53
73
  end
@@ -21,29 +21,35 @@ require 'right_api_client'
21
21
  class RightScaleCLI
22
22
  class Deployments < Thor
23
23
  namespace :deployments
24
-
24
+
25
+ def initialize(*args)
26
+ super
27
+ @client = RightScaleCLI::Client.new(options)
28
+ @logger = RightScaleCLI::Logger.new()
29
+ end
30
+
31
+ # include render options
32
+ eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
33
+
25
34
  desc "list", "Lists all deployments."
26
35
  def list()
27
- deployments = Array.new
28
- RightApi::Client.new(RightScaleCLI::Config::API).deployments.index.each { |deployment|
29
- deployments.push(deployment.raw)
30
- }
31
- puts deployments.to_yaml
36
+ @client.render(@client.get('deployments'), 'deployments')
32
37
  end
33
38
 
34
39
  desc "create", "Creates a deployment."
35
- def create(name)
36
- rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
37
-
40
+ def create(name, description)
41
+ @client.create('deployment', { :name => name, :description => description })
38
42
  end
39
43
 
40
44
  desc "destroy", "Deletes a deployment."
41
- def destroy(deployment)
42
- rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
43
-
44
- # construct deployment
45
- deployment = Hash.new
46
- rightscale.deployments.delete({:deployment => deployment})
45
+ def destroy(deployment_id)
46
+ @client.destroy('deployment', deployment_id)
47
+ end
48
+
49
+ desc "servers", "Lists servers in a deployment."
50
+ def servers(deployment)
51
+ @logger.info("Retrieving all servers in deployment, #{deployment}...")
52
+ @client.render(@client.show('deployments', deployment, 'servers'), 'servers')
47
53
  end
48
54
 
49
55
  def self.banner(task, namespace = true, subcommand = false)
@@ -26,7 +26,7 @@ class RightScaleCLI
26
26
 
27
27
  def initialize(*args)
28
28
  super
29
- @client = RightScaleCLI::Client.new()
29
+ @client = RightScaleCLI::Client.new(options)
30
30
  @logger = RightScaleCLI::Logger.new()
31
31
  end
32
32
 
@@ -36,9 +36,14 @@ class RightScaleCLI
36
36
  desc "list", "Lists all MultiCloud Images."
37
37
  def list()
38
38
  @logger.info('Retrieving all MultiCloud Images...')
39
- @client.render(@client.get('multi_cloud_images'), 'multi_cloud_images', options)
39
+ @client.render(@client.get('multi_cloud_images'), 'multi_cloud_images')
40
40
  end
41
41
 
42
+ desc "show", "Shows a particular MultiCloud Image."
43
+ def show(multi_cloud_image_id)
44
+ @client.render(@client.show('multi_cloud_images', multi_cloud_image_id), 'multi_cloud_image')
45
+ end
46
+
42
47
  desc "create", "Creates a MultiCloud Image."
43
48
  def create(name, description)
44
49
  @client.create('multi_cloud_image', { :name => name, :description => description })
@@ -26,18 +26,54 @@ require 'rightscale_cli/repositories'
26
26
  require 'rightscale_cli/servers'
27
27
  require 'rightscale_cli/server_arrays'
28
28
  require 'rightscale_cli/server_templates'
29
+ require 'rightscale_cli/tags'
29
30
  require 'rightscale_cli/volumes'
30
31
 
31
32
  # http://stackoverflow.com/questions/5663519/namespacing-thor-commands-in-a-standalone-ruby-executable
32
33
 
33
34
  class RightScaleCLI
34
35
  class Base < Thor
35
- class_option :debug,:type => :boolean, :default => false, :aliases => '-D', :desc => 'Debug mode.'
36
- class_option :verbose, :type => :boolean, :default => false, :aliases => '-V', :desc => 'Verbose output.'
37
- class_option :silent, :type => :boolean, :default => false, :aliases => '-S', :desc => 'Silent mode, do not print any log.'
38
- class_option :non_interactive, :type => :boolean, :default => false, :aliases => '-N', :desc => 'Non-interactive mode.'
39
- class_option :dry, :type => :boolean, :default => false, :desc => 'Dry-run only.'
40
-
36
+ class_option :account,
37
+ :type => :string,
38
+ :aliases => '-a',
39
+ :required => false,
40
+ :desc => 'The RightScale account ID.'
41
+
42
+ class_option :api,
43
+ :type => :string,
44
+ :aliases => '-A',
45
+ :required => false,
46
+ :desc => 'The RightScale API version.'
47
+
48
+ class_option :debug,
49
+ :type => :boolean,
50
+ :default => false,
51
+ :aliases => '-D',
52
+ :desc => 'Debug mode.'
53
+
54
+ class_option :verbose,
55
+ :type => :boolean,
56
+ :default => false,
57
+ :aliases => '-V',
58
+ :desc => 'Verbose output.'
59
+
60
+ class_option :silent,
61
+ :type => :boolean,
62
+ :default => false,
63
+ :aliases => '-S',
64
+ :desc => 'Silent mode, do not print any log.'
65
+
66
+ class_option :non_interactive,
67
+ :type => :boolean,
68
+ :default => false,
69
+ :aliases => '-N',
70
+ :desc => 'Non-interactive mode.'
71
+
72
+ class_option :dry,
73
+ :type => :boolean,
74
+ :default => false,
75
+ :desc => 'Dry-run only.'
76
+
41
77
  register(Clouds, 'clouds', 'clouds <command>', 'Query clouds.')
42
78
  register(Dashboard, 'dashboard', 'dashboard <command>', 'RightScale Dashboard (HTTP hax).')
43
79
  register(ServerArrays, 'arrays', 'arrays <command>', 'Manage server arrays.')
@@ -47,6 +83,7 @@ class RightScaleCLI
47
83
  register(Repositories, 'repositories', 'repositories <command>', 'Manage (Chef) Repositories.')
48
84
  register(Servers, 'servers', 'servers <command>', 'Manage servers.')
49
85
  register(ServerTemplates, 'server_templates', 'server-templates <command>', 'Manage ServerTemplates.')
86
+ register(Tags, 'tags', 'tags <command>', 'Manage tags.')
50
87
  register(Volumes, 'volumes', 'volumes <command>', 'Manage volumes.')
51
88
  end
52
89
  end
@@ -31,6 +31,12 @@ class RightScaleCLI
31
31
  class ServerArrays < Thor
32
32
  namespace :arrays
33
33
 
34
+ def initialize(*args)
35
+ super
36
+ @client = RightScaleCLI::Client.new(options)
37
+ @logger = RightScaleCLI::Logger.new()
38
+ end
39
+
34
40
  # include render options
35
41
  eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
36
42
 
@@ -62,21 +68,11 @@ class RightScaleCLI
62
68
  end
63
69
  end
64
70
 
65
- desc "show", "Shows a server array."
71
+ desc "show", "Shows a particular server array."
66
72
  def show(server_array_id)
67
- rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
68
-
69
- server_array = rightscale.server_arrays(:id => server_array_id).show.raw
70
-
71
- if options[:xml]
72
- puts server_array.to_xml(:root => 'server_array')
73
- elsif options[:json]
74
- puts JSON.pretty_generate(server_array)
75
- else
76
- puts server_array.to_yaml
77
- end
73
+ @client.render(@client.show('server_arrays', server_array_id), 'server_array')
78
74
  end
79
-
75
+
80
76
  desc "state", "Shows the state of a server array."
81
77
  def state(server_array_id)
82
78
  $log.info "Retrieving state for server array, #{server_array_id}."
@@ -113,6 +109,16 @@ class RightScaleCLI
113
109
  puts server_array
114
110
  end
115
111
 
112
+ desc "inputs", 'Update the inputs of the server array.'
113
+ def inputs(server_array_id)
114
+ @client.render(@client.show('server_arrays', server_array_id), 'server_array')
115
+ end
116
+
117
+ desc "next", 'Show the next instance properties of the server array.'
118
+ def next(server_array_id)
119
+ @client.render(@client.client.server_arrays(:id => server_array_id).show.next_instance.index)
120
+ end
121
+
116
122
  def self.banner(task, namespace = true, subcommand = false)
117
123
  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
118
124
  end
@@ -16,34 +16,39 @@
16
16
 
17
17
  require 'thor'
18
18
  require 'yaml'
19
- require 'right_api_client'
19
+ require 'rightscale_cli/client'
20
20
 
21
21
  class RightScaleCLI
22
22
  class Servers < Thor
23
23
  namespace :servers
24
24
 
25
- desc "show", "Lists all servers."
26
- def show()
27
- servers = Array.new
28
- RightApi::Client.new(RightScaleCLI::Config::API).servers.index.each { |deployment|
29
- servers.push(deployment.raw)
30
- }
31
- puts servers.to_yaml
25
+ def initialize(*args)
26
+ super
27
+ @client = RightScaleCLI::Client.new(options)
28
+ @logger = RightScaleCLI::Logger.new()
29
+ end
30
+
31
+ # include render options
32
+ eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
33
+
34
+ desc "list", "Lists all servers."
35
+ def list()
36
+ @client.render(@client.get('servers'), 'servers')
37
+ end
38
+
39
+ desc "show", "Shows a server."
40
+ def show(id)
41
+ @client.render(@client.show('servers', id), 'server')
32
42
  end
33
43
 
34
44
  desc "create", "Creates a server."
35
45
  def create(name)
36
- rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
37
-
46
+ # todo
38
47
  end
39
48
 
40
49
  desc "destroy", "Deletes a server."
41
50
  def destroy(server)
42
- rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
43
-
44
- # construct deployment
45
- server = Hash.new
46
- rightscale.servers.delete({:server => server})
51
+ # todo
47
52
  end
48
53
 
49
54
  def self.banner(task, namespace = true, subcommand = false)
@@ -0,0 +1,60 @@
1
+ # Author:: Chris Fordham (<chris@fordham-nagy.id.au>)
2
+ # Copyright:: Copyright (c) 2013 Chris Fordham
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'thor'
18
+ require 'yaml'
19
+ require 'right_api_client'
20
+ require 'rightscale_cli/client'
21
+ require 'rightscale_cli/logger'
22
+
23
+ class RightScaleCLI
24
+ class Tags < Thor
25
+ namespace :tags
26
+
27
+ def initialize(*args)
28
+ super
29
+ @client = RightScaleCLI::Client.new(options)
30
+ @logger = RightScaleCLI::Logger.new()
31
+ end
32
+
33
+ # include render options
34
+ eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
35
+
36
+ desc "search", "Search for resources having a list of tags in a specific resource_type."
37
+ def search()
38
+ # todo
39
+ end
40
+
41
+ desc "resource", "Get tags for a list of resource hrefs."
42
+ def resource(resource_hrefs)
43
+ @client.client.tags.by_resource(:resource_hrefs => resource_hrefs.split(','))
44
+ end
45
+
46
+ desc "add", "Adds tag(s) to resource(s)."
47
+ def add(hrefs, tags)
48
+ @client.client.tags.multi_add(:resource_hrefs => [hrefs.split(',')], :tags => [tags.split(',')])
49
+ end
50
+
51
+ desc "delete", "Deletes tags from resource(s)."
52
+ def delete(hrefs, tags)
53
+ @client.client.tags.multi_delete(:resource_hrefs => [hrefs.split(',')], :tags => [tags.split(',')])
54
+ end
55
+
56
+ def self.banner(task, namespace = true, subcommand = false)
57
+ "#{basename} #{task.formatted_usage(self, true, subcommand)}"
58
+ end
59
+ end
60
+ end
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  class RightScaleCLI
18
- VERSION = '0.4.0'
18
+ VERSION = '0.4.1'
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightscale-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Fordham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -101,36 +101,36 @@ executables:
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - LICENSE
105
+ - README.md
104
106
  - bin/rs
105
107
  - lib/rightscale_cli.rb
106
- - lib/rightscale_cli/servers.rb
107
- - lib/rightscale_cli/rightscale_cli.rb
108
- - lib/rightscale_cli/repositories.rb
109
- - lib/rightscale_cli/base.rb
110
- - lib/rightscale_cli/monkey_patches/client_attributes.rb
111
- - lib/rightscale_cli/output.rb
112
- - lib/rightscale_cli/instances.rb
113
108
  - lib/rightscale_cli/client.rb
114
- - lib/rightscale_cli/version.rb
115
- - lib/rightscale_cli/server_templates.rb
116
109
  - lib/rightscale_cli/clouds.rb
117
- - lib/rightscale_cli/deployments.rb
118
110
  - lib/rightscale_cli/config.rb
119
111
  - lib/rightscale_cli/dashboard.rb
120
- - lib/rightscale_cli/server_arrays.rb
112
+ - lib/rightscale_cli/deployments.rb
113
+ - lib/rightscale_cli/instances.rb
114
+ - lib/rightscale_cli/logger.rb
115
+ - lib/rightscale_cli/monkey_patches/client_attributes.rb
121
116
  - lib/rightscale_cli/multi_cloud_images.rb
117
+ - lib/rightscale_cli/output.rb
122
118
  - lib/rightscale_cli/render_options.rb
123
- - lib/rightscale_cli/volumes.rb
124
- - lib/rightscale_cli/server_arrays/current_instances.rb
125
- - lib/rightscale_cli/server_arrays/links.rb
126
- - lib/rightscale_cli/server_arrays/elasticity_params.rb
119
+ - lib/rightscale_cli/repositories.rb
120
+ - lib/rightscale_cli/rightscale_cli.rb
121
+ - lib/rightscale_cli/server_arrays.rb
127
122
  - lib/rightscale_cli/server_arrays/alert_specs.rb
128
123
  - lib/rightscale_cli/server_arrays/alerts.rb
124
+ - lib/rightscale_cli/server_arrays/current_instances.rb
125
+ - lib/rightscale_cli/server_arrays/elasticity_params.rb
126
+ - lib/rightscale_cli/server_arrays/links.rb
129
127
  - lib/rightscale_cli/server_arrays/multi_run_executable.rb
130
- - lib/rightscale_cli/logger.rb
128
+ - lib/rightscale_cli/server_templates.rb
129
+ - lib/rightscale_cli/servers.rb
130
+ - lib/rightscale_cli/tags.rb
131
+ - lib/rightscale_cli/version.rb
132
+ - lib/rightscale_cli/volumes.rb
131
133
  - lib/yesno.rb
132
- - README.md
133
- - LICENSE
134
134
  homepage: https://github.com/flaccid/rightscale-cli
135
135
  licenses:
136
136
  - Apache 2.0
@@ -151,8 +151,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 2.1.9
154
+ rubygems_version: 2.2.0
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: rightscale-cli
158
158
  test_files: []
159
+ has_rdoc:
@@ -1,5 +0,0 @@
1
- class RightScaleCLI
2
- class Base
3
-
4
- end
5
- end