gaff 0.3.4 → 0.3.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/README CHANGED
@@ -14,24 +14,9 @@ Example usage:
14
14
 
15
15
  $ gaff ./gaff.yml
16
16
 
17
- Send a JSON-RPC formatted message to the exchange with the a routing key to perform operations on that API.
17
+ See examples for how to format your json to send to the queue.
18
18
 
19
- require 'rubygems'
20
- require 'carrot'
19
+ Recent breaking changes:
20
+ * EC2 messages require the region to be set in params, this allows for all support of all regions.
21
+ * With the change to dynect_rest I have changed the "address" field to the more correct "rdata".
21
22
 
22
- exch = Carrot::AMQP::Exchange.new(Carrot.new, :topic, "api")
23
-
24
- hash = {"method" => "add_a_record", "params" => {
25
- "customer_name" => "gaff.com",
26
- "username" => "username",
27
- "password" => "password",
28
- "node" => "test123",
29
- "zone" => "gaff.com",
30
- "address" => "127.0.0.1",
31
- "ttl" => "300"
32
- }
33
- }
34
-
35
- json = hash.to_json
36
-
37
- exch.publish(json, :routing_key => "dynect")
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  require 'mq'
4
4
  require 'yajl'
5
- require 'dynect'
5
+ require 'dynect_rest'
6
6
  require 'fog'
7
7
  require 'mixlib/config'
8
8
  require 'mixlib/log'
@@ -9,63 +9,33 @@ class Gaff
9
9
  STDOUT.flush
10
10
 
11
11
  begin
12
- dynect = Dynect.new(
12
+ dynect = DynectRest.new(
13
13
  hash["params"]["customer_name"],
14
14
  hash["params"]["username"],
15
- hash["params"]["password"])
15
+ hash["params"]["password"],
16
+ hash["params"]["zone"])
16
17
 
17
18
  Gaff::Log.debug(dynect)
18
19
  STDOUT.flush
19
20
 
20
21
  case hash["method"]
21
22
  when "add_a_record"
22
- node = dynect.add_node(
23
- hash["params"]["node"],
24
- hash["params"]["zone"])
25
-
26
- record = dynect.add_a_record(
27
- hash["params"]["zone"],
28
- hash["params"]["address"],
29
- {
30
- "node" => "#{hash["params"]["node"]}.#{hash["params"]["zone"]}",
31
- "ttl" => hash["params"]["ttl"]
32
- })
23
+ result = dynect.a.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").ttl(hash["params"]["ttl"]).address(hash["params"]["rdata"]).save
24
+ publish = dynect.publish
33
25
  when "add_cname_record"
34
- node = dynect.add_node(
35
- hash["params"]["node"],
36
- hash["params"]["zone"])
37
-
38
- record = dynect.add_cname_record(
39
- hash["params"]["zone"],
40
- hash["params"]["address"],
41
- {
42
- "node" => "#{hash["params"]["node"]}.#{hash["params"]["zone"]}",
43
- "ttl" => hash["params"]["ttl"]
44
- })
26
+ result = dynect.cname.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").ttl(hash["params"]["ttl"]).cname(hash["params"]["rdata"]).save
27
+ publish = dynect.publish
45
28
  when "delete_a_record"
46
- record_id = dynect.list_a_records(
47
- hash["params"]["zone"],
48
- {
49
- "node" => "#{hash["params"]["node"]}.#{hash["params"]["zone"]}"
50
- })
51
-
52
- record = dynect.delete_a_record(record_id[0]["record_id"])
29
+ result = dynect.a.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").delete
30
+ publish = dynect.publish
53
31
  when "delete_cname_record"
54
- record_id = dynect.list_cname_records(
55
- hash["params"]["zone"],
56
- {
57
- "node" => "#{hash["params"]["node"]}.#{hash["params"]["zone"]}"
58
- })
59
-
60
- record = dynect.delete_cname_record(record_id[0]["record_id"])
32
+ result = dynect.cname.fqdn("#{hash["params"]["node"]}.#{hash["params"]["zone"]}").delete
33
+ publish = dynect.publish
61
34
  end
62
35
 
63
- if node
64
- Gaff::Log.debug(node.inspect)
65
- node = nil
66
- end
67
- Gaff::Log.info(record.inspect)
68
- STDOUT.flush
36
+ Gaff::Log.info(result)
37
+ Gaff::Log.debug(publish)
38
+ STDOUT.flush
69
39
  rescue Exception => e
70
40
  Gaff::Log.error(e)
71
41
  STDOUT.flush
@@ -9,131 +9,44 @@ class Gaff
9
9
  STDOUT.flush
10
10
 
11
11
  begin
12
- @ec2east = Fog::AWS::EC2.new(
12
+ @ec2 = Fog::AWS::Compute.new(
13
13
  :aws_access_key_id => hash["params"]["aws_key"],
14
14
  :aws_secret_access_key => hash["params"]["aws_key_secret"],
15
- :region => "us-east-1")
15
+ :region => hash["params"]["region"])
16
16
 
