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
@@ -1,65 +0,0 @@
|
|
1
|
-
module Nephophobia
|
2
|
-
class CredentialData
|
3
|
-
attr_reader :fingerprint, :material, :name
|
4
|
-
|
5
|
-
attr_accessor :attributes
|
6
|
-
|
7
|
-
def initialize attributes
|
8
|
-
@attributes = attributes
|
9
|
-
|
10
|
-
@material = attributes['keyMaterial']
|
11
|
-
@name = attributes['keyName']
|
12
|
-
@fingerprint = attributes['keyFingerprint']
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Credential
|
17
|
-
def initialize client
|
18
|
-
@client = client
|
19
|
-
end
|
20
|
-
|
21
|
-
##
|
22
|
-
# Returns information about key pairs that +@client+ owns.
|
23
|
-
|
24
|
-
def all
|
25
|
-
response = @client.action "DescribeKeyPairs", {}
|
26
|
-
|
27
|
-
key_set = response.body['DescribeKeyPairsResponse']['keySet']
|
28
|
-
key_set && Nephophobia.coerce(key_set['item']).collect do |data|
|
29
|
-
CredentialData.new data
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
##
|
34
|
-
# Create a key pair with the given 'key_name'.
|
35
|
-
# Returns information about the new key.
|
36
|
-
#
|
37
|
-
# +key_name+: A String containing a unique name for the key pair.
|
38
|
-
|
39
|
-
def create key_name
|
40
|
-
params = {
|
41
|
-
"KeyName" => key_name
|
42
|
-
}
|
43
|
-
|
44
|
-
response = @client.action "CreateKeyPair", params
|
45
|
-
|
46
|
-
CredentialData.new response.body['CreateKeyPairResponse']
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# Deletes the key pair for the given 'key_name'.
|
51
|
-
# Returns a response to the state change.
|
52
|
-
#
|
53
|
-
# +key_name+: A String containing a unique name for the key pair.
|
54
|
-
|
55
|
-
def destroy key_name
|
56
|
-
params = {
|
57
|
-
"KeyName" => key_name
|
58
|
-
}
|
59
|
-
|
60
|
-
response = @client.action "DeleteKeyPair", params
|
61
|
-
|
62
|
-
ResponseData.new response.body['DeleteKeyPairResponse']
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/lib/nephophobia/image.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
module Nephophobia
|
2
|
-
class ImageData
|
3
|
-
attr_reader :architecture, :image_id, :image_location, :image_owner_id
|
4
|
-
attr_reader :image_type, :kernel_id, :is_public, :state
|
5
|
-
|
6
|
-
attr_accessor :attributes
|
7
|
-
|
8
|
-
def initialize attributes
|
9
|
-
@attributes = attributes
|
10
|
-
|
11
|
-
@architecture = attributes['architecture']
|
12
|
-
@id = attributes['id']
|
13
|
-
@image_id = attributes['imageId']
|
14
|
-
@image_location = attributes['imageLocation']
|
15
|
-
@image_owner_id = attributes['imageOwnerId']
|
16
|
-
@image_type = attributes['imageType']
|
17
|
-
@is_public = attributes['isPublic']
|
18
|
-
@kernel_id = attributes['kernelId']
|
19
|
-
@state = attributes['imageState']
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Image
|
24
|
-
def initialize client
|
25
|
-
@client = client
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Returns information about AMIs, AKIs, and ARIs. Images returned include
|
30
|
-
# public images, private images that +@client+ owns, and private images
|
31
|
-
# owned by other AWS accounts but for which +@client+ has explicit launch
|
32
|
-
# permissions.
|
33
|
-
#
|
34
|
-
# +filter+: An optional Hash, intended for filtering.
|
35
|
-
# See the API Reference for further details.
|
36
|
-
# {
|
37
|
-
# "Filter.1.Name" => "instance-type",
|
38
|
-
# "Filter.1.Value.1" => "m1.small",
|
39
|
-
# "ExecutableBy.1" => "self",
|
40
|
-
# }
|
41
|
-
|
42
|
-
def all filter = {}
|
43
|
-
response = @client.action "DescribeImages", filter
|
44
|
-
|
45
|
-
item = response.body['DescribeImagesResponse']['imagesSet']['item'].collect do |data|
|
46
|
-
ImageData.new data
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# Returns information about the given 'image_id'.
|
52
|
-
#
|
53
|
-
# +image_id+: A String representing the ID of the image.
|
54
|
-
|
55
|
-
def find image_id
|
56
|
-
params = {
|
57
|
-
"ImageId.1" => image_id
|
58
|
-
}
|
59
|
-
|
60
|
-
response = @client.action "DescribeImages", params
|
61
|
-
|
62
|
-
ImageData.new response.body['DescribeImagesResponse']['imagesSet']['item']
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# Return information about all public images.
|
67
|
-
|
68
|
-
def runnable
|
69
|
-
all.select do |image|
|
70
|
-
runnable? image
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
##
|
76
|
-
# Images which do not have a valid kernel_id are not runnable.
|
77
|
-
|
78
|
-
def runnable? image
|
79
|
-
image.is_public == "true" &&
|
80
|
-
image.kernel_id != "true" &&
|
81
|
-
image.image_type == "machine"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/lib/nephophobia/project.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# __Must__ execute as a user with the +admin+ role.
|
3
|
-
|
4
|
-
module Nephophobia
|
5
|
-
class ProjectData
|
6
|
-
attr_reader :name, :manager_id, :description
|
7
|
-
|
8
|
-
attr_accessor :attributes
|
9
|
-
|
10
|
-
def initialize attributes
|
11
|
-
@attributes = attributes
|
12
|
-
|
13
|
-
@name = attributes['projectname']
|
14
|
-
@manager_id = attributes['projectManagerId']
|
15
|
-
@description = attributes['description']
|
16
|
-
@member = attributes['member']
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class MemberData
|
21
|
-
attr_reader :member
|
22
|
-
|
23
|
-
attr_accessor :attributes
|
24
|
-
|
25
|
-
def initialize attributes
|
26
|
-
@attributes = attributes
|
27
|
-
|
28
|
-
@member = attributes['member']
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Project
|
33
|
-
def initialize client
|
34
|
-
@client = client
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
# Adds the given 'user_name' to the specified 'project_name'.
|
39
|
-
# Returns a response to the state change.
|
40
|
-
#
|
41
|
-
# +user_name+: A String representing a nova user_name.
|
42
|
-
# +project_name+: A String representing a nova project_name name.
|
43
|
-
|
44
|
-
def add_member user_name, project_name
|
45
|
-
modify_membership user_name, "add", project_name
|
46
|
-
end
|
47
|
-
|
48
|
-
##
|
49
|
-
# Returns information about all projects, or all projects the given
|
50
|
-
# 'user_name' is in.
|
51
|
-
#
|
52
|
-
# +user_name+: An optional String representing a nova user_name.
|
53
|
-
|
54
|
-
def all user_name = nil
|
55
|
-
response = @client.action "DescribeProjects", {}
|
56
|
-
|
57
|
-
item = response.body['DescribeProjectsResponse']['projectSet']['item']
|
58
|
-
projects = Nephophobia.coerce(item).collect do |data|
|
59
|
-
ProjectData.new data
|
60
|
-
end
|
61
|
-
|
62
|
-
return projects unless user_name
|
63
|
-
projects.map { |project| project if @client.project.member? user_name, project.name }.compact
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# Creates the given 'project_name' and adds the specified 'user_name' as the manager.
|
68
|
-
# Returns a response to the state change.
|
69
|
-
#
|
70
|
-
# +project_name+: A String representing a nova project name.
|
71
|
-
# +user_name+: A String representing a nova user_name.
|
72
|
-
|
73
|
-
def create project_name, user_name
|
74
|
-
params = {
|
75
|
-
"Name" => project_name,
|
76
|
-
"ManagerUser" => user_name
|
77
|
-
}
|
78
|
-
|
79
|
-
response = @client.action "RegisterProject", params
|
80
|
-
|
81
|
-
ProjectData.new response.body['RegisterProjectResponse']
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# Removes the given 'project_name'.
|
86
|
-
# Returns a response to the state change.
|
87
|
-
#
|
88
|
-
# +project_name+: A String representing a nova project name.
|
89
|
-
|
90
|
-
def destroy project_name
|
91
|
-
response = @client.action "DeregisterProject", "Name" => project_name
|
92
|
-
|
93
|
-
ResponseData.new response.body['DeregisterProjectResponse']
|
94
|
-
end
|
95
|
-
|
96
|
-
##
|
97
|
-
# Returns information about the given 'project_name'.
|
98
|
-
#
|
99
|
-
# +project_name+: A String representing a nova project name.
|
100
|
-
|
101
|
-
def find project_name
|
102
|
-
response = @client.action "DescribeProject", "Name" => project_name
|
103
|
-
|
104
|
-
ProjectData.new response.body['DescribeProjectResponse']
|
105
|
-
rescue Hugs::Errors::BadRequest
|
106
|
-
end
|
107
|
-
|
108
|
-
##
|
109
|
-
# Returns information about all members of the given 'project_name'.
|
110
|
-
#
|
111
|
-
# +project_name+: A String representing a nova project name.
|
112
|
-
|
113
|
-
def members project_name
|
114
|
-
response = @client.action "DescribeProjectMembers", "Name" => project_name
|
115
|
-
|
116
|
-
item = response.body['DescribeProjectMembersResponse']['members']['item']
|
117
|
-
Nephophobia.coerce(item).collect do |data|
|
118
|
-
MemberData.new data
|
119
|
-
end
|
120
|
-
rescue Hugs::Errors::BadRequest
|
121
|
-
end
|
122
|
-
|
123
|
-
##
|
124
|
-
# Return a Boolean if the given 'user_name' is a member of the specified 'project_name'.
|
125
|
-
#
|
126
|
-
# +user_name+: A String representing a nova user_name.
|
127
|
-
# +project_name+: A String representing a nova project_name name.
|
128
|
-
|
129
|
-
def member? user_name, project_name
|
130
|
-
members(project_name).any? { |f| f.member == user_name }
|
131
|
-
end
|
132
|
-
|
133
|
-
##
|
134
|
-
# Removes the given 'user_name' from the specified 'project_name'.
|
135
|
-
# Returns a response to the state change.
|
136
|
-
#
|
137
|
-
# +user_name+: A String representing a nova user_name.
|
138
|
-
# +project_name+: A String representing a nova project_name name.
|
139
|
-
|
140
|
-
def remove_member user_name, project_name
|
141
|
-
modify_membership user_name, "remove", project_name
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
def modify_membership user_name, operation, project_name
|
146
|
-
params = {
|
147
|
-
"User" => user_name,
|
148
|
-
"Project" => project_name,
|
149
|
-
"Operation" => operation
|
150
|
-
}
|
151
|
-
|
152
|
-
response = @client.action "ModifyProjectMember", params
|
153
|
-
|
154
|
-
ResponseData.new response.body['ModifyProjectMemberResponse']
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
data/lib/nephophobia/role.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# __Must__ execute as a user with the +admin+ role.
|
3
|
-
|
4
|
-
module Nephophobia
|
5
|
-
class RoleData
|
6
|
-
attr_reader :name
|
7
|
-
|
8
|
-
attr_accessor :attributes
|
9
|
-
|
10
|
-
def initialize attributes
|
11
|
-
@attributes = attributes
|
12
|
-
|
13
|
-
@name = attributes['role']
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Role
|
18
|
-
DEFAULT = "sysadmin"
|
19
|
-
|
20
|
-
def initialize client
|
21
|
-
@client = client
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Returns global roles for the given 'user_name', or for the given 'project_name'.
|
26
|
-
#
|
27
|
-
# +user_name+: A String representing a nova user_name.
|
28
|
-
# +project_name+: An Optional String representing a nova project_name name.
|
29
|
-
|
30
|
-
def all user_name, project_name = nil
|
31
|
-
params = {
|
32
|
-
"User" => user_name,
|
33
|
-
}
|
34
|
-
params.merge!("Project" => project_name) if project_name
|
35
|
-
|
36
|
-
response = @client.action "DescribeUserRoles", params
|
37
|
-
|
38
|
-
roles = response.body['DescribeUserRolesResponse']['roles']
|
39
|
-
roles && Nephophobia.coerce(roles['item']).collect do |data|
|
40
|
-
RoleData.new data
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
# Adds the given 'user_name' to the global 'Role::DEFAULT', unless a
|
46
|
-
# 'role_name' is provided.
|
47
|
-
# Returns a response to the state change.
|
48
|
-
#
|
49
|
-
# +user_name+: A String representing a nova user_name.
|
50
|
-
# +project_name+: An Optional String representing a nova project_name name.
|
51
|
-
# +role_name+: An Optional String representing a nova role name.
|
52
|
-
|
53
|
-
def create user_name, project_name = nil, role_name = nil
|
54
|
-
modify_role user_name, "add", project_name, role_name
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# Removes the given 'user_name' from the global 'Role::DEFAULT', unless a
|
59
|
-
# 'role_name' is provided.
|
60
|
-
#
|
61
|
-
# +user_name+: A String representing a nova user_name.
|
62
|
-
# +project_name+: An Optional String representing a nova project_name name.
|
63
|
-
# +role_name+: An Optional String representing a nova role name.
|
64
|
-
|
65
|
-
def destroy user_name, project_name = nil, role_name = nil
|
66
|
-
modify_role user_name, "remove", project_name
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
def modify_role user_name, operation, project_name = nil, role_name = nil
|
71
|
-
params = {
|
72
|
-
"User" => user_name,
|
73
|
-
"Role" => role_name || DEFAULT,
|
74
|
-
"Operation" => operation
|
75
|
-
}
|
76
|
-
params.merge!("Project" => project_name) if project_name
|
77
|
-
|
78
|
-
response = @client.action "ModifyUserRole", params
|
79
|
-
|
80
|
-
ResponseData.new response.body['ModifyUserRoleResponse']
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/nephophobia/user.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# __Must__ execute as a user with the +admin+ role.
|
3
|
-
|
4
|
-
module Nephophobia
|
5
|
-
class UserData
|
6
|
-
attr_reader :accesskey, :username, :secretkey
|
7
|
-
|
8
|
-
attr_accessor :attributes
|
9
|
-
|
10
|
-
def initialize attributes
|
11
|
-
@attributes = attributes
|
12
|
-
|
13
|
-
@accesskey = attributes['accesskey']
|
14
|
-
@username = attributes['username']
|
15
|
-
@secretkey = attributes['secretkey']
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class User
|
20
|
-
def initialize client
|
21
|
-
@client = client
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Creates the given 'user_name'.
|
26
|
-
# Returns a response to the state change.
|
27
|
-
#
|
28
|
-
# +user_name+: A String representing a nova user_name.
|
29
|
-
|
30
|
-
def create user_name
|
31
|
-
response = @client.action "RegisterUser", "Name" => user_name
|
32
|
-
|
33
|
-
UserData.new response.body['RegisterUserResponse']
|
34
|
-
end
|
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
|
-
|
53
|
-
##
|
54
|
-
# Removes the given 'user_name'.
|
55
|
-
# Returns a response to the state change.
|
56
|
-
#
|
57
|
-
# +user_name+: A String representing a nova user_name.
|
58
|
-
|
59
|
-
def destroy user_name
|
60
|
-
response = @client.action "DeregisterUser", "Name" => user_name
|
61
|
-
|
62
|
-
ResponseData.new response.body['DeregisterUserResponse']
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# Returns information about the given 'user_name'.
|
67
|
-
#
|
68
|
-
# +user_name+: A String representing the user_name.
|
69
|
-
|
70
|
-
def find user_name
|
71
|
-
response = @client.action "DescribeUser", "Name" => user_name
|
72
|
-
|
73
|
-
UserData.new response.body['DescribeUserResponse']
|
74
|
-
rescue Hugs::Errors::BadRequest
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
# Apply a set of global and per-project permissions to the given 'user_name'.
|
79
|
-
# Do the following if the 'user_name' is not a member of the 'project_name'.
|
80
|
-
# - Add the 'user_name' with the default role (sysadmin) globally.
|
81
|
-
# - Add the 'user_name' to the 'project_name', with the default role (sysadmin).
|
82
|
-
# - Add the 'user_name' as a member to the 'project_name'
|
83
|
-
#
|
84
|
-
# +user_name+: A String representing a nova user_name.
|
85
|
-
# +project_name+: A String representing a nova project_name name.
|
86
|
-
|
87
|
-
def register user_name, project_name
|
88
|
-
unless @client.project.member? user_name, project_name
|
89
|
-
@client.role.create user_name
|
90
|
-
@client.role.create user_name, project_name
|
91
|
-
@client.project.add_member user_name, project_name
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|