rightscale-cli 0.1.0 → 0.1.1

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: 19fc3aa02344fa7e82a36cf2ad02d221587ad2a2
4
- data.tar.gz: 76047cc9efa98f62ec6a9d6097cc67d207da3cb9
3
+ metadata.gz: b9f392d4242167db76694675551a365d026cb066
4
+ data.tar.gz: 651df9b631bfbc4c5c75bb2f7839e9cff6075dfc
5
5
  SHA512:
6
- metadata.gz: 5344b6b7da3f508a58dbeb3d9b798f6276fceef38f64f571b9b57fdb7ab327a1b91c1361ebd69260fa90dade453d4d0c5f926eac7a30e43c60ef517cd981344b
7
- data.tar.gz: edd3728b2cfc6892116ef2adc8bf8e60dca14499c915adff7d6c40151640b2b521d45867943e5c5f67fabb77a58335126c0daa287e7b38f7ec3b8cd214142684
6
+ metadata.gz: 1f12aa5f64660219a8bebec31319d9a18fe78f0ee6ed9b831c09c25f9ba3c57bd21ddc23b3e4b11d87b044a907c49229c11da294f7ddad59d29a1f61a9045499
7
+ data.tar.gz: 5d1e9b6f60a8442794c0b2875c35e2a824dbdd2eab51c5042e2c0e2e25416c58e6988c2f48d442ac393d09f5c6933017d83228950072dac96c798213778779b5
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ rightscale-cli
2
+ ==============
3
+
4
+ RightScale CLI client. Currently in early development stages.
@@ -0,0 +1,18 @@
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 'rightscale_cli/config'
18
+ require 'right_api_client'
@@ -0,0 +1,72 @@
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 'json'
20
+ require "active_support/core_ext"
21
+ require 'rightscale_cli/logger'
22
+
23
+ class RightScaleCLI
24
+ class Clouds < Thor
25
+ namespace :clouds
26
+
27
+ desc "list", "Lists all clouds."
28
+ def list()
29
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
30
+ clouds = []
31
+ rightscale.clouds.index.each { |cloud|
32
+ clouds.push(cloud.raw)
33
+ }
34
+ puts clouds.to_yaml
35
+ end
36
+
37
+ desc "show", "Shows a cloud."
38
+ def show(cloud_id)
39
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
40
+ cloud = rightscale.clouds(:id => cloud_id).show.raw
41
+ puts cloud.to_yaml
42
+ end
43
+
44
+ desc "search", "Searches for clouds by cloud type, name, description."
45
+ option :name, :type => :string, :required => false
46
+ option :cloud_type, :type => :string, :required => false
47
+ option :description, :type => :string, :required => false
48
+ def search()
49
+ log = CLILogger.new
50
+
51
+ filter = []
52
+ filter.push("name==#{options[:name]}") if options[:name]
53
+ filter.push("cloud_type==#{options[:cloud_type]}") if options[:cloud_type]
54
+ filter.push("description==#{options[:cloud]}") if options[:description]
55
+
56
+ log.info("Searching for clouds!")
57
+
58
+ puts "filter: #{filter}" if options[:debug]
59
+
60
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
61
+ clouds = []
62
+ rightscale.clouds.index(:filter => filter).each { |cloud|
63
+ clouds.push(cloud.raw)
64
+ }
65
+ puts clouds.to_yaml
66
+ end
67
+
68
+ def self.banner(task, namespace = true, subcommand = false)
69
+ "#{basename} #{task.formatted_usage(self, true, subcommand)}"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,23 @@
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 'yaml'
18
+
19
+ class RightScaleCLI
20
+ class Config
21
+ API = YAML.load_file(File.join(ENV['HOME'], '.rightscale', 'right_api_client.yml'))
22
+ end
23
+ end
@@ -0,0 +1,55 @@
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
+
21
+ class RightScaleCLI
22
+ class Deployments < Thor
23
+ namespace :deployments
24
+
25
+ desc "show", "Lists all deployments."
26
+ def show()
27
+ option :xml, :type => :boolean, :default => false, :aliases => '-X', :desc => 'Return XML.'
28
+
29
+ deployments = Array.new
30
+ RightApi::Client.new(RightScaleCLI::Config::API).deployments.index.each { |deployment|
31
+ deployments.push(deployment.raw)
32
+ }
33
+ puts deployments.to_yaml
34
+ end
35
+
36
+ desc "create", "Creates a deployment."
37
+ def create(name)
38
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
39
+
40
+ end
41
+
42
+ desc "destroy", "Deletes a deployment."
43
+ def destroy(deployment)
44
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
45
+
46
+ # construct deployment
47
+ deployment = Hash.new
48
+ rightscale.deployments.delete({:deployment => deployment})
49
+ end
50
+
51
+ def self.banner(task, namespace = true, subcommand = false)
52
+ "#{basename} #{task.formatted_usage(self, true, subcommand)}"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,139 @@
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 'logger'
18
+
19
+ class RightScaleCLI
20
+ # A Logger instance that gives better control of messaging the user
21
+ # and logging app activity. At it's most basic, you would use <tt>info</tt>
22
+ # as a replacement for +puts+ and <tt>error</tt> as a replacement
23
+ # for <tt>STDERR.puts</tt>. Since this is a logger, however, you
24
+ # can also use #debug, #warn, and #fatal, and you can control
25
+ # the format and "logging level" as such.
26
+ #
27
+ # So, by default:
28
+ # * debug messages do not appear anywhere
29
+ # * info messages appear on the standard output
30
+ # * warn, error, and fatal messagse appear on the standard error
31
+ # * The default format of messages is simply the message, no logging cruft, however if your output
32
+ # is redirected to a file, a better timestamped logging format is used
33
+ #
34
+ # You can customize this in several ways:
35
+ #
36
+ # * You can override the devices used by passing different devices to the constructor
37
+ # * You can adjust the level of message that goes to the error logger via error_level=
38
+ # * You can adjust the format for messages to the error logger separately via error_formatter=
39
+ #
40
+ # === Example
41
+ #
42
+ # logger = CLILogger.new
43
+ # logger.debug("Starting up") # => only the standard output gets this
44
+ # logger.warn("careful!") # => only the standard error gets this
45
+ # logger.error("Something went wrong!") # => only the standard error gets this
46
+ #
47
+ # logger = CLILogger.new
48
+ # logger.error_level = Logger::ERROR
49
+ # logger.debug("Starting up") # => only the standard output gets this
50
+ # logger.warn("careful!") # => only the standard OUTPUT gets this
51
+ # logger.error("Something went wrong!") # => only the standard error gets this
52
+ #
53
+ # logger = CLILogger.new('logfile.txt')
54
+ # logger.debug("Starting up") # => logfile.txt gets this
55
+ # logger.error("Something went wrong!") # => BOTH logfile.txt AND the standard error get this
56
+ class CLILogger < Logger
57
+ BLANK_FORMAT = proc { |severity,datetime,progname,msg|
58
+ msg + "\n"
59
+ }
60
+
61
+ # Helper to proxy methods to the super class AND to the internal error logger
62
+ #
63
+ # +symbol+:: Symbol for name of the method to proxy
64
+ def self.proxy_method(symbol) #:nodoc:
65
+ old_name = "old_#{symbol}".to_sym
66
+ alias_method old_name,symbol
67
+ define_method symbol do |*args,&block|
68
+ send(old_name,*args,&block)
69
+ @stderr_logger.send(symbol,*args,&block)
70
+ end
71
+ end
72
+
73
+ proxy_method :'formatter='
74
+ proxy_method :'datetime_format='
75
+
76
+ def add(severity, message = nil, progname = nil, &block) #:nodoc:
77
+ if @split_logs
78
+ unless severity >= @stderr_logger.level
79
+ super(severity,message,progname,&block)
80
+ end
81
+ else
82
+ super(severity,message,progname,&block)
83
+ end
84
+ @stderr_logger.add(severity,message,progname,&block)
85
+ end
86
+
87
+ DEFAULT_ERROR_LEVEL = Logger::Severity::WARN
88
+
89
+ # A logger that logs error-type messages to a second device; useful
90
+ # for ensuring that error messages go to standard error. This should be
91
+ # pretty smart about doing the right thing. If both log devices are
92
+ # ttys, e.g. one is going to standard error and the other to the standard output,
93
+ # messages only appear once in the overall output stream. In other words,
94
+ # an ERROR logged will show up *only* in the standard error. If either
95
+ # log device is NOT a tty, then all messages go to +log_device+ and only
96
+ # errors go to +error_device+
97
+ #
98
+ # +log_device+:: device where all log messages should go, based on level
99
+ # +error_device+:: device where all error messages should go. By default, this is Logger::Severity::WARN
100
+ def initialize(log_device=$stdout,error_device=$stderr)
101
+ super(log_device)
102
+ @stderr_logger = Logger.new(error_device)
103
+
104
+ @split_logs = log_device.tty? && error_device.tty?
105
+
106
+ self.level = Logger::Severity::INFO
107
+ @stderr_logger.level = DEFAULT_ERROR_LEVEL
108
+
109
+ self.formatter = BLANK_FORMAT if log_device.tty?
110
+ @stderr_logger.formatter = BLANK_FORMAT if error_device.tty?
111
+ end
112
+
113
+ def level=(level)
114
+ super(level)
115
+ current_error_level = @stderr_logger.level
116
+ if (level > DEFAULT_ERROR_LEVEL) && @split_logs
117
+ @stderr_logger.level = level
118
+ end
119
+ end
120
+
121
+ # Set the threshold for what messages go to the error device. Note that calling
122
+ # #level= will *not* affect the error logger *unless* both devices are TTYs.
123
+ #
124
+ # +level+:: a constant from Logger::Severity for the level of messages that should go
125
+ # to the error logger
126
+ def error_level=(level)
127
+ @stderr_logger.level = level
128
+ end
129
+
130
+ # Overrides the formatter for the error logger. A future call to #formatter= will
131
+ # affect both, so the order of the calls matters.
132
+ #
133
+ # +formatter+:: Proc that handles the formatting, the same as for #formatter=
134
+ def error_formatter=(formatter)
135
+ @stderr_logger.formatter=formatter
136
+ end
137
+
138
+ end
139
+ end
@@ -0,0 +1,21 @@
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
+ module RightApi
18
+ class Client
19
+ attr_reader :api_version, :api_url, :account_id
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ class_option :xml, :type => :boolean, :default => false, :aliases => '-X', :required => false, :desc => 'Returns XML.'
2
+ class_option :json, :type => :boolean, :default => false, :aliases => '-J', :required => false, :desc => 'Returns JSON.'
@@ -0,0 +1,38 @@
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 'rightscale_cli/clouds'
19
+ require 'rightscale_cli/deployments'
20
+ require 'rightscale_cli/servers'
21
+ require 'rightscale_cli/server_arrays'
22
+
23
+ # http://stackoverflow.com/questions/5663519/namespacing-thor-commands-in-a-standalone-ruby-executable
24
+
25
+ class RightScaleCLI
26
+ class Base < Thor
27
+ class_option :debug,:type => :boolean, :default => false, :aliases => '-D', :desc => 'Debug mode.'
28
+ class_option :verbose, :type => :boolean, :default => false, :aliases => '-V', :desc => 'Verbose output.'
29
+ class_option :silent, :type => :boolean, :default => false, :aliases => '-S', :desc => 'Silent mode, do not print any log.'
30
+ class_option :non_interactive, :type => :boolean, :default => false, :aliases => '-N', :desc => 'Non-interactive mode.'
31
+ class_option :dry, :type => :boolean, :default => false, :desc => 'Dry-run only.'
32
+
33
+ register(Clouds, 'clouds', 'clouds <command>', 'Query clouds.')
34
+ register(ServerArrays, 'arrays', 'arrays <command>', 'Manage server arrays.')
35
+ register(Deployments, 'deployments', 'deployments <command>', 'Manage deployments.')
36
+ register(Servers, 'servers', 'servers <command>', 'Manage servers.')
37
+ end
38
+ end
@@ -0,0 +1,127 @@
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 'json'
20
+ require "active_support/core_ext"
21
+ require 'rightscale_cli/logger'
22
+ require 'rightscale_cli/client'
23
+ require 'rightscale_cli/server_arrays/alerts'
24
+ require 'rightscale_cli/server_arrays/alert_specs'
25
+ require 'rightscale_cli/server_arrays/current_instances'
26
+ require 'rightscale_cli/server_arrays/elasticity_params'
27
+ require 'rightscale_cli/server_arrays/links'
28
+ require 'rightscale_cli/server_arrays/multi_run_executable'
29
+
30
+ class RightScaleCLI
31
+ class ServerArrays < Thor
32
+ namespace :arrays
33
+
34
+ # include render options
35
+ eval(IO.read("#{File.dirname(File.expand_path(__FILE__))}/render_options.rb"), binding)
36
+
37
+ desc "list", "Lists server arrays, optionally with filter by cloud, deployment, name."
38
+ option :cloud, :type => :string, :required => false
39
+ option :deployment, :type => :string, :required => false
40
+ option :name, :type => :string, :required => false
41
+ def list()
42
+ log = CLILogger.new
43
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
44
+
45
+ filter = []
46
+ filter.push("cloud_href==/api/clouds/#{options[:cloud]}") if options[:cloud]
47
+ filter.push("deployment_href==/api/deployments/#{options[:cloud]}") if options[:deployment]
48
+ filter.push("name==#{options[:name]}") if options[:name]
49
+
50
+ log.info "filter: #{filter}" if options[:debug]
51
+
52
+ server_arrays = []
53
+ rightscale.server_arrays.index(:filter => filter).each { |server_array|
54
+ server_arrays.push(server_array.raw)
55
+ }
56
+
57
+ if options[:xml]
58
+ puts server_arrays.to_xml(:root => 'server_arrays')
59
+ elsif options[:json]
60
+ puts JSON.pretty_generate(server_arrays)
61
+ else
62
+ puts server_arrays.to_yaml
63
+ end
64
+ end
65
+
66
+ desc "show", "Shows a server array."
67
+ def show(server_array_id)
68
+ log = CLILogger.new
69
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
70
+
71
+ server_array = rightscale.server_arrays(:id => server_array_id).show.raw
72
+
73
+ if options[:xml]
74
+ puts server_array.to_xml(:root => 'server_array')
75
+ elsif options[:json]
76
+ puts JSON.pretty_generate(server_array)
77
+ else
78
+ puts server_array.to_yaml
79
+ end
80
+ end
81
+
82
+ desc "state", "Shows the state of a server array."
83
+ def state(server_array_id)
84
+ log = CLILogger.new
85
+ log.info "Retrieving state for server array, #{server_array_id}."
86
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
87
+ puts rightscale.server_arrays(:id => server_array_id).show.state
88
+ end
89
+
90
+ desc "instances_count", "Shows the instances count of a server array."
91
+ def instances_count(server_array_id)
92
+ log = CLILogger.new
93
+ log.info "Retrieving instances count for server array, #{server_array_id}."
94
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
95
+ puts rightscale.server_arrays(:id => server_array_id).show.instances_count
96
+ end
97
+
98
+ desc "desc", "Shows the description of a server array."
99
+ def desc(server_array_id)
100
+ log = CLILogger.new
101
+ log.info "Retrieving description for server array, #{server_array_id}."
102
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
103
+ puts rightscale.server_arrays(:id => server_array_id).show.description
104
+ end
105
+
106
+ desc "name", "Shows the name of a server array."
107
+ def name(server_array_id)
108
+ log = CLILogger.new
109
+ log.info "Retrieving name for server array, #{server_array_id}."
110
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
111
+ puts rightscale.server_arrays(:id => server_array_id).show.name
112
+ end
113
+
114
+ desc "api_methods", "Lists the API methods available to a server array."
115
+ def api_methods(server_array_id)
116
+ log = CLILogger.new
117
+ log.info "Retrieving API methods for server array, #{server_array_id}."
118
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
119
+ server_array = rightscale.server_arrays(:id => server_array_id).show.api_methods
120
+ puts server_array
121
+ end
122
+
123
+ def self.banner(task, namespace = true, subcommand = false)
124
+ "#{basename} #{task.formatted_usage(self, true, subcommand)}"
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,39 @@
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
+ class RightScaleCLI
18
+ class ServerArrays < Thor
19
+
20
+ desc "alert_specs", "Shows a server array's alert specifications."
21
+
22
+ def alert_specs(server_array_id)
23
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
24
+
25
+ alert_specs = []
26
+ rightscale.server_arrays(:id => server_array_id).show.alert_specs.index.each { |alert_spec|
27
+ alert_specs.push(alert_spec.raw)
28
+ }
29
+
30
+ if options[:xml]
31
+ puts alert_specs.to_xml(:root => 'alert_specs')
32
+ elsif options[:json]
33
+ puts JSON.pretty_generate(alert_specs)
34
+ else
35
+ puts alert_specs.to_yaml
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
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
+ class RightScaleCLI
18
+ class ServerArrays < Thor
19
+
20
+ desc "alerts", "Shows a server array's active alerts."
21
+
22
+ def alerts(server_array_id)
23
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
24
+
25
+ array_alerts = rightscale.server_arrays(:id => server_array_id).show.alerts.index
26
+
27
+ if options[:xml]
28
+ puts array_alerts.to_xml(:root => 'alerts')
29
+ elsif options[:json]
30
+ puts JSON.pretty_generate(array_alerts)
31
+ else
32
+ puts array_alerts.to_yaml
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
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
+ class RightScaleCLI
18
+ class ServerArrays < Thor
19
+
20
+ desc "instances", "Shows a server array's current instances."
21
+
22
+ def instances(server_array_id)
23
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
24
+
25
+ array_instances = rightscale.server_arrays(:id => server_array_id).show.current_instances.index
26
+
27
+ if options[:xml]
28
+ puts current_instances.to_xml(:root => 'array_instances')
29
+ elsif options[:json]
30
+ puts JSON.pretty_generate(array_instances)
31
+ else
32
+ puts array_instances.to_yaml
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
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
+ class RightScaleCLI
18
+ class ServerArrays < Thor
19
+
20
+ desc "params", "Lists the elasticity parameters for a server array."
21
+
22
+ def params(server_array_id)
23
+ log = CLILogger.new
24
+ log.info "Retrieving elasticity parameters for server array, #{server_array_id}."
25
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
26
+ puts rightscale.server_arrays(:id => server_array_id).show.elasticity_params.to_yaml
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
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
+ class RightScaleCLI
18
+ class ServerArrays < Thor
19
+
20
+ desc "links", "Lists the links for a server array."
21
+
22
+ def links(server_array_id)
23
+ log = CLILogger.new
24
+ log.info "Retrieving links for server array, #{server_array_id}."
25
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
26
+ puts rightscale.server_arrays(:id => server_array_id).show.links.to_yaml
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
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
+ class RightScaleCLI
18
+ class ServerArrays < Thor
19
+
20
+ desc "run_exec", "Runs a RightScript or Chef recipe on the array instances."
21
+
22
+ def run_exec(server_array_id, exec_type, exec_identifier)
23
+ log = CLILogger.new
24
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
25
+
26
+ params = {}
27
+
28
+ if exec_type == 'recipe'
29
+ params['recipe_name'] = exec_identifier
30
+ elsif exec_type == 'rightscript'
31
+ params['right_script_href'] = "/api/right_scripts/#{exec_identifier}"
32
+ end
33
+
34
+ server_array = rightscale.server_arrays(:id => server_array_id)
35
+
36
+ log.info "params: #{params}" if options[:debug]
37
+ log.info "Running executable on server array."
38
+
39
+ server_array.multi_run_executable(params)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,53 @@
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
+
21
+ class RightScaleCLI
22
+ class Servers < Thor
23
+ namespace :servers
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
32
+ end
33
+
34
+ desc "create", "Creates a server."
35
+ def create(name)
36
+ rightscale = RightApi::Client.new(RightScaleCLI::Config::API)
37
+
38
+ end
39
+
40
+ desc "destroy", "Deletes a server."
41
+ 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})
47
+ end
48
+
49
+ def self.banner(task, namespace = true, subcommand = false)
50
+ "#{basename} #{task.formatted_usage(self, true, subcommand)}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
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
+ class RightScaleCLI
18
+ VERSION = '0.1.0'
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightscale-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Fordham
@@ -87,8 +87,27 @@ executables:
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - lib/rightscale_cli.rb
91
90
  - bin/rs