17
- @ec2west = Fog::AWS::EC2.new(
18
- :aws_access_key_id => hash["params"]["aws_key"],
19
- :aws_secret_access_key => hash["params"]["aws_key_secret"],
20
- :region => "us-west-1")
21
-
22
- @apac = Fog::AWS::EC2.new(
23
- :aws_access_key_id => hash["params"]["aws_key"],
24
- :aws_secret_access_key => hash["params"]["aws_key_secret"],
25
- :region => "ap-southeast-1")
26
-
27
- Gaff::Log.debug(@ec2east)
28
- Gaff::Log.debug(@ec2west)
29
- Gaff::Log.debug(@apac)
17
+ Gaff::Log.debug(@ec2)
30
18
  STDOUT.flush
31
19
 
32
20
  case hash["method"]
33
21
  when "attach_volume"
34
- if zone(hash["params"]["volume_id"]).include? "us-east-1"
35
- result = @ec2east.attach_volume(hash["params"]["instance_id"], hash["params"]["volume_id"], hash["params"]["device"])
36
- elsif zone(hash["params"]["volume_id"]).include? "us-west-1"
37
- result = @ec2west.attach_volume(hash["params"]["instance_id"], hash["params"]["volume_id"], hash["params"]["device"])
38
- elsif zone(hash["params"]["volume_id"]).include? "ap-southeast-1"
39
- result = @apac.attach_volume(hash["params"]["instance_id"], hash["params"]["volume_id"], hash["params"]["device"])
40
- end
22
+ result = @ec2.attach_volume(hash["params"]["instance_id"], hash["params"]["volume_id"], hash["params"]["device"])
41
23
  when "create_volume"
42
- if hash["params"]["availability_zone"].include? "us-east-1"
43
- result = @ec2east.create_volume(hash["params"]["availability_zone"], hash["params"]["size"].to_i, hash["params"]["snapshot_id"])
44
- elsif hash["params"]["availability_zone"].include? "us-west-1"
45
- result = @ec2west.create_volume(hash["params"]["availability_zone"], hash["params"]["size"].to_i, hash["params"]["snapshot_id"])
46
- elsif hash["params"]["availability_zone"].include? "ap-southeast-1"
47
- result = @apac.create_volume(hash["params"]["availability_zone"], hash["params"]["size"].to_i, hash["params"]["snapshot_id"])
48
- end
24
+ result = @ec2.create_volume(hash["params"]["availability_zone"], hash["params"]["size"].to_i, hash["params"]["snapshot_id"])
49
25
  when "delete_volume"
50
- volume_id = hash["params"]["volume_id"]
51
- if zone(volume_id).include? "us-east-1"
52
- result = @ec2east.delete_volume(volume_id)
53
- elsif zone(volume_id).include? "us-west-1"
54
- result = @ec2west.delete_volume(volume_id)
55
- elsif zone(volume_id).include? "ap-southeast-1"
56
- result = @apac.delete_volume(volume_id)
57
- end
26
+ result = @ec2.delete_volume(hash["params"]["volume_id"])
58
27
  when "detach_volume"
59
- if zone(hash["params"]["volume_id"]).include? "us-east-1"
60
- result = @ec2east.detach_volume(
61
- hash["params"]["volume_id"],
62
- {
63
- "InstanceId" => hash["params"]["instance_id"],
64
- "Device" => hash["params"]["device"],
65
- "Force" => hash["params"]["force"]
66
- })
67
- elsif zone(hash["params"]["volume_id"]).include? "us-west-1"
68
- result = @ec2west.detach_volume(
69
- hash["params"]["volume_id"],
70
- {
71
- "InstanceId" => hash["params"]["instance_id"],
72
- "Device" => hash["params"]["device"],
73
- "Force" => hash["params"]["force"]
74
- })
75
- elsif zone(hash["params"]["volume_id"]).include? "ap-southeast-1"
76
- result = @apac.detach_volume(
77
- hash["params"]["volume_id"],
78
- {
79
- "InstanceId" => hash["params"]["instance_id"],
80
- "Device" => hash["params"]["device"],
81
- "Force" => hash["params"]["force"]
82
- })
83
- end
28
+ result = @ec2.detach_volume(
29
+ hash["params"]["volume_id"],
30
+ {
31
+ "InstanceId" => hash["params"]["instance_id"],
32
+ "Device" => hash["params"]["device"],
33
+ "Force" => hash["params"]["force"]
34
+ })
84
35
  when "launch_instances"
