nephophobia 0.3.0 → 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/lib/nephophobia.rb +26 -37
- data/lib/nephophobia/client.rb +6 -6
- data/lib/nephophobia/resource/compute.rb +209 -0
- data/lib/nephophobia/resource/credential.rb +68 -0
- data/lib/nephophobia/resource/image.rb +65 -0
- data/lib/nephophobia/resource/project.rb +132 -0
- data/lib/nephophobia/resource/role.rb +72 -0
- data/lib/nephophobia/resource/user.rb +83 -0
- data/lib/nephophobia/response/address.rb +13 -0
- data/lib/nephophobia/response/compute.rb +34 -0
- data/lib/nephophobia/response/credential.rb +17 -0
- data/lib/nephophobia/response/image.rb +24 -0
- data/lib/nephophobia/response/member.rb +15 -0
- data/lib/nephophobia/response/project.rb +18 -0
- data/lib/nephophobia/response/return.rb +16 -0
- data/lib/nephophobia/response/role.rb +15 -0
- data/lib/nephophobia/response/user.rb +17 -0
- data/lib/nephophobia/response/vnc.rb +11 -0
- data/lib/nephophobia/util.rb +12 -0
- data/lib/nephophobia/version.rb +1 -1
- data/nephophobia.gemspec +2 -2
- data/test/cassettes/compute_describe_addresses.yml +244 -0
- data/test/cassettes/compute_find.yml +30 -18
- data/test/cassettes/credential_import.yml +82 -0
- data/test/cassettes/role_all_no_params.yml +82 -0
- data/test/cassettes/role_modify_role.yml +190 -0
- data/test/dummy.pub +1 -0
- data/test/lib/nephophobia/{compute_test.rb → response/compute_test.rb} +39 -4
- data/test/lib/nephophobia/{credential_test.rb → response/credential_test.rb} +28 -1
- data/test/lib/nephophobia/{image_test.rb → response/image_test.rb} +1 -1
- data/test/lib/nephophobia/{project_test.rb → response/project_test.rb} +1 -1
- data/test/lib/nephophobia/{role_test.rb → response/role_test.rb} +57 -4
- data/test/lib/nephophobia/{user_test.rb → response/user_test.rb} +1 -1
- data/test/lib/{nephophobia_test.rb → nephophobia/util_test.rb} +3 -3
- data/test/test_helper.rb +7 -0
- metadata +45 -24
- data/lib/nephophobia/compute.rb +0 -243
- data/lib/nephophobia/credential.rb +0 -65
- data/lib/nephophobia/image.rb +0 -84
- data/lib/nephophobia/project.rb +0 -157
- data/lib/nephophobia/role.rb +0 -83
- data/lib/nephophobia/user.rb +0 -95
data/lib/nephophobia.rb
CHANGED
@@ -2,52 +2,41 @@ require "aws"
|
|
2
2
|
require "hashify"
|
3
3
|
require "date"
|
4
4
|
require "nephophobia/client"
|
5
|
-
require "nephophobia/
|
6
|
-
require "nephophobia/
|
7
|
-
require "nephophobia/
|
8
|
-
require "nephophobia/
|
9
|
-
require "nephophobia/
|
10
|
-
require "nephophobia/
|
5
|
+
require "nephophobia/util"
|
6
|
+
require "nephophobia/response/address"
|
7
|
+
require "nephophobia/response/compute"
|
8
|
+
require "nephophobia/response/credential"
|
9
|
+
require "nephophobia/response/image"
|
10
|
+
require "nephophobia/response/member"
|
11
|
+
require "nephophobia/response/project"
|
12
|
+
require "nephophobia/response/return"
|
13
|
+
require "nephophobia/response/role"
|
14
|
+
require "nephophobia/response/user"
|
15
|
+
require "nephophobia/response/vnc"
|
16
|
+
require "nephophobia/resource/compute"
|
17
|
+
require "nephophobia/resource/credential"
|
18
|
+
require "nephophobia/resource/image"
|
19
|
+
require "nephophobia/resource/project"
|
20
|
+
require "nephophobia/resource/role"
|
21
|
+
require "nephophobia/resource/user"
|
11
22
|
|
12
23
|
require "hugs"
|
13
24
|
|
14
|
-
module Nephophobia
|
15
|
-
class ResponseData
|
16
|
-
attr_reader :return, :request_id
|
17
|
-
|
18
|
-
attr_accessor :attributes
|
19
|
-
|
20
|
-
def initialize attributes
|
21
|
-
@attributes = attributes
|
22
|
-
|
23
|
-
@request_id = attributes["requestId"]
|
24
|
-
@return = attributes["return"] == "true"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Wraps a Hash with an Array.
|
30
|
-
#
|
31
|
-
# +obj+: The Object to be tested for wrapping.
|
32
|
-
|
33
|
-
def self.coerce obj
|
34
|
-
(obj.is_a? Hash) ? [obj] : obj
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
25
|
##
|
39
26
|
# Allow Data Classes to comply with ActiveModel.
|
40
27
|
|
41
28
|
module Nephophobia
|
42
29
|
class Rails
|
43
30
|
CLASSES = [
|
44
|
-
::Nephophobia::
|
45
|
-
::Nephophobia::
|
46
|
-
::Nephophobia::
|
47
|
-
::Nephophobia::
|
48
|
-
::Nephophobia::
|
49
|
-
::Nephophobia::
|
50
|
-
::Nephophobia::
|
31
|
+
::Nephophobia::Response::Address,
|
32
|
+
::Nephophobia::Response::Compute,
|
33
|
+
::Nephophobia::Response::Credential,
|
34
|
+
::Nephophobia::Response::Image,
|
35
|
+
::Nephophobia::Response::Member,
|
36
|
+
::Nephophobia::Response::Project,
|
37
|
+
::Nephophobia::Response::Role,
|
38
|
+
::Nephophobia::Response::User,
|
39
|
+
::Nephophobia::Response::Vnc
|
51
40
|
].freeze
|
52
41
|
|
53
42
|
def self.insert
|
data/lib/nephophobia/client.rb
CHANGED
@@ -59,7 +59,7 @@ module Nephophobia
|
|
59
59
|
|
60
60
|
def compute
|
61
61
|
@path = "/services/Cloud"
|
62
|
-
@compute ||= Nephophobia::Compute.new self
|
62
|
+
@compute ||= Nephophobia::Resource::Compute.new self
|
63
63
|
end
|
64
64
|
|
65
65
|
##
|
@@ -67,7 +67,7 @@ module Nephophobia
|
|
67
67
|
|
68
68
|
def credential
|
69
69
|
@path = "/services/Cloud"
|
70
|
-
@credential ||= Nephophobia::Credential.new self
|
70
|
+
@credential ||= Nephophobia::Resource::Credential.new self
|
71
71
|
end
|
72
72
|
|
73
73
|
##
|
@@ -75,7 +75,7 @@ module Nephophobia
|
|
75
75
|
|
76
76
|
def image
|
77
77
|
@path = "/services/Cloud"
|
78
|
-
@image ||= Nephophobia::Image.new self
|
78
|
+
@image ||= Nephophobia::Resource::Image.new self
|
79
79
|
end
|
80
80
|
|
81
81
|
##
|
@@ -83,7 +83,7 @@ module Nephophobia
|
|
83
83
|
|
84
84
|
def project
|
85
85
|
@path = "/services/Admin"
|
86
|
-
@project ||= Nephophobia::Project.new self
|
86
|
+
@project ||= Nephophobia::Resource::Project.new self
|
87
87
|
end
|
88
88
|
|
89
89
|
##
|
@@ -91,7 +91,7 @@ module Nephophobia
|
|
91
91
|
|
92
92
|
def user
|
93
93
|
@path = "/services/Admin"
|
94
|
-
@user ||= Nephophobia::User.new self
|
94
|
+
@user ||= Nephophobia::Resource::User.new self
|
95
95
|
end
|
96
96
|
|
97
97
|
##
|
@@ -99,7 +99,7 @@ module Nephophobia
|
|
99
99
|
|
100
100
|
def role
|
101
101
|
@path = "/services/Admin"
|
102
|
-
@role ||= Nephophobia::Role.new self
|
102
|
+
@role ||= Nephophobia::Resource::Role.new self
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Resource
|
3
|
+
class Compute
|
4
|
+
def initialize client
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns information about instances that +@client+ owns.
|
10
|
+
#
|
11
|
+
# +filter+: An optional Hash, intended for filtering.
|
12
|
+
# See the API Reference for further details.
|
13
|
+
# {
|
14
|
+
# "Filter.1.Name" => "instance-type",
|
15
|
+
# "Filter.1.Value.1" => "m1.small"
|
16
|
+
# }
|
17
|
+
|
18
|
+
def all filter = {}
|
19
|
+
response = @client.action "DescribeInstances", filter
|
20
|
+
|
21
|
+
item = response.body['DescribeInstancesResponse']['reservationSet']['item']
|
22
|
+
Nephophobia::Util.coerce(item).collect do |data|
|
23
|
+
Response::Compute.new data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Create a compute instance with the given 'image_id'.
|
29
|
+
# Returns information about the new instance.
|
30
|
+
#
|
31
|
+
# +image_id+: A String representing the ID of the image.
|
32
|
+
# +params+: An optional Hash.
|
33
|
+
# See the API Reference for further details.
|
34
|
+
# {
|
35
|
+
# "DisplayName" => "testserver1",
|
36
|
+
# "DisplayDescription" => "test description"
|
37
|
+
# }
|
38
|
+
|
39
|
+
def create image_id, params = {}
|
40
|
+
response = @client.action "RunInstances", { "ImageId" => image_id }.merge(params)
|
41
|
+
|
42
|
+
Response::Compute.new response.body['RunInstancesResponse']
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Removes the given 'instance_id'.
|
47
|
+
# Returns instances response to a state change.
|
48
|
+
#
|
49
|
+
# +instance_id+: A String representing the ID of the instance.
|
50
|
+
|
51
|
+
def destroy instance_id
|
52
|
+
params = {
|
53
|
+
"InstanceId.1" => instance_id
|
54
|
+
}
|
55
|
+
|
56
|
+
response = @client.action "TerminateInstances", params
|
57
|
+
|
58
|
+
Response::Return.new response.body['TerminateInstancesResponse']
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Returns information about the given 'instance_id'.
|
63
|
+
#
|
64
|
+
# +instance_id+: A String representing the ID of the instance.
|
65
|
+
|
66
|
+
def find instance_id
|
67
|
+
params = {
|
68
|
+
"InstanceId.1" => instance_id
|
69
|
+
}
|
70
|
+
|
71
|
+
response = @client.action "DescribeInstances", params
|
72
|
+
|
73
|
+
Response::Compute.new response.body['DescribeInstancesResponse']['reservationSet']['item']
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Reboot the given 'instance_id'.
|
78
|
+
# Returns instances response to a state change.
|
79
|
+
#
|
80
|
+
# +instance_id+: A String representing the ID of the instance.
|
81
|
+
|
82
|
+
def reboot instance_id
|
83
|
+
params = {
|
84
|
+
"InstanceId.1" => instance_id
|
85
|
+
}
|
86
|
+
|
87
|
+
response = @client.action "RebootInstances", params
|
88
|
+
|
89
|
+
Response::Return.new response.body['RebootInstancesResponse']
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Starts the given 'instance_id'.
|
94
|
+
# Returns instances current and previous state.
|
95
|
+
#
|
96
|
+
# +instance_id+: A String representing the ID of the instance.
|
97
|
+
|
98
|
+
def start instance_id
|
99
|
+
params = {
|
100
|
+
"InstanceId.1" => instance_id
|
101
|
+
}
|
102
|
+
|
103
|
+
response = @client.action "StopInstances", params
|
104
|
+
|
105
|
+
Response::Return.new response.body
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Stops the given 'instance_id'
|
110
|
+
# Returns instances current and previous state.
|
111
|
+
#
|
112
|
+
# +instance_id+: A String representing the ID of the instance.
|
113
|
+
|
114
|
+
def stop instance_id
|
115
|
+
params = {
|
116
|
+
"InstanceId.1" => instance_id
|
117
|
+
}
|
118
|
+
|
119
|
+
response = @client.action "StartInstances", params
|
120
|
+
|
121
|
+
Response::Return.new response.body
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Returns the VNC browser URL. Used by the Portal.
|
126
|
+
# __Must__ execute as a user with the +admin+ role.
|
127
|
+
#
|
128
|
+
# +instance_id+: A String representing the ID of the instance.
|
129
|
+
|
130
|
+
def vnc_url instance_id
|
131
|
+
params = {
|
132
|
+
"InstanceId" => instance_id
|
133
|
+
}
|
134
|
+
|
135
|
+
response = @client.action "GetVncConsole", params
|
136
|
+
|
137
|
+
Response::Vnc.new response.body['GetVncConsoleResponse']
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Acquires an elastic IP address.
|
142
|
+
# Returns an elastic IP.
|
143
|
+
|
144
|
+
def allocate_address
|
145
|
+
response = @client.action "AllocateAddress", {}
|
146
|
+
|
147
|
+
Response::Address.new response.body['AllocateAddressResponse']
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Releases an elastic IP address.
|
152
|
+
#
|
153
|
+
# +floating_ip+: A String representing a floating IP address.
|
154
|
+
|
155
|
+
def release_address floating_ip
|
156
|
+
params = {
|
157
|
+
"PublicIp" => floating_ip
|
158
|
+
}
|
159
|
+
|
160
|
+
response = @client.action "ReleaseAddress", params
|
161
|
+
|
162
|
+
Response::Address.new response.body['ReleaseAddressResponse']['releaseResponse']
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Associates an elastic IP address with an instance.
|
167
|
+
#
|
168
|
+
# +instance_id+: A String representing the ID of the instance.
|
169
|
+
# +floating_ip+: A String representing a floating IP address.
|
170
|
+
|
171
|
+
def associate_address instance_id, floating_ip
|
172
|
+
params = {
|
173
|
+
"InstanceId" => instance_id,
|
174
|
+
"PublicIp" => floating_ip
|
175
|
+
}
|
176
|
+
|
177
|
+
response = @client.action "AssociateAddress", params
|
178
|
+
|
179
|
+
Response::Address.new response.body['AssociateAddressResponse']['associateResponse']
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# Disassociates the specified elastic IP address from the instance
|
184
|
+
# to which it is assigned.
|
185
|
+
#
|
186
|
+
# +instance_id+: A String representing the ID of the instance.
|
187
|
+
# +floating_ip+: A String representing a floating IP address.
|
188
|
+
|
189
|
+
def disassociate_address floating_ip
|
190
|
+
params = {
|
191
|
+
"PublicIp" => floating_ip
|
192
|
+
}
|
193
|
+
|
194
|
+
response = @client.action "DisassociateAddress", params
|
195
|
+
|
196
|
+
Response::Address.new response.body['DisassociateAddressResponse']['disassociateResponse']
|
197
|
+
end
|
198
|
+
|
199
|
+
def describe_addresses
|
200
|
+
response = @client.action "DescribeAddresses", {}
|
201
|
+
|
202
|
+
item = response.body['DescribeAddressesResponse']['addressesSet']['item']
|
203
|
+
Nephophobia::Util.coerce(item).collect do |data|
|
204
|
+
Response::Address.new data
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Resource
|
3
|
+
class Credential
|
4
|
+
def initialize client
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns information about key pairs that +@client+ owns.
|
10
|
+
|
11
|
+
def all
|
12
|
+
response = @client.action "DescribeKeyPairs", {}
|
13
|
+
|
14
|
+
key_set = response.body['DescribeKeyPairsResponse']['keySet']
|
15
|
+
key_set && Nephophobia::Util.coerce(key_set['item']).collect do |data|
|
16
|
+
Response::Credential.new data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Create a key pair with the given 'key_name'.
|
22
|
+
# Returns information about the new key.
|
23
|
+
#
|
24
|
+
# +key_name+: A String containing a unique name for the key pair.
|
25
|
+
|
26
|
+
def create key_name
|
27
|
+
params = {
|
28
|
+
"KeyName" => key_name
|
29
|
+
}
|
30
|
+
|
31
|
+
response = @client.action "CreateKeyPair", params
|
32
|
+
|
33
|
+
Response::Credential.new response.body['CreateKeyPairResponse']
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Import a key pair
|
38
|
+
|
39
|
+
def import_public_key key_name, pubkey, fprint=nil
|
40
|
+
params = {
|
41
|
+
'KeyName' => key_name,
|
42
|
+
'PublicKey' => pubkey
|
43
|
+
}
|
44
|
+
params.merge!( 'Fingerprint' => fprint ) unless fprint.nil?
|
45
|
+
|
46
|
+
response = @client.action "ImportPublicKey", params
|
47
|
+
|
48
|
+
Response::Credential.new response.body["ImportPublicKeyResponse"]['return']
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Deletes the key pair for the given 'key_name'.
|
53
|
+
# Returns a response to the state change.
|
54
|
+
#
|
55
|
+
# +key_name+: A String containing a unique name for the key pair.
|
56
|
+
|
57
|
+
def destroy key_name
|
58
|
+
params = {
|
59
|
+
"KeyName" => key_name
|
60
|
+
}
|
61
|
+
|
62
|
+
response = @client.action "DeleteKeyPair", params
|
63
|
+
|
64
|
+
Response::Return.new response.body['DeleteKeyPairResponse']
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Resource
|
3
|
+
class Image
|
4
|
+
def initialize client
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns information about AMIs, AKIs, and ARIs. Images returned include
|
10
|
+
# public images, private images that +@client+ owns, and private images
|
11
|
+
# owned by other AWS accounts but for which +@client+ has explicit launch
|
12
|
+
# permissions.
|
13
|
+
#
|
14
|
+
# +filter+: An optional Hash, intended for filtering.
|
15
|
+
# See the API Reference for further details.
|
16
|
+
# {
|
17
|
+
# "Filter.1.Name" => "instance-type",
|
18
|
+
# "Filter.1.Value.1" => "m1.small",
|
19
|
+
# "ExecutableBy.1" => "self",
|
20
|
+
# }
|
21
|
+
|
22
|
+
def all filter = {}
|
23
|
+
response = @client.action "DescribeImages", filter
|
24
|
+
|
25
|
+
item = response.body['DescribeImagesResponse']['imagesSet']['item'].collect do |data|
|
26
|
+
Response::Image.new data
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Returns information about the given 'image_id'.
|
32
|
+
#
|
33
|
+
# +image_id+: A String representing the ID of the image.
|
34
|
+
|
35
|
+
def find image_id
|
36
|
+
params = {
|
37
|
+
"ImageId.1" => image_id
|
38
|
+
}
|
39
|
+
|
40
|
+
response = @client.action "DescribeImages", params
|
41
|
+
|
42
|
+
Response::Image.new response.body['DescribeImagesResponse']['imagesSet']['item']
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Return information about all public images.
|
47
|
+
|
48
|
+
def runnable
|
49
|
+
all.select do |image|
|
50
|
+
runnable? image
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
##
|
56
|
+
# Images which do not have a valid kernel_id are not runnable.
|
57
|
+
|
58
|
+
def runnable? image
|
59
|
+
image.is_public == "true" &&
|
60
|
+
image.kernel_id != "true" &&
|
61
|
+
image.image_type == "machine"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|