Class: Capistrano::RightScale::Resource
- Inherits:
-
Object
- Object
- Capistrano::RightScale::Resource
- Includes:
- Singleton
- Defined in:
- lib/cap-rightscale/configuration/rightscale/resource.rb
Instance Attribute Summary collapse
-
#array(id) ⇒ Object
readonly
Returns the value of attribute array.
-
#array_instances(id) ⇒ Object
readonly
Returns the value of attribute array_instances.
-
#confpath ⇒ Object
Returns the value of attribute confpath.
-
#deployment(id, params) ⇒ Object
readonly
Returns the value of attribute deployment.
-
#logger ⇒ Object
writeonly
Sets the attribute logger.
Instance Method Summary collapse
- #_instance_variable_set(method, id, api) ⇒ Object
- #connect ⇒ Object
-
#initialize ⇒ Resource
constructor
A new instance of Resource.
- #tag(params) ⇒ Object
Constructor Details
#initialize ⇒ Resource
Returns a new instance of Resource.
10 11 12 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 10 def initialize @confpath = Capistrano::RightScale::RS_DEFAULT_CONFPATH end |
Instance Attribute Details
#array(id) ⇒ Object (readonly)
Returns the value of attribute array.
9 10 11 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 9 def array @array end |
#array_instances(id) ⇒ Object (readonly)
Returns the value of attribute array_instances.
9 10 11 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 9 def array_instances @array_instances end |
#confpath ⇒ Object
Returns the value of attribute confpath.
8 9 10 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 8 def confpath @confpath end |
#deployment(id, params) ⇒ Object (readonly)
Returns the value of attribute deployment.
9 10 11 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 9 def deployment @deployment end |
#logger=(value) ⇒ Object
Sets the attribute logger
8 9 10 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 8 def logger=(value) @logger = value end |
Instance Method Details
#_instance_variable_set(method, id, api) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 39 def _instance_variable_set(method, id, api) connect begin self.instance_variable_set("@#{method}_#{id}", api.call) rescue => e @logger.important("#{e.class}: #{e.pretty_inspect}") @logger.trace("Backtrace:\n#{e.backtrace.pretty_inspect}") exit(1) end status_code = RightResource::Base.status_code if status_code.nil? @logger.important("Error: Unknown Error when accessing RightScale API") exit(1) elsif status_code != 200 @logger.important("Errors: HTTP STATUS CODE is #{status_code}") @logger.trace(RightResource::Base.headers) exit(1) end data = self.instance_variable_get("@#{method}_#{id}") data end |
#connect ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 14 def connect begin @auth ||= open(confpath) {|f| YAML.load(f) } @conn ||= RightResource::Connection.new do |c| c.login(:username => @auth["username"], :password => @auth["password"], :account => @auth["account"]) end rescue => e auth_data = open(File.join(File.( File.dirname(__FILE__)), '/../../../../rsapiconfig.yml.sample')) {|f| f.read } @logger.important <<-"USAGE" Cannot load RightScale API credentials!!: Put authfile:<rsapiconfig.yml> in <HOME>/.rsconf/ OR Define param<set_rs_confpath> in Capfile: # Load RightScale API credentials set :set_rs_confpath, <authfile_path> Authfile contents: specify your Rightscale API credentials #{auth_data} USAGE exit(1) end RightResource::Base.connection = @conn end |
#tag(params) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cap-rightscale/configuration/rightscale/resource.rb', line 81 def tag(params) begin = Tag.search(params) # not stored rescue => e @logger.important("#{e.class}: #{e.pretty_inspect}") @logger.trace("Backtrace:\n#{e.backtrace.pretty_inspect}") exit(1) end status_code = Tag.status_code if status_code.nil? @logger.important("Error: Unknown Error when accessing RightScale API") exit(1) elsif status_code != 200 @logger.important("Errors: HTTP STATUS CODE is #{status_code}") @logger.trace(Tag.headers) exit(1) end end |