rightscale-cli 0.5.2 → 0.5.3

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: cac4bf566926e6c5d1fc28e6d5f9bb8a95f9757f
4
- data.tar.gz: c2a383530d59631460496293bfcfc6dc12ed4dd4
3
+ metadata.gz: 1156a9a906152fa3289a2d566200e0f3c50973ac
4
+ data.tar.gz: eefa246fca31de0429b29abc099eb1b97569570d
5
5
  SHA512:
6
- metadata.gz: ca723891f38355aa870f04fe711f2b3de221133b21b11378b77098d5b3dd77cb4b105355e0d9cfaaaf0db9a60930b498e94a4e2c5c509b2fcc92365e105bc88f
7
- data.tar.gz: 10307926ce934939d79e73d6baa3728689f6f8a553c4975b2916c546cc931c3a27197370500c1f52b232b0bcde75b1bf55fc4ac5582eae7d9688a07a87a96852
6
+ metadata.gz: c4bb172cb85e1ca200369881305106b507807a33a5c88c9afe83d9bdec8719a1c7941530c3bcb108422b905d7d1f550a453255332fde9dda8bcd2561a9eac8e3
7
+ data.tar.gz: 03050c7b7e681593ae161b008860bb065f4599b5e7e1d70b6e1a6731320bf50d9e38643e93def8fe2e7b0d3919a567ea177731b108aa9ec46e2bc4b6f375434e
@@ -25,7 +25,7 @@ class RightScaleCLI
25
25
  attr_accessor :render
26
26
 
27
27
  def initialize(options)
28
- config = RightScaleCLI::Config.new.local
28
+ config = RightScaleCLI::Config.new.directives
29
29
  config[:account_id] = options['account'] if options[:account]
30
30
  config[:email] = options['user'] if options[:user]
31
31
  config[:api_version] = options['api'] if options[:api]
@@ -15,14 +15,34 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require 'yaml'
18
+ require 'fileutils'
18
19
 
19
20
  class RightScaleCLI
20
21
  class Config
21
- attr_accessor :local, :path
22
+ attr_accessor :template_path, :config_home, :config_path, :directives
22
23
 
23
24
  def initialize(*args)
24
- @path = File.join(ENV['HOME'], '.rightscale', 'right_api_client.yml')
25
- @local = YAML.load_file(@path)
25
+ @template_path = File.join(File.dirname(__FILE__), '..', 'templates', 'right_api_client.yml.erb')
26
+ @config_home = File.join(ENV['HOME'], '.rightscale')
27
+ @config_path = File.join(@config_home, 'right_api_client.yml')
28
+
29
+ Dir.mkdir(@config_home) unless File.exists?(@config_home)
30
+ FileUtils.touch(@config_path)
31
+
32
+ # write a fresh file if it does not load/parse
33
+ unless YAML.load_file(@config_path)
34
+ @directives = {
35
+ :account_id => '',
36
+ :email => '',
37
+ :password_base64 => '',
38
+ :api_url => 'https://us-4.rightscale.com',
39
+ :api_version => '1.5'
40
+ }
41
+ File.open(@config_path, 'w') {|f| f.write(ERB.new(IO.read(@template_path)).result(binding)) }
42
+ end
43
+
44
+ # load/reload the directives from the file
45
+ @directives = YAML.load_file(@config_path)
26
46
  end
27
47
  end
28
48
  end
@@ -30,60 +30,53 @@ class RightScaleCLI
30
30
  def initialize(*args)
31
31
  super
32
32
  @logger = RightScaleCLI::Logger.new()
33
- @template_path = File.join(File.dirname(__FILE__), '..', 'templates', '/right_api_client.yml.erb')
34
33
  @config = RightScaleCLI::Config.new
35
- @directives = {}
34
+ @directives = @config.directives
36
35
  end
37
36
 
38
37
  no_commands{
39
- def update_conf(directives)
40
- renderer = ERB.new(IO.read(@template_path))
41
- Dir.mkdir(File.dirname(@config.path)) unless File.exists?(File.dirname(@config.path))
42
- File.open(@config.path, 'w') {|f| f.write(renderer.result(binding)) }
38
+ def update_conf()
39
+ File.open(@config.config_path, 'w') {|f| f.write(ERB.new(IO.read(@config.template_path)).result(binding)) }
43
40
  end
44
41
  }
45
42
 
46
43
  desc "account", "Configure the RightScale account ID for the client."
47
44
  def account()
48
- update_conf(@config.local.merge({:account_id => ask("RightScale account ID (e.g. 1337):")}))
45
+ @directives.merge!( { :account_id => ask("RightScale account ID (e.g. 1337):")})
46
+ update_conf
49
47
  end
50
48
 
51
49
  desc "user", "Configure the RightScale user for the client."
52
50
  def user()
