right-scale-api 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  *~
4
4
  .DS_Store
5
5
  pkg/*
6
+ *.gem
data/Rakefile CHANGED
@@ -2,42 +2,24 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "right-scale-api"
8
- gem.summary = %Q{A RightScale API gem that doesn't suck.(mostly)}
9
- gem.description = %Q{A client for the RightScale API that hides some of the complexity of the API
10
- (It doesn't require passing around hrefs as much). Based on HTTParty
11
- }
12
- gem.email = "ndh@baroquebobcat.com"
13
- gem.homepage = "http://github.com/baroquebobcat/right-scale-api"
14
- gem.authors = ["Nick Howard"]
15
- gem.add_dependency "httparty", "~> 0.6.0"
16
- gem.add_dependency "activesupport"
17
- gem.add_development_dependency "rspec", ">= 1.2.9"
18
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
5
+ require 'spec/rake/spectask'
6
+ Spec::Rake::SpecTask.new(:spec) do |spec|
7
+ spec.libs << 'lib' << 'spec'
8
+ spec.spec_files = FileList['spec/**/*_spec.rb']
19
9
  end
20
- Jeweler::GemcutterTasks.new
21
- rescue LoadError
22
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
- end
24
10
 
25
- require 'spec/rake/spectask'
26
- Spec::Rake::SpecTask.new(:spec) do |spec|
27
- spec.libs << 'lib' << 'spec'
28
- spec.spec_files = FileList['spec/**/*_spec.rb']
29
- end
30
-
31
- Spec::Rake::SpecTask.new(:rcov) do |spec|
32
- spec.libs << 'lib' << 'spec'
33
- spec.pattern = 'spec/**/*_spec.rb'
34
- spec.rcov = true
35
- end
36
-
37
- task :spec => :check_dependencies
11
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
12
+ spec.libs << 'lib' << 'spec'
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rcov = true
15
+ end
38
16
 
39
- task :default => :spec
17
+ task :spec => :check_dependencies
40
18
 
19
+ task :default => :spec
20
+ rescue LoadError
21
+ puts 'install rspec'
22
+ end
41
23
  require 'rake/rdoctask'
42
24
  Rake::RDocTask.new do |rdoc|
43
25
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
@@ -1,13 +1,19 @@
1
1
  module RightScaleAPI
2
2
  class Account < Base
3
-
3
+ attributes [:id, :href]
4
4
  collection_uri "/api/acct"
5
5
 
6
+ # Creates a method for each passed symbol
7
+ # that grabs the list of objects matching it
8
+ # takes options that are added as query params
9
+ # also does some munging of the opts
10
+ # in particular, :region => :us_east/:us_west/:eu/:ap
11
+ # will map to the proper cloud_id, so you don't have to remember them
6
12
  def self.sub_resources *resources
7
13
  resources.each do |resource|
