nephophobia 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.autotest +29 -0
  2. data/.gitignore +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +35 -0
  6. data/README.md +23 -0
  7. data/Rakefile +11 -0
  8. data/lib/aws.rb +51 -0
  9. data/lib/hashify.rb +29 -0
  10. data/lib/nephophobia.rb +30 -0
  11. data/lib/nephophobia/client.rb +73 -0
  12. data/lib/nephophobia/compute.rb +150 -0
  13. data/lib/nephophobia/image.rb +78 -0
  14. data/lib/nephophobia/project.rb +113 -0
  15. data/lib/nephophobia/role.rb +5 -0
  16. data/lib/nephophobia/user.rb +86 -0
  17. data/lib/nephophobia/version.rb +3 -0
  18. data/nephophobia.gemspec +30 -0
  19. data/test/fixtures/cassettes/compute_all.yml +28 -0
  20. data/test/fixtures/cassettes/compute_all_with_filter.yml +30 -0
  21. data/test/fixtures/cassettes/compute_all_with_string_into_int_error.yml +28 -0
  22. data/test/fixtures/cassettes/compute_create.yml +28 -0
  23. data/test/fixtures/cassettes/compute_create_with_optional_params.yml +28 -0
  24. data/test/fixtures/cassettes/compute_destroy.yml +28 -0
  25. data/test/fixtures/cassettes/compute_find.yml +28 -0
  26. data/test/fixtures/cassettes/compute_reboot.yml +28 -0
  27. data/test/fixtures/cassettes/compute_start.yml +30 -0
  28. data/test/fixtures/cassettes/compute_stop.yml +30 -0
  29. data/test/fixtures/cassettes/image_all.yml +28 -0
  30. data/test/fixtures/cassettes/image_all_with_filter.yml +28 -0
  31. data/test/fixtures/cassettes/image_all_with_string_into_int_error.yml +28 -0
  32. data/test/fixtures/cassettes/image_find.yml +28 -0
  33. data/test/fixtures/cassettes/project_add_member.yml +28 -0
  34. data/test/fixtures/cassettes/project_all.yml +28 -0
  35. data/test/fixtures/cassettes/project_all_with_string_into_int_error.yml +28 -0
  36. data/test/fixtures/cassettes/project_create.yml +28 -0
  37. data/test/fixtures/cassettes/project_destroy.yml +28 -0
  38. data/test/fixtures/cassettes/project_find.yml +28 -0
  39. data/test/fixtures/cassettes/project_members.yml +28 -0
  40. data/test/fixtures/cassettes/project_remove_member.yml +28 -0
  41. data/test/fixtures/cassettes/user_add_role.yml +28 -0
  42. data/test/fixtures/cassettes/user_create.yml +28 -0
  43. data/test/fixtures/cassettes/user_destroy.yml +28 -0
  44. data/test/fixtures/cassettes/user_find.yml +28 -0
  45. data/test/fixtures/cassettes/user_remove_role.yml +28 -0
  46. data/test/lib/aws_test.rb +22 -0
  47. data/test/lib/hashify_test.rb +15 -0
  48. data/test/lib/nephophobia/compute_test.rb +144 -0
  49. data/test/lib/nephophobia/image_test.rb +76 -0
  50. data/test/lib/nephophobia/project_test.rb +104 -0
  51. data/test/lib/nephophobia/user_test.rb +71 -0
  52. data/test/lib/nephophobia_test.rb +17 -0
  53. data/test/test_helper.rb +47 -0
  54. metadata +221 -0
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=DescribeProjectMembers&Name=production&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=to4Ia9Otnptorh4mIc11yfQgkbSZOiUdvt2%2FcqD%2Foa8%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
+ - "605"
23
+ date:
24
+ - Tue, 22 Feb 2011 06:52:40 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><DescribeProjectMembersResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>KR4WD541JK-40-5M6F8P</requestId><members><item><member>root</member></item><item><member>foo</member></item><item><member>jkleinpeter</member></item><item><member>ccrissman</member></item><item><member>amikula</member></item><item><member>kbringard</member></item><item><member>cnoshpitz</member></item><item><member>dfong</member></item><item><member>jheiss</member></item><item><member>gnolan</member></item><item><member>msaltman</member></item></members></DescribeProjectMembersResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=ModifyProjectMember&Operation=remove&Project=foobar_project&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&User=foobar_user&Version=2010-11-15&Signature=F2fyTQhUp%2F6sWK5RHDtWC5LIgBpn%2B5txucwppHhmCGc%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
+ - Tue, 01 Mar 2011 00:09:04 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><ModifyProjectMemberResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>ZYIT7PLXESQS3-R6C7-5</requestId><return>true</return></ModifyProjectMemberResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=ModifyUserRole&Operation=add&Role=sysadmin&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&User=foobar_user&Version=2010-11-15&Signature=u6HKETcfKwGOrd9raDpqR%2F3UUvK2MuFurOPcGKdfGf0%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
+ - "184"
23
+ date:
24
+ - Tue, 01 Mar 2011 00:09:31 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><ModifyUserRoleResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>07TFB4HPAXZ6LCHVPIOM</requestId><return>true</return></ModifyUserRoleResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=RegisterUser&Name=foobar_user&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=i0l%2Bd24KlYwnDkSyncn6MqM7clMzbDUPM1e3HLGhBCw%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
+ - "316"
23
+ date:
24
+ - Tue, 22 Feb 2011 06:22:39 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><RegisterUserResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>5FON7RFZ5HUGK3JZFZVO</requestId><username>foobar_user</username><secretkey>58db9822-1640-4f9b-ac6e-124bad7cf011</secretkey><accesskey>03a576f7-dca0-439c-9b14-edb5dc05f73c</accesskey><file/></RegisterUserResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=DeregisterUser&Name=foobar_user&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=%2Fz%2BEt26qgbQpbF0wq55%2FdqrQYVqh%2BVlxHZgBi44VZPs%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
+ - "184"
23
+ date:
24
+ - Sun, 27 Feb 2011 06:03:26 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><DeregisterUserResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>N-IBN290-1NG933LHXJY</requestId><return>true</return></DeregisterUserResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=DescribeUser&Name=jdewey&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=SEgVk29ZPc%2BMBtuV4dIINMYpfLaPq13EUlxxuoOx%2BwA%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
+ - "311"
23
+ date:
24
+ - Tue, 22 Feb 2011 06:22:51 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><DescribeUserResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>HSXBUX3F32M3AZGBWKP8</requestId><username>jdewey</username><secretkey>3ae9d9f0-2723-480a-99eb-776f05950506</secretkey><accesskey>9c01b833-3047-4f2e-bb2a-5c8dc7c8ae9c</accesskey><file/></DescribeUserResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,28 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://10.1.170.32:8773/services/Admin/?AWSAccessKeyId=1d7a687b-0065-44d6-9611-5bf6c6c72424%3Aproduction&Action=ModifyUserRole&Operation=remove&Role=sysadmin&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&User=foobar_user&Version=2010-11-15&Signature=NPQY7sAUsOW4MR05%2Byq96qoA%2FDhrh%2BIFjfFQEjzocVc%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
+ - "184"
23
+ date:
24
+ - Tue, 01 Mar 2011 00:09:31 GMT
25
+ connection:
26
+ - keep-alive
27
+ body: <?xml version="1.0" ?><ModifyUserRoleResponse xmlns="http://ec2.amazonaws.com/doc/2010-11-15/"><requestId>D-7DGZ3BHUJ8OEXEYWMI</requestId><return>true</return></ModifyUserRoleResponse>
28
+ http_version: "1.1"
@@ -0,0 +1,22 @@
1
+ require "test_helper"
2
+
3
+ describe AWS do
4
+ describe "#signed_params" do
5
+ before do
6
+ @aws = AWS.new(
7
+ :host => "example.com",
8
+ :port => 8773,
9
+ :path => "/services/Cloud",
10
+ :access_key => "9c01b833-3047-4f2e-bb2a-5c8dc7c8ae9c",
11
+ :secret_key => "3ae9d9f0-2723-480a-99eb-776f05950506",
12
+ :project => "production"
13
+ )
14
+ end
15
+
16
+ it "returns signed query params" do
17
+ result = @aws.signed_params "get", "Action" => "DescribeInstances"
18
+
19
+ result.must_equal "AWSAccessKeyId=9c01b833-3047-4f2e-bb2a-5c8dc7c8ae9c%3Aproduction&Action=DescribeInstances&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=1999-12-31T19%3A59%3A59Z&Version=2010-11-15&Signature=x0wJmpbCeXpNcwVuTmB7E59zmlyTRkjDxjlO%2BCQi4z4%3D"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ describe Hashify do
4
+ #TODO: *WAY* more testing
5
+
6
+ describe "::convert" do
7
+ it "creates a hash from a Nokogiri::XML::Document" do
8
+ xml = cassette_for "compute_all"
9
+ hash = Hashify.convert xml.root
10
+
11
+ assert_equal "Server 199", hash['DescribeInstancesResponse']['reservationSet']['item'].first['instancesSet']['item']['displayName']
12
+ assert_equal "Server 198", hash['DescribeInstancesResponse']['reservationSet']['item'].last['instancesSet']['item']['displayName']
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,144 @@
1
+ require "test_helper"
2
+
3
+ describe Nephophobia::Compute do
4
+ before { @compute = Nephophobia::Compute.new USER_CLIENT }
5
+
6
+ describe "#compute" do
7
+ it "has compute decorator" do
8
+ USER_CLIENT.must_respond_to :compute
9
+ end
10
+ end
11
+
12
+ describe "#all" do
13
+ it "returns all instances" do
14
+ VCR.use_cassette "compute_all" do
15
+ response = @compute.all
16
+
17
+ response.size.must_equal 2
18
+ end
19
+ end
20
+
21
+ it "API doesn't implement Filter" do
22
+ VCR.use_cassette "compute_all_with_filter" do
23
+ filter = {
24
+ "Filter.1.Name" => "instance-type",
25
+ "Filter.1.Value.1" => "m1.small"
26
+ }
27
+
28
+ lambda { @compute.all filter }.must_raise Hugs::Errors::BadRequest
29
+ end
30
+ end
31
+
32
+ it "has a 'TypeError: can't convert String into Integer' error" do
33
+ VCR.use_cassette "compute_all_with_string_into_int_error" do
34
+ response = @compute.all
35
+
36
+ response.size.must_equal 1
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#create" do
42
+ before { @image_id = "ami-usc3oydl" }
43
+
44
+ it "create an instance with given 'image_id'" do
45
+ VCR.use_cassette "compute_create" do
46
+ response = @compute.create @image_id
47
+
48
+ response.image_id.must_equal @image_id
49
+ end
50
+ end
51
+
52
+ it "create an instance with optional params" do
53
+ params = {
54
+ "DisplayName" => "testserver1",
55
+ "DisplayDescription" => "test description"
56
+ }
57
+
58
+ VCR.use_cassette "compute_create_with_optional_params" do
59
+ response = @compute.create @image_id, params
60
+
61
+ response.name.must_equal "testserver1"
62
+ response.description.must_equal "test description"
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "#destroy" do
68
+ before { @instance_id = "i-000000c7" }
69
+
70
+ it "destroy the given 'instance_id'" do
71
+ VCR.use_cassette "compute_destroy" do
72
+ response = @compute.destroy @instance_id
73
+
74
+ response.return.must_equal true
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "#find" do
80
+ before do
81
+ @instance_id = "i-000000c7"
82
+
83
+ VCR.use_cassette "compute_find" do
84
+ @response = @compute.find @instance_id
85
+ end
86
+ end
87
+
88
+ it "returns the given 'instance_id'" do
89
+ @response.instance_id.must_equal @instance_id
90
+ end
91
+
92
+ it "contains the compute data" do
93
+ compute = @response
94
+
95
+ compute.project_id.must_equal "production"
96
+ compute.description.must_be_nil
97
+ compute.name.must_equal "Server 199"
98
+ compute.key_name.must_equal "None (production, e3ab3)"
99
+ compute.instance_id.must_equal "i-000000c7"
100
+ compute.state.must_equal "running"
101
+ compute.public_dns_name.must_be_nil
102
+ compute.private_dns_name.must_equal "10.1.171.8"
103
+ compute.image_id.must_equal "ami-usc3oydl"
104
+ compute.dns_name.must_equal "10.1.171.8"
105
+ compute.launch_time.must_equal Time.new("2011-02-21 17:54:35").utc
106
+ compute.placement.must_equal "nova"
107
+ compute.instance_type.must_equal "m1.small"
108
+ end
109
+ end
110
+
111
+ describe "#reboot" do
112
+ before { @instance_id = "i-00000471" }
113
+
114
+ it "reboots the given 'instance_id'" do
115
+ VCR.use_cassette "compute_reboot" do
116
+ response = @compute.reboot @instance_id
117
+
118
+ response.return.must_equal true
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "#start" do
124
+ before { @instance_id = "i-00000471" }
125
+
126
+ # 2011-02-26 22:24:55,809 ERROR nova.api [HU844ZYTDM1-8QJIY6MI jdewey production] Unexpected error raised: Unsupported API request: controller = CloudController, action = StartInstances
127
+ it "API doesn't implement StartInstances" do
128
+ VCR.use_cassette "compute_start" do
129
+ lambda { @compute.start @instance_id }.must_raise Hugs::Errors::BadRequest
130
+ end
131
+ end
132
+ end
133
+
134
+ describe "#stop" do
135
+ before { @instance_id = "i-00000471" }
136
+
137
+ # 2011-02-26 20:50:45,375 ERROR nova.api [HIA363E2X4025I-FIZ7E jdewey production] Unexpected error raised: Unsupported API request: controller = CloudController, action = StopInstances
138
+ it "API doesn't implement StopInstances" do
139
+ VCR.use_cassette "compute_stop" do
140
+ lambda { @compute.stop @instance_id }.must_raise Hugs::Errors::BadRequest
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,76 @@
1
+ require "test_helper"
2
+
3
+ describe Nephophobia::Image do
4
+ before do
5
+ @image = Nephophobia::Image.new USER_CLIENT
6
+ end
7
+
8
+ describe "#image" do
9
+ it "has image decorator" do
10
+ USER_CLIENT.must_respond_to :image
11
+ end
12
+ end
13
+
14
+ describe "#all" do
15
+ it "returns all images" do
16
+ VCR.use_cassette "image_all" do
17
+ response = @image.all
18
+
19
+ response.size.must_equal 8
20
+ end
21
+ end
22
+
23
+ it "API doesn't implement Filter" do
24
+ VCR.use_cassette "image_all_with_filter" do
25
+ response = @image.all "ExecutableBy.1" => "self"
26
+
27
+ response.size.must_equal 8
28
+ end
29
+ end
30
+
31
+ it "has a 'TypeError: can't convert String into Integer' error" do
32
+ VCR.use_cassette "image_all_with_string_into_int_error" do
33
+ response = @image.all
34
+
35
+ response.size.must_equal 1
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "#find" do
41
+ before do
42
+ @image_id = "ami-l1u1pqfm"
43
+
44
+ VCR.use_cassette "image_find" do
45
+ @response = @image.find @image_id
46
+ end
47
+ end
48
+
49
+ it "returns the given 'image_id'" do
50
+ @response.image_id.must_equal @image_id
51
+ end
52
+
53
+ it "contains the image data" do
54
+ image = @response
55
+
56
+ image.architecture.must_equal "x86_64"
57
+ image.image_id.must_equal "ami-l1u1pqfm"
58
+ image.image_location.must_equal "ttylinx-bucket/ttylinux-uec-amd64-12.1_2.6.35-22_1.img.manifest.xml"
59
+ image.image_owner_id.must_equal "production"
60
+ image.image_type.must_equal "machine"
61
+ image.is_public.must_equal "false"
62
+ image.kernel_id.must_equal "ami-d0f0o14c"
63
+ image.state.must_equal "available"
64
+ end
65
+ end
66
+
67
+ describe "#public" do
68
+ it "returns all public images" do
69
+ VCR.use_cassette "image_all" do
70
+ response = @image.public
71
+
72
+ response.size.must_equal 2
73
+ end
74
+ end
75
+ end
76
+ end