53
- update_conf(@config.local.merge({:email => ask("RightScale username (e.g. bill.gates@microsoft.com):")}))
51
+ @directives.merge!( { :email => ask("RightScale username (e.g. bill.gates@microsoft.com):") })
52
+ update_conf
54
53
  end
55
54
 
56
55
  desc "password", "Configure the RightScale user password for the client."
57
56
  def password()
58
- update_conf(@config.local.merge({:password_base64 => Base64.encode64(ask_pass).strip}))
57
+ @directives.merge!( { :password_base64 => Base64.encode64(ask_pass).strip })
58
+ update_conf
59
59
  end
60
60
 
61
61
  desc "api", "Configure the RightScale API version used by the client."
62
62
  def api()
63
- update_conf(@config.local.merge({:api_version => ask("RightScale API version (e.g. 1.5):")}))
63
+ @directives.merge!( { :api_version => ask("RightScale API version (e.g. 1.5):") })
64
+ update_conf
64
65
  end
65
66
 
66
67
  desc "shard", "Configure the RightScale shard used by the client."
67
68
  def shard()
68
- update_conf(@config.local.merge({:api_url => "https://#{ask("RightScale shard (e.g. us-4.rightscale.com):")}"}))
69
+ @directives.merge!( { :api_url => "https://#{ask("RightScale shard (e.g. us-4.rightscale.com):")}" })
70
+ update_conf
69
71
  end
70
72
 
71
73
  desc "show", "Print the current configuration from ~/.rightscale/right_api_client.yml."
72
74
  def show()
73
- puts @config.local
75
+ puts @directives
74
76
  end
75
77
 
76
78
  desc "all", "Configure RightScale CLI."
77
79
  def all()
78
- # directives = {
79
- # :account_id => account(),
80
- # :email => user(),
81
- # :password_base64 => Base64.encode64(ask_pass).strip,
82
- # :api_url => shard(),
83
- # :api_version => api()
84
- # }
85
- # @logger.debug(directives)
86
-
87
80
  # currently this is the lazy way, each is written sequentially
88
81
  account
89
82
  user
@@ -57,10 +57,11 @@ class RightScaleCLI
57
57
  def terminate(deployment)
58
58
  @client.show('deployments', deployment, 'servers').each { |server|
59
59
  unless server['state'] == 'inactive'
60
- current_instance = server['links'].select { |link| link['rel'] == 'current_instance' }.first['href']
61
- cloud = current_instance.split('/')[3]
62
- instance_id = current_instance.split('/').last
63
- @client.client.clouds(:id => cloud).show.instances(:id => instance_id).terminate
60
+ server.terminate
61
+ #current_instance = server['links'].select { |link| link['rel'] == 'current_instance' }.first['href']
62
+ #cloud = current_instance.split('/')[3]
63
+ #instance_id = current_instance.split('/').last
64
+ #@client.client.clouds(:id => cloud).show.instances(:id => instance_id).terminate
64
65
  end
65
66
  }
66
67
  end
@@ -15,5 +15,5 @@
15
15
  # limitations under the License.
16
16
 
17
17
  class RightScaleCLI
18
- VERSION = '0.5.2'
18
+ VERSION = '0.5.3'
19
19
  end
@@ -4,17 +4,17 @@
4
4
  # Account ID is a required parameter. You can find your account number by logging into the
5
5
  # RightScale dashboard (https://my.rightscale.com), navigate to the Settings > Account Settings page.
6
6
  # The account number is at the end of the browser address bar.
7
- :account_id: <%= directives[:account_id] %>
7
+ :account_id: <%= @directives[:account_id] %>
8
8
 
9
9
  # There are five login mechanisms:
10
10
 
11
11
  # 0. Use the following parameters to login with your email and base64-encoded password:
12
12
  # To encode your plaintext password, use 'base64' command or similar.
13
- :email: <%= directives[:email] %>
14
- :password_base64: <%= directives[:password_base64] %>
13
+ :email: <%= @directives[:email] %>
14
+ :password_base64: <%= @directives[:password_base64] %>
15
15
 
16
16
  # 1. Use the following parameters to login with your email and plaintext password:
17
- #:email: <%= directives[:email] %>
17
+ #:email: <%= @directives[:email] %>
18
18
  #:password: my_password
19
19
 
20
20
  # 2. Use the following parameter to login with an instance_token:
@@ -31,5 +31,5 @@
31
31
  #:access_token: my_token_string
32
32
 
33
33
  # The following are optional parameters:
34
- :api_url: <%= directives[:api_url] %>
35
- :api_version: <%= directives[:api_version] %>
34
+ :api_url: <%= @directives[:api_url] %>
35
+ :api_version: <%= @directives[:api_version] %>
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.5.2
4
+ version: 0.5.3
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-02-17 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport