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
@@ -0,0 +1,132 @@
|
|
1
|
+
##
|
2
|
+
# __Must__ execute as a user with the +admin+ role.
|
3
|
+
|
4
|
+
module Nephophobia
|
5
|
+
module Resource
|
6
|
+
class Project
|
7
|
+
def initialize client
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Adds the given 'user_name' to the specified 'project_name'.
|
13
|
+
# Returns a response to the state change.
|
14
|
+
#
|
15
|
+
# +user_name+: A String representing a nova user_name.
|
16
|
+
# +project_name+: A String representing a nova project_name name.
|
17
|
+
|
18
|
+
def add_member user_name, project_name
|
19
|
+
modify_membership user_name, "add", project_name
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Returns information about all projects, or all projects the given
|
24
|
+
# 'user_name' is in.
|
25
|
+
#
|
26
|
+
# +user_name+: An optional String representing a nova user_name.
|
27
|
+
|
28
|
+
def all user_name = nil
|
29
|
+
response = @client.action "DescribeProjects", {}
|
30
|
+
|
31
|
+
item = response.body['DescribeProjectsResponse']['projectSet']['item']
|
32
|
+
projects = Nephophobia::Util.coerce(item).collect do |data|
|
33
|
+
Response::Project.new data
|
34
|
+
end
|
35
|
+
|
36
|
+
return projects unless user_name
|
37
|
+
projects.map { |project| project if @client.project.member? user_name, project.name }.compact
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Creates the given 'project_name' and adds the specified 'user_name' as the manager.
|
42
|
+
# Returns a response to the state change.
|
43
|
+
#
|
44
|
+
# +project_name+: A String representing a nova project name.
|
45
|
+
# +user_name+: A String representing a nova user_name.
|
46
|
+
|
47
|
+
def create project_name, user_name
|
48
|
+
params = {
|
49
|
+
"Name" => project_name,
|
50
|
+
"ManagerUser" => user_name
|
51
|
+
}
|
52
|
+
|
53
|
+
response = @client.action "RegisterProject", params
|
54
|
+
|
55
|
+
Response::Project.new response.body['RegisterProjectResponse']
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Removes the given 'project_name'.
|
60
|
+
# Returns a response to the state change.
|
61
|
+
#
|
62
|
+
# +project_name+: A String representing a nova project name.
|
63
|
+
|
64
|
+
def destroy project_name
|
65
|
+
response = @client.action "DeregisterProject", "Name" => project_name
|
66
|
+
|
67
|
+
Response::Return.new response.body['DeregisterProjectResponse']
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Returns information about the given 'project_name'.
|
72
|
+
#
|
73
|
+
# +project_name+: A String representing a nova project name.
|
74
|
+
|
75
|
+
def find project_name
|
76
|
+
response = @client.action "DescribeProject", "Name" => project_name
|
77
|
+
|
78
|
+
Response::Project.new response.body['DescribeProjectResponse']
|
79
|
+
rescue Hugs::Errors::BadRequest
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Returns information about all members of the given 'project_name'.
|
84
|
+
#
|
85
|
+
# +project_name+: A String representing a nova project name.
|
86
|
+
|
87
|
+
def members project_name
|
88
|
+
response = @client.action "DescribeProjectMembers", "Name" => project_name
|
89
|
+
|
90
|
+
item = response.body['DescribeProjectMembersResponse']['members']['item']
|
91
|
+
Nephophobia::Util.coerce(item).collect do |data|
|
92
|
+
Response::Member.new data
|
93
|
+
end
|
94
|
+
rescue Hugs::Errors::BadRequest
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Return a Boolean if the given 'user_name' is a member of the specified 'project_name'.
|
99
|
+
#
|
100
|
+
# +user_name+: A String representing a nova user_name.
|
101
|
+
# +project_name+: A String representing a nova project_name name.
|
102
|
+
|
103
|
+
def member? user_name, project_name
|
104
|
+
members(project_name).any? { |f| f.member == user_name }
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Removes the given 'user_name' from the specified 'project_name'.
|
109
|
+
# Returns a response to the state change.
|
110
|
+
#
|
111
|
+
# +user_name+: A String representing a nova user_name.
|
112
|
+
# +project_name+: A String representing a nova project_name name.
|
113
|
+
|
114
|
+
def remove_member user_name, project_name
|
115
|
+
modify_membership user_name, "remove", project_name
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
def modify_membership user_name, operation, project_name
|
120
|
+
params = {
|
121
|
+
"User" => user_name,
|
122
|
+
"Project" => project_name,
|
123
|
+
"Operation" => operation
|
124
|
+
}
|
125
|
+
|
126
|
+
response = @client.action "ModifyProjectMember", params
|
127
|
+
|
128
|
+
Response::Return.new response.body['ModifyProjectMemberResponse']
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
##
|
2
|
+
# __Must__ execute as a user with the +admin+ role.
|
3
|
+
|
4
|
+
module Nephophobia
|
5
|
+
module Resource
|
6
|
+
class Role
|
7
|
+
DEFAULT = "sysadmin"
|
8
|
+
|
9
|
+
def initialize client
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Returns global roles for the given 'user_name', or for the given 'project_name'.
|
15
|
+
#
|
16
|
+
# +user_name+: A String representing a nova user_name.
|
17
|
+
# +project_name+: An Optional String representing a nova project_name name.
|
18
|
+
|
19
|
+
def all user_name=nil, project_name = nil
|
20
|
+
params = {}
|
21
|
+
params.merge!("User" => user_name) if user_name
|
22
|
+
params.merge!("Project" => project_name) if project_name
|
23
|
+
action = ( user_name ? "DescribeUserRoles" : "DescribeRoles" )
|
24
|
+
|
25
|
+
response = @client.action action, params
|
26
|
+
|
27
|
+
roles = response.body["#{action}Response"]['roles']
|
28
|
+
roles && Nephophobia::Util.coerce(roles['item']).collect do |data|
|
29
|
+
Response::Role.new data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Adds the given 'user_name' to the global 'Role::DEFAULT', unless a
|
35
|
+
# 'role_name' is provided.
|
36
|
+
# Returns a response to the state change.
|
37
|
+
#
|
38
|
+
# +user_name+: A String representing a nova user_name.
|
39
|
+
# +project_name+: An Optional String representing a nova project_name name.
|
40
|
+
# +role_name+: An Optional String representing a nova role name.
|
41
|
+
|
42
|
+
def create user_name, project_name = nil, role_name = nil
|
43
|
+
modify_role user_name, "add", project_name, role_name
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Removes the given 'user_name' from the global 'Role::DEFAULT', unless a
|
48
|
+
# 'role_name' is provided.
|
49
|
+
#
|
50
|
+
# +user_name+: A String representing a nova user_name.
|
51
|
+
# +project_name+: An Optional String representing a nova project_name name.
|
52
|
+
# +role_name+: An Optional String representing a nova role name.
|
53
|
+
|
54
|
+
def destroy user_name, project_name = nil, role_name = nil
|
55
|
+
modify_role user_name, "remove", project_name
|
56
|
+
end
|
57
|
+
|
58
|
+
def modify_role user_name, operation, project_name = nil, role_name = nil
|
59
|
+
params = {
|
60
|
+
"User" => user_name,
|
61
|
+
"Role" => role_name || DEFAULT,
|
62
|
+
"Operation" => operation
|
63
|
+
}
|
64
|
+
params.merge!("Project" => project_name) if project_name
|
65
|
+
|
66
|
+
response = @client.action "ModifyUserRole", params
|
67
|
+
|
68
|
+
Response::Return.new response.body['ModifyUserRoleResponse']
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
##
|
2
|
+
# __Must__ execute as a user with the +admin+ role.
|
3
|
+
|
4
|
+
module Nephophobia
|
5
|
+
module Resource
|
6
|
+
class User
|
7
|
+
def initialize client
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Creates the given 'user_name'.
|
13
|
+
# Returns a response to the state change.
|
14
|
+
#
|
15
|
+
# +user_name+: A String representing a nova user_name.
|
16
|
+
|
17
|
+
def create user_name
|
18
|
+
response = @client.action "RegisterUser", "Name" => user_name
|
19
|
+
|
20
|
+
Response::User.new response.body['RegisterUserResponse']
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Returns the credentials for a given 'user_name' for the specified 'project_name'.
|
25
|
+
#
|
26
|
+
# +user_name+: A String containing a nova user_name.
|
27
|
+
# +project_name+: A String containing a nova project_name name.
|
28
|
+
|
29
|
+
def credentials user_name, project_name
|
30
|
+
params = {
|
31
|
+
"Name" => user_name,
|
32
|
+
"Project" => project_name
|
33
|
+
}
|
34
|
+
|
35
|
+
response = @client.action "GenerateX509ForUser", params
|
36
|
+
|
37
|
+
Base64.decode64 response.body['GenerateX509ForUserResponse']['file']
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Removes the given 'user_name'.
|
42
|
+
# Returns a response to the state change.
|
43
|
+
#
|
44
|
+
# +user_name+: A String representing a nova user_name.
|
45
|
+
|
46
|
+
def destroy user_name
|
47
|
+
response = @client.action "DeregisterUser", "Name" => user_name
|
48
|
+
|
49
|
+
Response::Return.new response.body['DeregisterUserResponse']
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Returns information about the given 'user_name'.
|
54
|
+
#
|
55
|
+
# +user_name+: A String representing the user_name.
|
56
|
+
|
57
|
+
def find user_name
|
58
|
+
response = @client.action "DescribeUser", "Name" => user_name
|
59
|
+
|
60
|
+
Response::User.new response.body['DescribeUserResponse']
|
61
|
+
rescue Hugs::Errors::BadRequest
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Apply a set of global and per-project permissions to the given 'user_name'.
|
66
|
+
# Do the following if the 'user_name' is not a member of the 'project_name'.
|
67
|
+
# - Add the 'user_name' with the default role (sysadmin) globally.
|
68
|
+
# - Add the 'user_name' to the 'project_name', with the default role (sysadmin).
|
69
|
+
# - Add the 'user_name' as a member to the 'project_name'
|
70
|
+
#
|
71
|
+
# +user_name+: A String representing a nova user_name.
|
72
|
+
# +project_name+: A String representing a nova project_name name.
|
73
|
+
|
74
|
+
def register user_name, project_name
|
75
|
+
unless @client.project.member? user_name, project_name
|
76
|
+
@client.role.create user_name
|
77
|
+
@client.role.create user_name, project_name
|
78
|
+
@client.project.add_member user_name, project_name
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Response
|
3
|
+
class Address
|
4
|
+
attr_reader :attributes, :floating_ip, :status, :instance_id
|
5
|
+
|
6
|
+
def initialize attributes
|
7
|
+
@floating_ip = attributes['publicIp']
|
8
|
+
@instance_id = attributes['instanceId']
|
9
|
+
@status = attributes['item']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Response
|
3
|
+
class Compute
|
4
|
+
attr_reader :description, :dns_name, :image_id, :instance_id, :instance_type
|
5
|
+
attr_reader :key_name, :launch_time, :name, :owner_id, :placement
|
6
|
+
attr_reader :private_dns_name, :project_id, :public_dns_name, :state
|
7
|
+
attr_reader :ip_address, :private_ip_address
|
8
|
+
|
9
|
+
attr_accessor :attributes
|
10
|
+
|
11
|
+
def initialize attributes
|
12
|
+
@attributes = attributes
|
13
|
+
|
14
|
+
@project_id = attributes['ownerId']
|
15
|
+
item = attributes['instancesSet']['item']
|
16
|
+
item = item.first if item.is_a?(Array)
|
17
|
+
@description = item['displayDescription']
|
18
|
+
@name = item['displayName']
|
19
|
+
@key_name = item['keyName']
|
20
|
+
@instance_id = item['instanceId']
|
21
|
+
@ip_address = item['ipAddress']
|
22
|
+
@state = item['instanceState']['name']
|
23
|
+
@public_dns_name = item['publicDnsName']
|
24
|
+
@private_dns_name = item['privateDnsName']
|
25
|
+
@private_ip_address = item['privateIpAddress']
|
26
|
+
@image_id = item['imageId']
|
27
|
+
@dns_name = item['dnsName']
|
28
|
+
@launch_time = DateTime.parse(item['launchTime'])
|
29
|
+
@placement = item['placement']['availabilityZone']
|
30
|
+
@instance_type = item['instanceType']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Response
|
3
|
+
class Credential
|
4
|
+
attr_reader :fingerprint, :material, :name
|
5
|
+
|
6
|
+
attr_accessor :attributes
|
7
|
+
|
8
|
+
def initialize attributes
|
9
|
+
@attributes = attributes
|
10
|
+
|
11
|
+
@material = attributes['keyMaterial']
|
12
|
+
@name = attributes['keyName']
|
13
|
+
@fingerprint = attributes['keyFingerprint']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Response
|
3
|
+
class Image
|
4
|
+
attr_reader :architecture, :image_id, :image_location, :image_owner_id
|
5
|
+
attr_reader :image_type, :kernel_id, :is_public, :state
|
6
|
+
|
7
|
+
attr_accessor :attributes
|
8
|
+
|
9
|
+
def initialize attributes
|
10
|
+
@attributes = attributes
|
11
|
+
|
12
|
+
@architecture = attributes['architecture']
|
13
|
+
@id = attributes['id']
|
14
|
+
@image_id = attributes['imageId']
|
15
|
+
@image_location = attributes['imageLocation']
|
16
|
+
@image_owner_id = attributes['imageOwnerId']
|
17
|
+
@image_type = attributes['imageType']
|
18
|
+
@is_public = attributes['isPublic']
|
19
|
+
@kernel_id = attributes['kernelId']
|
20
|
+
@state = attributes['imageState']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Response
|
3
|
+
class Project
|
4
|
+
attr_reader :name, :manager_id, :description
|
5
|
+
|
6
|
+
attr_accessor :attributes
|
7
|
+
|
8
|
+
def initialize attributes
|
9
|
+
@attributes = attributes
|
10
|
+
|
11
|
+
@name = attributes['projectname']
|
12
|
+
@manager_id = attributes['projectManagerId']
|
13
|
+
@description = attributes['description']
|
14
|
+
@member = attributes['member']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Nephophobia
|
2
|
+
module Response
|
3
|
+
class Return
|
4
|
+
attr_reader :return, :request_id
|
5
|
+
|
6
|
+
attr_accessor :attributes
|
7
|
+
|
8
|
+
def initialize attributes
|
9
|
+
@attributes = attributes
|
10
|
+
|
11
|
+
@request_id = attributes["requestId"]
|
12
|
+
@return = attributes["return"] == "true"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|