rightresource 0.1.9 → 0.2.0

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.
@@ -1,6 +1,11 @@
1
1
  module RightResource
2
2
  class Base
3
3
  class << self # Define singleton methods
4
+ # Set Logger object
5
+ # === Examples
6
+ # logger = Logger.new(STDERR)
7
+ # logger.level = Logger::WARN [Default: Logger::DEBUG]
8
+ # Server.logger = logger
4
9
  def logger=(logger)
5
10
  @logger = logger
6
11
  end
@@ -81,6 +86,9 @@ module RightResource
81
86
  # Server.index.each do |server|
82
87
  # puts server.nickname if server.state = "operational"
83
88
  # end
89
+ #
90
+ # Get EC2 Security Groups(aws ap = 4)
91
+ # sec_grps = Ec2SecurityGroup.index(:cloud_id => "4")
84
92
  def index(params = {})
85
93
  path = "#{resource_name}s.#{format.extension}#{query_string(params)}"
86
94
  connection.clear
@@ -237,8 +245,7 @@ module RightResource
237
245
  end
238
246
  yield self if block_given?
239
247
  end
240
- attr_accessor :id
241
- attr_reader :attributes
248
+ attr_accessor :id, :attributes
242
249
 
243
250
  def loads(attributes)
244
251
  raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
@@ -295,11 +302,9 @@ module RightResource
295
302
  def create
296
303
  #TODO: refactor hard coding
297
304
  attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
298
- puts attrs.pretty_inspect
299
305
  pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
300
306
  headers = Hash[*pair.flatten]
301
307
  headers["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
302
- puts headers.pretty_inspect
303
308
  connection.post(collection_path, headers)
304
309
  self.id = self.class.resource_id
305
310
  end
@@ -1,7 +1,6 @@
1
1
  module RightResource
2
2
  class Connection
3
3
  @reraise = false
4
- RestClient.log = STDERR
5
4
 
6
5
  attr_accessor :api_version, :log, :api, :format, :username, :password, :account, :reraise
7
6
  attr_reader :headers, :resource_id, :response, :status
@@ -12,9 +11,15 @@ module RightResource
12
11
  @api = "https://my.rightscale.com/api/acct/"
13
12
  @format = params[:format] || RightResource::Formats::JsonFormat
14
13
  @logger = params[:logger] || Logger.new(STDERR)
14
+ RestClient.log = STDERR if @logger.level == Logger::DEBUG # HTTP request/response log
15
15
  yield self if block_given? # RightResource::Connection.new {|conn| ...}
16
16
  end
17
17
 
18
+ # RestClient authentication
19
+ # === Examples
20
+ # params = {:username => "foo", :password => "bar", :account => "1"}
21
+ # conn = Connection.new
22
+ # conn.login(params)
18
23
  def login(params={})
19
24
  @username = params[:username] unless params[:username].nil? || params[:username].empty?
20
25
  @password = params[:password] unless params[:password].nil? || params[:password].empty?
@@ -32,6 +37,7 @@ module RightResource
32
37
  @api_object ? true : false
33
38
  end
34
39
 
40
+ # Send HTTP Request
35
41
  def request(path, method="get", headers={})
36
42
  raise "Not Login!!" unless self.login?
37
43
  # if /(.xml|.js)/ =~ path
@@ -79,6 +85,8 @@ module RightResource
79
85
 
80
86
  # update
81
87
  def put(path, headers={})
88
+ puts path.pretty_inspect
89
+ puts headers.pretty_inspect
82
90
  self.request(path, "put", headers)
83
91
  end
84
92
 
@@ -1,11 +1 @@
1
- class Ec2SecurityGroup < RightResource::Base
2
- class << self
3
- def index(id)
4
- raise NotImplementedError
5
- end
6
-
7
- def update(id)
8
- raise NotImplementedError
9
- end
10
- end
11
- end
1
+ class Ec2SecurityGroup < RightResource::Base; end
@@ -1,14 +1,21 @@
1
1
  class Server < RightResource::Base
2
2
  class << self
3
+ #TODO: refactor define_method or method_missing
3
4
  def action; end
5
+ # server start(Starting created instance)
6
+ # === Examples
7
+ # server_id = Server.index(:filter => "nickname=dev001").first.id
8
+ # Server.start(server_id)
4
9
  def start(id)
5
10
  connection.post(element_path(id, :start))
6
11
  end
7
12
 
13
+ # server stop(Starting created instance)
8
14
  def stop(id)
9
15
  connection.post(element_path(id, :stop))
10
16
  end
11
17
 
18
+ # server restart(Starting created instance)
12
19
  def reboot(id)
13
20
  connection.post(element_path(id, :reboot))
14
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rightresource
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 9
10
- version: 0.1.9
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Satoshi Ohki