91
+ - lib/rightscale_cli.rb
92
+ - lib/rightscale_cli/servers.rb
93
+ - lib/rightscale_cli/rightscale_cli.rb
94
+ - lib/rightscale_cli/monkey_patches/client_attributes.rb
95
+ - lib/rightscale_cli/client.rb
96
+ - lib/rightscale_cli/version.rb
97
+ - lib/rightscale_cli/clouds.rb
98
+ - lib/rightscale_cli/deployments.rb
99
+ - lib/rightscale_cli/config.rb
100
+ - lib/rightscale_cli/server_arrays.rb
101
+ - lib/rightscale_cli/render_options.rb
102
+ - lib/rightscale_cli/server_arrays/current_instances.rb
103
+ - lib/rightscale_cli/server_arrays/links.rb
104
+ - lib/rightscale_cli/server_arrays/elasticity_params.rb
105
+ - lib/rightscale_cli/server_arrays/alert_specs.rb
106
+ - lib/rightscale_cli/server_arrays/alerts.rb
107
+ - lib/rightscale_cli/server_arrays/multi_run_executable.rb
108
+ - lib/rightscale_cli/logger.rb
109
+ - README.md
110
+ - LICENSE
92
111
  homepage: https://github.com/flaccid/rightscale-cli
93
112
  licenses:
94
113
  - Apache 2.0