8
14
  module_eval %(
9
- def #{resource}
10
- get('/#{resource}.xml')['#{resource}'].map do |attrs|
15
+ def #{resource} query_opts={}
16
+ get('/#{resource}.xml', :query => #{resource.to_s.classify}.opts_to_query_opts(query_opts) )['#{resource}'].map do |attrs|
11
17
  #{resource.to_s.classify}.new attrs.merge(:account => self)
12
18
  end
13
19
  end
@@ -31,6 +37,7 @@ module RightScaleAPI
31
37
  # @option opts [String] :description The description of the deployment
32
38
  # @option opts [String :default_ec2_availability_zone the default availability zone for the deployment e.g. us-east-1a
33
39
  # @option opts [String] :default_vpc_subnet_href
40
+ # @option opts [Symbol] :region (:us_east) The region to create the IP in. One of :us_east, :eu, :us_west, :ap
34
41
  def create_deployment opts
35
42
  Deployment.create opts.merge :account => self
36
43
  end
@@ -38,7 +45,7 @@ module RightScaleAPI
38
45
  # Creates an EC2 EBS Elastic IP
39
46
  # @param [Hash] opts ip attributes
40
47
  # @option opts [String] :nickname The nickname of the ip
41
- # @option opts [Fixnum] :cloud_id the cloud identifier default 1 (1 = us-east; 2 = eu; 3 = us-west, 4 = ap)
48
+ # @option opts [Symbol] :region (:us_east) The region to create the IP in. One of :us_east, :eu, :us_west, :ap
42
49
  def create_ec2_elastic_ip opts
43
50
  Ec2ElasticIp.create opts.merge :account => self
44
51
  end
@@ -49,20 +56,23 @@ module RightScaleAPI
49
56
  # @option opts [String] :description
50
57
  # @option opts [Fixnum] :aws_size The size of the volume in gigabytes*
51
58
  # @option opts [String] :ec2_availability_zone name of the availability zone e.g. us-east-1a*
59
+ # @option opts [Symbol] :region (:us_east) The region to create the IP in. One of :us_east, :eu, :us_west, :ap
52
60
  def create_ec2_ebs_volume opts
53
61
  Ec2EbsVolume.create opts.merge :account => self
54
62
  end
55
63
 
56
64
  # Creates an EC2 Instance
57
65
  # @param [Hash] opts server attributes
58
- # @option [RightScaleAPI::ServerTemplate] opts :server_template the server template to use*
59
- # @option [[RightScaleAPI::Deployment] opts :deployment
66
+ # @option opts [RightScaleAPI::ServerTemplate] :server_template the server template to use*
67
+ # @option opts [[RightScaleAPI::Deployment] :deployment the deployment to add the instance to.
68
+ # @option opts [Symbol] :region (:us_east) The region to create the IP in. One of :us_east, :eu, :us_west, :ap
60
69
  def create_server opts
61
70
  Server.create opts.merge :account => self
62
71
  end
63
72
 
64
73
  # Gets an EC2 ssh key.
65
- # Currently you can't get a list of ssh keys through the API, so you need to get the id through the web interface.
74
+ # Currently you can't get a list of ssh keys through the API,
75
+ # so you need to get the id through the web interface.
66
76
  # https://my.rightscale.com/clouds/1/ec2_ssh_keys
67
77
  # @param id the id of the ssh key to get
68
78
  def get_ec2_ssh_key id
@@ -71,11 +81,18 @@ module RightScaleAPI
71
81
 
72
82
  class SubResource < Base
73
83
  attr_accessor :account
74
-
84
+
75
85
  def collection_uri
76
- account.path + "/" + self.class.api_name.pluralize
86
+ "#{account.path}/#{self.class.api_name.pluralize}"
87
+ end
88
+
89
+ protected
90
+
91
+ def self.opts_to_query_opts opts
92
+ super(opts).tap{|o|o.delete "account"}
77
93
  end
94
+
78
95
  end
79
-
96
+
80
97
  end
81
98
  end
@@ -1,8 +1,6 @@
1
1
  module RightScaleAPI
2
2
  class Base
3
3
 
4
- attr_accessor :id, :href
5
-
6
4
  # attributes that directly correspond to the api's
7
5
  # @param [Array<Symbol>] attrs a list of attributes an object type has
8
6
  def self.attributes attrs=nil
@@ -23,7 +21,7 @@ module RightScaleAPI
23
21
  @attributes
24
22
  end
25
23
 
26
- attributes [:tags, :created_at, :updated_at,:errors, :nickname]
24
+ attributes [:id, :href, :tags, :created_at, :updated_at,:errors, :nickname]
27
25
 
28
26
  # gets an object by id
29
27
  # @param id [Fixnum]
@@ -38,7 +36,7 @@ module RightScaleAPI
38
36
 
39
37
  query_opts = opts_to_query_opts opts
40
38
 
41
- result = RightScaleAPI::Client.post(object.collection_uri, :body => {api_name => query_opts})
39
+ result = RightScaleAPI::Client.post(object.collection_uri, :body => query_opts)
42
40
 
43
41
  if result.code.to_i != 201
44
42
  p object.collection_uri
@@ -129,7 +127,7 @@ module RightScaleAPI
129
127
  end
130
128
 
131
129
  def path
132
- collection_uri + "/" + id
130
+ "#{collection_uri}/#{id}"
133
131
  end
134
132
 
135
133
  def id_from_href href
@@ -143,6 +141,11 @@ module RightScaleAPI
143
141
  def self.opts_to_query_opts opts
144
142
  query_opts = opts.dup
145
143
 
144
+ if query_opts[:region]
145
+ val = query_opts.delete :region
146
+ query_opts[:cloud_id] = RightScaleAPI::CLOUD_REGIONS[val.to_sym]
147
+ end
148
+
146
149
  relations = attributes.select {|a|a.to_s.include? '_href'}
147
150
  relations.each do |r|
148
151
  r_name = r.to_s.sub('_href','').to_sym
@@ -150,7 +153,11 @@ module RightScaleAPI
150
153
  query_opts[r] = query_opts.delete(r_name).href
151
154
  end
152
155
  end
153
- query_opts.delete_if {|k,v| ! attributes.include? k.to_sym }
156
+
157
+ attrs = query_opts.dup.delete_if {|k,v| ! attributes.include? k.to_sym }
158
+ query_opts.dup.delete_if {|k,v| attributes.include? k.to_sym }
159
+
160
+ query_opts[api_name] = attrs
154
161
 
155
162
  query_opts
156
163
  end
@@ -3,7 +3,6 @@ module RightScaleAPI
3
3
  attributes %w(
4
4
  ec2_instance_id
5
5
  public_ip
6
- cloud_id
7
6
  server_href
8
7
  instance_href
9
8
  )
@@ -4,7 +4,6 @@ module RightScaleAPI
4
4
  aki_image_href
5
5
  ari_image_href
6
6
  associate_eip_at_launch
7
- cloud_id
8
7
  current_instance_href
9
8
  deployment_href
10
9
  ec2_availability_zone
@@ -7,6 +7,13 @@ module RightScaleAPI
7
7
  API_VERSION = '1.0'
8
8
  BASE_URI = "https://my.rightscale.com/"
9
9
 
10
+ CLOUD_REGIONS = {
11
+ :us_east => 1,
12
+ :eu => 2,
13
+ :us_west => 3,
14
+ :ap => 4
15
+ }
16
+
10
17
  def self.login *args
11
18
  Client.login *args
12
19
  end
@@ -1,11 +1,8 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{right-scale-api}
8
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Nick Howard"]
@@ -54,23 +51,8 @@ Gem::Specification.new do |s|
54
51
  "spec/spec_helper.rb"
55
52
  ]
56
53
 
57
- if s.respond_to? :specification_version then
58
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
59
- s.specification_version = 3
60
-
61
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
- s.add_runtime_dependency(%q<httparty>, ["~> 0.6.0"])
63
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
64
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
65
- else
66
- s.add_dependency(%q<httparty>, ["~> 0.6.0"])
67
- s.add_dependency(%q<activesupport>, [">= 0"])
68
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
69
- end
70
- else
71
- s.add_dependency(%q<httparty>, ["~> 0.6.0"])
72
- s.add_dependency(%q<activesupport>, [">= 0"])
73
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
74
- end
54
+ s.add_runtime_dependency(%q<httparty>, ["~> 0.6.0"])
55
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
56
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
75
57
  end
76
58
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right-scale-api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Howard