85
- if hash["params"]["availability_zone"].include? "us-east-1"
86
- result = @ec2east.run_instances(
87
- hash["params"]["image_id"],
88
- hash["params"]["count"],
89
- hash["params"]["count"],
90
- {
91
- "SecurityGroup" => hash["params"]["group_ids"],
92
- "KeyName" => hash["params"]["key_name"],
93
- "Placement.AvailabilityZone" => hash["params"]["availability_zone"],
94
- "InstanceType" => hash["params"]["instance_type"]
95
- })
96
- elsif hash["params"]["availability_zone"].include? "us-west-1"
97
- result = @ec2west.run_instances(
98
- hash["params"]["image_id"],
99
- hash["params"]["count"],
100
- hash["params"]["count"],
101
- {
102
- "SecurityGroup" => hash["params"]["group_ids"],
103
- "KeyName" => hash["params"]["key_name"],
104
- "Placement.AvailabilityZone" => hash["params"]["availability_zone"],
105
- "InstanceType" => hash["params"]["instance_type"]
106
- })
107
- elsif hash["params"]["availability_zone"].include? "ap-southeast-1"
108
- result = @apac.run_instances(
109
- hash["params"]["image_id"],
110
- hash["params"]["count"],
111
- hash["params"]["count"],
112
- {
113
- "SecurityGroup" => hash["params"]["group_ids"],
114
- "KeyName" => hash["params"]["key_name"],
115
- "Placement.AvailabilityZone" => hash["params"]["availability_zone"],
116
- "InstanceType" => hash["params"]["instance_type"]
117
- })
118
- end
36
+ result = @ec2.run_instances(
37
+ hash["params"]["image_id"],
38
+ hash["params"]["count"],
39
+ hash["params"]["count"],
40
+ {
41
+ "SecurityGroup" => hash["params"]["group_ids"],
42
+ "KeyName" => hash["params"]["key_name"],
43
+ "Placement.AvailabilityZone" => hash["params"]["availability_zone"],
44
+ "InstanceType" => hash["params"]["instance_type"]
45
+ })
119
46
  when "reboot_instances"
120
- instance_ids = hash["params"]["instance_ids"]
121
- if zone(instance_ids).include? "us-east-1"
122
- result = @ec2east.reboot_instances(instance_ids)
123
- elsif zone(instance_ids).include? "us-west-1"
124
- result = @ec2west.reboot_instances(instance_ids)
125
- elsif zone(instance_ids).include? "ap-southeast-1"
126
- result = @apac.reboot_instances(instance_ids)
127
- end
47
+ result = @ec2.reboot_instances(hash["params"]["instance_ids"])
128
48
  when "terminate_instances"
129
- instance_ids = hash["params"]["instance_ids"]
130
- if zone(instance_ids).include? "us-east-1"
131
- result = @ec2east.terminate_instances(instance_ids)
132
- elsif zone(instance_ids).include? "us-west-1"
133
- result = @ec2west.terminate_instances(instance_ids)
134
- elsif zone(instance_ids).include? "ap-southeast-1"
135
- result = @apac.terminate_instances(instance_ids)
136
- end
49
+ result = @ec2.terminate_instances(hash["params"]["instance_ids"])
137
50
  end
138
51
 
139
52
  Gaff::Log.info(result)
@@ -143,30 +56,6 @@ class Gaff
143
56
  STDOUT.flush
144
57
  end
145
58
  end
146
-
147
- def self.zone(id)
148
- if id.include? "i-"
149
- begin
150
- @ec2east.describe_instances(id).body["reservationSet"].first["instancesSet"].first["placement"]["availabilityZone"]
151
- rescue
152
- begin
153
- @ec2west.describe_instances(id).body["reservationSet"].first["instancesSet"].first["placement"]["availabilityZone"]
154
- rescue
155
- @apac.describe_instances(id).body["reservationSet"].first["instancesSet"].first["placement"]["availabilityZone"]
156
- end
157
- end
158
- elsif id.include? "vol-"
159
- begin
160
- @ec2east.describe_volumes(id).body["volumeSet"].first["availabilityZone"]
161
- rescue
162
- begin
163
- @ec2west.describe_volumes(id).body["volumeSet"].first["availabilityZone"]
164
- rescue
165
- @apac.describe_volumes(id).body["volumeSet"].first["availabilityZone"]
166
- end
167
- end
168
- end
169
- end
170
59
 
171
60
  end
172
61
  end
@@ -9,7 +9,7 @@ class Gaff
9
9
  STDOUT.flush
10
10
 
11
11
  begin
12
- slicehost = Fog::Slicehost.new({:slicehost_password => hash["params"]["password"]})
12
+ slicehost = Fog::Slicehost::Compute.new({:slicehost_password => hash["params"]["password"]})
13
13
 
14
14
  Gaff::Log.debug(slicehost)
15
15
  STDOUT.flush
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - joe williams
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-31 00:00:00 -07:00
18
+ date: 2011-01-13 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -61,7 +61,7 @@ dependencies:
61
61
  type: :runtime
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: dynect
64
+ name: dynect_rest
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false