skeme 0.0.5 → 0.0.6

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -19,6 +19,7 @@ module Skeme
19
19
  @@logger = nil
20
20
  @@fog_aws_computes = {}
21
21
 
22
+ # TODO: Allow a preferred region/az if it's known
22
23
  def initialize(options={})
23
24
  @@logger = options[:logger]
24
25
  if options[:aws_access_key_id] && options[:aws_secret_access_key]
@@ -57,16 +58,16 @@ module Skeme
57
58
  supplied_id_type.each do |resource_id_key|
58
59
  resource_id = params[resource_id_key]
59
60
  if setting
61
+ @@logger.info("Tagging AWS resource id (#{resource_id}) with (#{tag})")
60
62
  not_found_exceptions = []
61
63
  @@fog_aws_computes.each do |key,val|
62
64
  begin
63
65
  val.create_tags(resource_id, {tag => nil})
64
- @@logger.info("Tagging AWS resource id (#{resource_id}) with (#{tag}) in AWS cloud (#{key})")
65
66
  rescue Fog::Service::NotFound => e
66
67
  not_found_exceptions << e
67
68
  end
68
69
  end
69
- if not_found_exceptions.count == @@fog_aws_computes.count
70
+ if @@fog_aws_computes.count > 0 && not_found_exceptions.count == @@fog_aws_computes.count
70
71
  raise not_found_exceptions.first
71
72
  end
72
73
  else
@@ -79,7 +80,7 @@ module Skeme
79
80
  not_found_exceptions << e
80
81
  end
81
82
  end
82
- if not_found_exceptions.count == @@fog_aws_computes.count
83
+ if @@fog_aws_computes.count > 0 && not_found_exceptions.count == @@fog_aws_computes.count
83
84
  raise not_found_exceptions.first
84
85
  end
85
86
  end
@@ -19,15 +19,19 @@ module Skeme
19
19
  class RightScale
20
20
  attr_accessor :logger, :gotime
21
21
 
22
+ @@region_hash = {'us-east-1' => 1, 'eu-west-1' => 2, 'us-west-1' => 3, 'ap-northeast-1' => 4, 'ap-southeast-1' => 5}
23
+
22
24
  def initialize(options={})
23
25
  @logger = options[:logger]
24
26
  if options[:rs_email] && options[:rs_pass] && options[:rs_acct_num]
27
+ pass = options[:rs_pass].gsub('"', '\\"')
28
+
25
29
  @logger.info("RightScale credentials supplied. RightScale Tagging Enabled.")
26
30
  ::RightScale::Api::BaseExtend.class_eval <<-EOF
27
31
  @@connection ||= RestConnection::Connection.new
28
32
  @@connection.settings = {
29
33
  :user => "#{options[:rs_email]}",
30
- :pass => "#{options[:rs_pass]}",
34
+ :pass => "#{pass}",
31
35
  :api_url => "https://my.rightscale.com/api/acct/#{options[:rs_acct_num]}",
32
36
  :common_headers => {
33
37
  "X_API_VERSION" => "1.0"
@@ -38,7 +42,7 @@ module Skeme
38
42
  @@connection ||= RestConnection::Connection.new
39
43
  @@connection.settings = {
40
44
  :user => "#{options[:rs_email]}",
41
- :pass => "#{options[:rs_pass]}",
45
+ :pass => "#{pass}",
42
46
  :api_url => "https://my.rightscale.com/api/acct/#{options[:rs_acct_num]}",
43
47
  :common_headers => {
44
48
  "X_API_VERSION" => "1.0"
@@ -75,6 +79,44 @@ module Skeme
75
79
  server
76
80
  end
77
81
 
82
+ def volume_from_unique_id(ec2_volume_id, options={:region => nil})
83
+ @logger.info("Looking for ec2_volume_id #{ec2_volume_id}")
84
+ vol = nil
85
+ local_region_hash = @@region_hash
86
+ local_region_hash = {options[:region] => @@region_hash[options[:region]]} if options[:region]
87
+
88
+ @logger.info("region hash is #{local_region_hash}")
89
+
90
+ local_region_hash.each do |region_name,region_id|
91
+ @logger.info("Searching in region #{region_name}")
92
+ vols_in_region = Ec2EbsVolume.find_by_cloud_id(region_id)
93
+ vols_matching_id = vols_in_region.select { |v| v.aws_id == ec2_volume_id }
94
+ if vols_matching_id && vols_matching_id.count > 0
95
+ vol = vols_matching_id.first
96
+ break
97
+ end
98
+ end
99
+
100
+ vol
101
+ end
102
+
103
+ def snapshot_from_unique_id(ec2_snapshot_id, options={:region => nil})
104
+ snap = nil
105
+ local_region_hash = @@region_hash
106
+ local_region_hash = {options[:region] => @@region_hash[options[:region]]} if options[:region]
107
+
108
+ local_region_hash.each do |region_name,region_id|
109
+ snaps_in_region = Ec2EbsSnapshot.find_by_cloud_id(region_id)
110
+ snaps_matching_id = snaps_in_region.select { |v| v.aws_id == ec2_snapshot_id }
111
+ if snaps_matching_id && snaps_matching_id.count > 0
112
+ snap = snaps_matching_id.first
113
+ break
114
+ end
115
+ end
116
+
117
+ snap
118
+ end
119
+
78
120
  def tag(params={})
79
121
  if @gotime
80
122
  tag = params[:rs_tag] || params[:tag]
@@ -83,14 +125,19 @@ module Skeme
83
125
  params.keys.each do |resource_id_key|
84
126
  resource_href = nil
85
127
  case resource_id_key
128
+ # TODO: Should check for nil on each of these, since what I'm looking for may not be found
129
+
86
130
  # This creates a condition where the instance is tagged twice if both ec2_instance_id and rs_tag_target are both provided.
87
131
  # It's still less calls than iterating all of the servers for the aws-id though.
88
132
  when :ec2_instance_id, :rs_tag_target
89
- resource_href = server_from_unique_id(params[:ec2_instance_id], params[:rs_tag_target]).current_instance_href
133
+ server = server_from_unique_id(params[:ec2_instance_id], params[:rs_tag_target])
134
+ resource_href = server.current_instance_href if server
90
135
  when :ec2_ebs_volume_id
91
- resource_href = Ec2EbsVolume.find(:first) { |vol| vol.aws_id == params[:ec2_ebs_volume_id] }.href
136
+ vol = volume_from_unique_id(params[:ec2_ebs_volume_id])
137
+ resource_href = vol.href if vol
92
138
  when :ec2_ebs_snapshot_id
93
- resource_href = Ec2EbsSnapshot.find(:first) { |snap| snap.aws_id == params[:ec2_ebs_snapshot_id] }.href
139
+ snap = snapshot_from_unique_id(params[:ec2_ebs_snapshot_id])
140
+ resource_href = snap.href if snap
94
141
  end
95
142
 
96
143
  if resource_href
data/skeme.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{skeme}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan J. Geyer"]
12
- s.date = %q{2011-05-27}
12
+ s.date = %q{2011-06-06}
13
13
  s.description = %q{= skeme
14
14
 
15
15
  Skeme is a library for tagging objects (server instances, storage volumes, etc). It is intended to allow tagging of the same resource in multiple systems simultaneously.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skeme
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan J. Geyer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-27 00:00:00 -07:00
18
+ date: 2011-06-06 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency