nephophobia 0.2.0 → 0.3.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.
Files changed (46) hide show
  1. data/README.md +4 -0
  2. data/lib/nephophobia/client.rb +3 -3
  3. data/lib/nephophobia/compute.rb +70 -2
  4. data/lib/nephophobia/credential.rb +0 -19
  5. data/lib/nephophobia/project.rb +3 -0
  6. data/lib/nephophobia/role.rb +3 -0
  7. data/lib/nephophobia/user.rb +20 -0
  8. data/lib/nephophobia/version.rb +1 -1
  9. data/nephophobia.gemspec +2 -2
  10. data/test/cassettes/compute_allocate_address.yml +55 -0
  11. data/test/cassettes/compute_allocate_address_when_not_available.yml +30 -0
  12. data/test/cassettes/compute_associate_address.yml +136 -0
  13. data/test/cassettes/compute_disassociate_address.yml +163 -0
  14. data/test/cassettes/compute_release_address.yml +55 -0
  15. data/test/cassettes/project_add_member.yml +12 -12
  16. data/test/cassettes/project_all.yml +3 -3
  17. data/test/cassettes/project_all_with_user_name.yml +22 -22
  18. data/test/cassettes/project_create.yml +12 -12
  19. data/test/cassettes/project_destroy.yml +12 -12
  20. data/test/cassettes/project_find.yml +3 -3
  21. data/test/cassettes/project_find_with_invalid_project_name.yml +3 -3
  22. data/test/cassettes/project_member.yml +16 -16
  23. data/test/cassettes/project_members.yml +10 -10
  24. data/test/cassettes/project_members_with_invalid_project_name.yml +3 -3
  25. data/test/cassettes/project_remove_member.yml +12 -12
  26. data/test/cassettes/role_all.yml +15 -15
  27. data/test/cassettes/role_all_with_project_name.yml +15 -15
  28. data/test/cassettes/role_all_without_roles.yml +12 -12
  29. data/test/cassettes/role_create.yml +12 -12
  30. data/test/cassettes/role_create_with_project_name.yml +12 -12
  31. data/test/cassettes/role_create_with_project_name_and_role_name.yml +12 -12
  32. data/test/cassettes/role_destroy.yml +12 -12
  33. data/test/cassettes/role_destroy_with_project_name.yml +12 -12
  34. data/test/cassettes/role_destroy_with_project_name_and_role_name.yml +12 -12
  35. data/test/cassettes/user_create.yml +6 -6
  36. data/test/cassettes/user_credentials.yml +190 -0
  37. data/test/cassettes/user_destroy.yml +6 -6
  38. data/test/cassettes/user_find.yml +9 -9
  39. data/test/cassettes/user_find_with_invalid_user_name.yml +3 -3
  40. data/test/cassettes/user_register.yml +19 -19
  41. data/test/cassettes/user_register_asserts.yml +10 -10
  42. data/test/lib/nephophobia/compute_test.rb +104 -9
  43. data/test/lib/nephophobia/credential_test.rb +4 -17
  44. data/test/lib/nephophobia/user_test.rb +31 -0
  45. data/test/test_helper.rb +11 -0
  46. metadata +16 -4
data/README.md CHANGED
@@ -25,3 +25,7 @@ ruby 1.9.2
25
25
  Tests can run offline thanks to [VCR](https://github.com/myronmarston/vcr).
26
26
 
27
27
  $ bundle exec rake
28
+
29
+ ## TODO
30
+
31
+ * Should really handle users better. Once you have a user object perform actions on it vs passing user all over the place.
@@ -82,7 +82,7 @@ module Nephophobia
82
82
  # Provide a simple interface to the OpenStack Project resources.
83
83
 
84
84
  def project
85
- @path = "/services/Admin/"
85
+ @path = "/services/Admin"
86
86
  @project ||= Nephophobia::Project.new self
87
87
  end
88
88
 
@@ -90,7 +90,7 @@ module Nephophobia
90
90
  # Provide a simple interface to the OpenStack User resources.
91
91
 
92
92
  def user
93
- @path = "/services/Admin/"
93
+ @path = "/services/Admin"
94
94
  @user ||= Nephophobia::User.new self
95
95
  end
96
96
 
@@ -98,7 +98,7 @@ module Nephophobia
98
98
  # Provide a simple interface to the OpenStack Role resources.
99
99
 
100
100
  def role
101
- @path = "/services/Admin/"
101
+ @path = "/services/Admin"
102
102
  @role ||= Nephophobia::Role.new self
103
103
  end
104
104
  end
@@ -28,13 +28,22 @@ module Nephophobia
28
28
  end
29
29
 
30
30
  class VncData
31
- attr_reader :url
31
+ attr_reader :attributes, :url
32
32
 
33
33
  def initialize attributes
34
34
  @url = attributes['url']
35
35
  end
36
36
  end
37
37
 
38
+ class AddressData
39
+ attr_reader :attributes, :floating_ip, :status
40
+
41
+ def initialize attributes
42
+ @floating_ip = attributes['publicIp']
43
+ @status = attributes['item']
44
+ end
45
+ end
46
+
38
47
  class Compute
39
48
  def initialize client
40
49
  @client = client
@@ -158,7 +167,7 @@ module Nephophobia
158
167
 
159
168
  ##
160
169
  # Returns the VNC browser URL. Used by the Portal.
161
- # __Must__ have an +admin+ role to use.
170
+ # __Must__ execute as a user with the +admin+ role.
162
171
  #
163
172
  # +instance_id+: A String representing the ID of the instance.
164
173
 
@@ -171,5 +180,64 @@ module Nephophobia
171
180
 
172
181
  VncData.new response.body['GetVncConsoleResponse']
173
182
  end
183
+
184
+ ##
185
+ # Acquires an elastic IP address.
186
+ # Returns an elastic IP.
187
+
188
+ def allocate_address
189
+ response = @client.action "AllocateAddress", {}
190
+
191
+ AddressData.new response.body['AllocateAddressResponse']
192
+ end
193
+
194
+ ##
195
+ # Releases an elastic IP address.
196
+ #
197
+ # +floating_ip+: A String representing a floating IP address.
198
+
199
+ def release_address floating_ip
200
+ params = {
201
+ "PublicIp" => floating_ip
202
+ }
203
+
204
+ response = @client.action "ReleaseAddress", params
205
+
206
+ AddressData.new response.body['ReleaseAddressResponse']['releaseResponse']
207
+ end
208
+
209
+ ##
210
+ # Associates an elastic IP address with an instance.
211
+ #
212
+ # +instance_id+: A String representing the ID of the instance.
213
+ # +floating_ip+: A String representing a floating IP address.
214
+
215
+ def associate_address instance_id, floating_ip
216
+ params = {
217
+ "InstanceId" => instance_id,
218
+ "PublicIp" => floating_ip
219
+ }
220
+
221
+ response = @client.action "AssociateAddress", params
222
+
223
+ AddressData.new response.body['AssociateAddressResponse']['associateResponse']
224
+ end
225
+
226
+ ##
227
+ # Disassociates the specified elastic IP address from the instance
228
+ # to which it is assigned.
229
+ #
230
+ # +instance_id+: A String representing the ID of the instance.
231
+ # +floating_ip+: A String representing a floating IP address.
232
+
233
+ def disassociate_address floating_ip
234
+ params = {
235
+ "PublicIp" => floating_ip
236
+ }
237
+
238
+ response = @client.action "DisassociateAddress", params
239
+
240
+ AddressData.new response.body['DisassociateAddressResponse']['disassociateResponse']
241
+ end
174
242
  end
175
243
  end
@@ -61,24 +61,5 @@ module Nephophobia
61
61
 
62
62
  ResponseData.new response.body['DeleteKeyPairResponse']
63
63
  end
64
-
65
- ##
66
- # Returns the credentials for a given 'user_name' for the specified 'project_name'.
67
- #
68
- # +user_name+: A String containing a nova user_name.
69
- # +project_name+: A String containing a nova project_name name.
70
- #
71
- # TODO: Determine why it fails in Nova when a user is in more than one project.
72
-
73
- #def download user_name, project_name
74
- # params = {
75
- # "Name" => user_name,
76
- # "Project" => project_name
77
- # }
78
-
79
- # response = @client.action "GenerateX509ForUser", params
80
-
81
- # Base64.decode64 response.body['GenerateX509ForUserResponse']['file']
82
- #end
83
64
  end
84
65
  end
@@ -1,3 +1,6 @@
1
+ ##
2
+ # __Must__ execute as a user with the +admin+ role.
3
+
1
4
  module Nephophobia
2
5
  class ProjectData
3
6
  attr_reader :name, :manager_id, :description
@@ -1,3 +1,6 @@
1
+ ##
2
+ # __Must__ execute as a user with the +admin+ role.
3
+
1
4
  module Nephophobia
2
5
  class RoleData
3
6
  attr_reader :name
@@ -1,3 +1,6 @@
1
+ ##
2
+ # __Must__ execute as a user with the +admin+ role.
3
+
1
4
  module Nephophobia
2
5
  class UserData
3
6
  attr_reader :accesskey, :username, :secretkey
@@ -30,6 +33,23 @@ module Nephophobia
30
33
  UserData.new response.body['RegisterUserResponse']
31
34
  end
32
35
 
36
+ ##
37
+ # Returns the credentials for a given 'user_name' for the specified 'project_name'.
38
+ #
39
+ # +user_name+: A String containing a nova user_name.
40
+ # +project_name+: A String containing a nova project_name name.
41
+
42
+ def credentials user_name, project_name
43
+ params = {
44
+ "Name" => user_name,
45
+ "Project" => project_name
46
+ }
47
+
48
+ response = @client.action "GenerateX509ForUser", params
49
+
50
+ Base64.decode64 response.body['GenerateX509ForUserResponse']['file']
51
+ end
52
+
33
53
  ##
34
54
  # Removes the given 'user_name'.
35
55
  # Returns a response to the state change.
@@ -1,3 +1,3 @@
1
1
  module Nephophobia
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/nephophobia.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.version = Nephophobia::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["John Dewey", "Josh Kleinpeter"]
10
- s.email = ["jdewey@attinteractive.com", "jkleinpeter@attinteractive.com"]
11
- s.homepage = ""
10
+ s.email = ["john@dewey.ws", "jkleinpeter@attinteractive.com"]
11
+ s.homepage = "http://github.com/retr0h/nephophobia"
12
12
  s.summary = %q{Bindings to EC2/OpenStack}
13
13
  s.description = %q{This gem is a simple binding to the EC2 API. It has specific extensions to allow extra functionality provided by OpenStack.}
14
14
 
@@ -0,0 +1,55 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=AllocateAddress&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=bCaGs5tWfNNy%2F3sg%2FRP0ISHMEnT0EZzuoPe%2Fcconzn8%3D
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/xml
10
+ connection:
11
+ - keep-alive
12
+ keep-alive:
13
+ - 30
14
+ response: !ruby/struct:VCR::Response
15
+ status: !ruby/struct:VCR::ResponseStatus
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ content-type:
20
+ - text/xml
21
+ content-length:
22
+ - "194"
23
+ date:
24
+ - Wed, 25 May 2011 22:30:56 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>PW8TPJTX8XSPDPTNSAIR</requestId><publicIp>69.1.1.1</publicIp></AllocateAddressResponse>
28
+ http_version: "1.1"
29
+ - !ruby/struct:VCR::HTTPInteraction
30
+ request: !ruby/struct:VCR::Request
31
+ method: :get
32
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=ReleaseAddress&PublicIp=69.1.1.1&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=lQpO7lKIr7pdJWi7J%2FWS3T6e6X%2FYjVixw2qaK%2FJyS30%3D
33
+ body:
34
+ headers:
35
+ accept:
36
+ - application/xml
37
+ connection:
38
+ - keep-alive
39
+ keep-alive:
40
+ - 30
41
+ response: !ruby/struct:VCR::Response
42
+ status: !ruby/struct:VCR::ResponseStatus
43
+ code: 200
44
+ message: OK
45
+ headers:
46
+ content-type:
47
+ - text/xml
48
+ content-length:
49
+ - "228"
50
+ date:
51
+ - Wed, 25 May 2011 22:30:56 GMT
52
+ connection:
53
+ - keep-alive
54
+ body: <?xml version="1.0" ?><ReleaseAddressResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>6RRU8VV0CEG-SPEB5KKP</requestId><releaseResponse><item>Address released.</item></releaseResponse></ReleaseAddressResponse>
55
+ http_version: "1.1"
@@ -0,0 +1,30 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=AllocateAddress&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=bCaGs5tWfNNy%2F3sg%2FRP0ISHMEnT0EZzuoPe%2Fcconzn8%3D
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/xml
10
+ connection:
11
+ - keep-alive
12
+ keep-alive:
13
+ - 30
14
+ response: !ruby/struct:VCR::Response
15
+ status: !ruby/struct:VCR::ResponseStatus
16
+ code: 400
17
+ message: Bad Request
18
+ headers:
19
+ content-type:
20
+ - text/xml
21
+ content-length:
22
+ - "223"
23
+ date:
24
+ - Wed, 25 May 2011 20:18:57 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: |-
28
+ <?xml version="1.0"?>
29
+ <Response><Errors><Error><Code>UnknownError</Code><Message>An unknown error has occurred. Please try your request again.</Message></Error></Errors><RequestID>XMJSQ3C9JVKG8425FI48</RequestID></Response>
30
+ http_version: "1.1"
@@ -0,0 +1,136 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=RunInstances&ImageId=ami-00000002&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=tPz8K7mYsXFNuGeGmQCf3JFCOWsQ5iGKP%2B4CU1PUoOI%3D
6
+ body:
7
+ headers:
8
+ accept:
9
+ - application/xml
10
+ connection:
11
+ - keep-alive
12
+ keep-alive:
13
+ - 30
14
+ response: !ruby/struct:VCR::Response
15
+ status: !ruby/struct:VCR::ResponseStatus
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ content-type:
20
+ - text/xml
21
+ content-length:
22
+ - "838"
23
+ date:
24
+ - Wed, 25 May 2011 21:22:10 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>MJCBI4431XGHED2QAQUU</requestId><ownerId>sandbox</ownerId><groupSet><item><groupId>default</groupId></item></groupSet><reservationId>r-cqy0q7w3</reservationId><instancesSet><item><displayDescription/><displayName>Server 64</displayName><keyName>None (sandbox, None)</keyName><instanceId>i-00000040</instanceId><instanceState><code>0</code><name>scheduling</name></instanceState><publicDnsName/><imageId>ami-00000002</imageId><productCodesSet/><privateDnsName/><dnsName/><launchTime>2011-05-25T21:22:09Z</launchTime><amiLaunchIndex>0</amiLaunchIndex><placement><availabilityZone>unknown zone</availabilityZone></placement><ipAddress/><instanceType>m1.small</instanceType><privateIpAddress/></item></instancesSet></RunInstancesResponse>
28
+ http_version: "1.1"
29
+ - !ruby/struct:VCR::HTTPInteraction
30
+ request: !ruby/struct:VCR::Request
31
+ method: :get
32
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=AssociateAddress&InstanceId=i-00000040&PublicIp=69.1.1.1&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=BPjJhW8InPmLYkhbNoDw6wcpuAZ1seaX0m1PFsLj%2FY8%3D
33
+ body:
34
+ headers:
35
+ accept:
36
+ - application/xml
37
+ connection:
38
+ - keep-alive
39
+ keep-alive:
40
+ - 30
41
+ response: !ruby/struct:VCR::Response
42
+ status: !ruby/struct:VCR::ResponseStatus
43
+ code: 200
44
+ message: OK
45
+ headers:
46
+ content-type:
47
+ - text/xml
48
+ content-length:
49
+ - "238"
50
+ date:
51
+ - Wed, 25 May 2011 21:22:15 GMT
52
+ connection:
53
+ - keep-alive
54
+ body: <?xml version="1.0" ?><AssociateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>H9IDU1-TG51CLYOMVT76</requestId><associateResponse><item>Address associated.</item></associateResponse></AssociateAddressResponse>
55
+ http_version: "1.1"
56
+ - !ruby/struct:VCR::HTTPInteraction
57
+ request: !ruby/struct:VCR::Request
58
+ method: :get
59
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=TerminateInstances&InstanceId.1=i-00000040&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=%2FR%2FjPbTCgci4Ip2a0N0nO5F9KPU%2Bney9Ji5CrHbd4GI%3D
60
+ body:
61
+ headers:
62
+ accept:
63
+ - application/xml
64
+ connection:
65
+ - keep-alive
66
+ keep-alive:
67
+ - 30
68
+ response: !ruby/struct:VCR::Response
69
+ status: !ruby/struct:VCR::ResponseStatus
70
+ code: 200
71
+ message: OK
72
+ headers:
73
+ content-type:
74
+ - text/xml
75
+ content-length:
76
+ - "192"
77
+ date:
78
+ - Wed, 25 May 2011 21:22:15 GMT
79
+ connection:
80
+ - keep-alive
81
+ body: <?xml version="1.0" ?><TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>IH7PO8M4R6RCMR8B8PEV</requestId><return>true</return></TerminateInstancesResponse>
82
+ http_version: "1.1"
83
+ - !ruby/struct:VCR::HTTPInteraction
84
+ request: !ruby/struct:VCR::Request
85
+ method: :get
86
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=AllocateAddress&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=bCaGs5tWfNNy%2F3sg%2FRP0ISHMEnT0EZzuoPe%2Fcconzn8%3D
87
+ body:
88
+ headers:
89
+ accept:
90
+ - application/xml
91
+ connection:
92
+ - keep-alive
93
+ keep-alive:
94
+ - 30
95
+ response: !ruby/struct:VCR::Response
96
+ status: !ruby/struct:VCR::ResponseStatus
97
+ code: 200
98
+ message: OK
99
+ headers:
100
+ content-type:
101
+ - text/xml
102
+ content-length:
103
+ - "194"
104
+ date:
105
+ - Wed, 25 May 2011 22:39:52 GMT
106
+ connection:
107
+ - keep-alive
108
+ body: <?xml version="1.0" ?><AllocateAddressResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>7URCU5WTAPD50ZXP9RH0</requestId><publicIp>69.1.1.1</publicIp></AllocateAddressResponse>
109
+ http_version: "1.1"
110
+ - !ruby/struct:VCR::HTTPInteraction
111
+ request: !ruby/struct:VCR::Request
112
+ method: :get
113
+ uri: http://10.3.170.35:8773/services/Cloud?AWSAccessKeyId=2ea76797-229c-4e52-a21b-f30513cb91a6%3Asandbox&Action=ReleaseAddress&PublicIp=69.1.1.1&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=lQpO7lKIr7pdJWi7J%2FWS3T6e6X%2FYjVixw2qaK%2FJyS30%3D
114
+ body:
115
+ headers:
116
+ accept:
117
+ - application/xml
118
+ connection:
119
+ - keep-alive
120
+ keep-alive:
121
+ - 30
122
+ response: !ruby/struct:VCR::Response
123
+ status: !ruby/struct:VCR::ResponseStatus
124
+ code: 200
125
+ message: OK
126
+ headers:
127
+ content-type:
128
+ - text/xml
129
+ content-length:
130
+ - "228"
131
+ date:
132
+ - Wed, 25 May 2011 22:42:37 GMT
133
+ connection:
134
+ - keep-alive
135
+ body: <?xml version="1.0" ?><ReleaseAddressResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>61E-BMEKN9BB9BTXBP-Y</requestId><releaseResponse><item>Address released.</item></releaseResponse></ReleaseAddressResponse>
136
+ http_version: "1.1"