ropenstack 1.2.1 → 2.0.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 (113) hide show
  1. data/.gitignore +1 -0
  2. data/README.md +2 -1
  3. data/doc/Ropenstack.html +151 -0
  4. data/doc/Ropenstack/Cinder.html +197 -0
  5. data/doc/Ropenstack/Glance.html +292 -0
  6. data/doc/Ropenstack/Keystone.html +737 -0
  7. data/doc/Ropenstack/MalformedRequestError.html +142 -0
  8. data/doc/Ropenstack/NotFoundError.html +142 -0
  9. data/doc/Ropenstack/Nova.html +562 -0
  10. data/doc/Ropenstack/OpenstackService.html +199 -0
  11. data/doc/Ropenstack/Quantum.html +830 -0
  12. data/doc/Ropenstack/Rest.html +483 -0
  13. data/doc/Ropenstack/RopenstackError.html +143 -0
  14. data/doc/Ropenstack/TimeoutError.html +142 -0
  15. data/doc/Ropenstack/UnauthorisedError.html +142 -0
  16. data/doc/created.rid +10 -0
  17. data/doc/images/add.png +0 -0
  18. data/doc/images/brick.png +0 -0
  19. data/doc/images/brick_link.png +0 -0
  20. data/doc/images/bug.png +0 -0
  21. data/doc/images/bullet_black.png +0 -0
  22. data/doc/images/bullet_toggle_minus.png +0 -0
  23. data/doc/images/bullet_toggle_plus.png +0 -0
  24. data/doc/images/date.png +0 -0
  25. data/doc/images/delete.png +0 -0
  26. data/doc/images/find.png +0 -0
  27. data/doc/images/loadingAnimation.gif +0 -0
  28. data/doc/images/macFFBgHack.png +0 -0
  29. data/doc/images/package.png +0 -0
  30. data/doc/images/page_green.png +0 -0
  31. data/doc/images/page_white_text.png +0 -0
  32. data/doc/images/page_white_width.png +0 -0
  33. data/doc/images/plugin.png +0 -0
  34. data/doc/images/ruby.png +0 -0
  35. data/doc/images/tag_blue.png +0 -0
  36. data/doc/images/tag_green.png +0 -0
  37. data/doc/images/transparent.png +0 -0
  38. data/doc/images/wrench.png +0 -0
  39. data/doc/images/wrench_orange.png +0 -0
  40. data/doc/images/zoom.png +0 -0
  41. data/doc/index.html +93 -0
  42. data/doc/js/darkfish.js +153 -0
  43. data/doc/js/jquery.js +18 -0
  44. data/doc/js/navigation.js +142 -0
  45. data/doc/js/search.js +94 -0
  46. data/doc/js/search_index.js +1 -0
  47. data/doc/js/searcher.js +228 -0
  48. data/doc/rdoc.css +543 -0
  49. data/doc/table_of_contents.html +200 -0
  50. data/lib/ropenstack.rb +18 -0
  51. data/lib/ropenstack/blockStorage.rb +25 -0
  52. data/lib/ropenstack/blockStorage/v1.rb +67 -0
  53. data/lib/ropenstack/blockStorage/v2.rb +11 -0
  54. data/lib/ropenstack/common/error.rb +12 -0
  55. data/lib/ropenstack/common/openstackservice.rb +28 -0
  56. data/lib/ropenstack/common/rest.rb +138 -0
  57. data/lib/ropenstack/compute.rb +164 -0
  58. data/lib/ropenstack/compute/v2.rb +11 -0
  59. data/lib/ropenstack/compute/v2/extensions.rb +14 -0
  60. data/lib/ropenstack/compute/v2/extensions/admin.rb +0 -0
  61. data/lib/ropenstack/compute/v2/extensions/agents.rb +0 -0
  62. data/lib/ropenstack/compute/v2/extensions/aggregates.rb +0 -0
  63. data/lib/ropenstack/compute/v2/extensions/certificates.rb +0 -0
  64. data/lib/ropenstack/compute/v2/extensions/cloudpipe.rb +0 -0
  65. data/lib/ropenstack/compute/v2/extensions/console.rb +0 -0
  66. data/lib/ropenstack/compute/v2/extensions/coverage.rb +0 -0
  67. data/lib/ropenstack/compute/v2/extensions/defaultsecuritygroup.rb +0 -0
  68. data/lib/ropenstack/compute/v2/extensions/diagnostics.rb +0 -0
  69. data/lib/ropenstack/compute/v2/extensions/extraspecs.rb +0 -0
  70. data/lib/ropenstack/compute/v2/extensions/fixedips.rb +0 -0
  71. data/lib/ropenstack/compute/v2/extensions/flavors.rb +0 -0
  72. data/lib/ropenstack/compute/v2/extensions/hosts.rb +0 -0
  73. data/lib/ropenstack/compute/v2/extensions/hypervisors.rb +0 -0
  74. data/lib/ropenstack/compute/v2/extensions/images.rb +0 -0
  75. data/lib/ropenstack/compute/v2/extensions/instanceactions.rb +0 -0
  76. data/lib/ropenstack/compute/v2/extensions/interfaces.rb +0 -0
  77. data/lib/ropenstack/compute/v2/extensions/keypairs.rb +20 -0
  78. data/lib/ropenstack/compute/v2/extensions/limits.rb +0 -0
  79. data/lib/ropenstack/compute/v2/extensions/migrations.rb +0 -0
  80. data/lib/ropenstack/compute/v2/extensions/networks.rb +0 -0
  81. data/lib/ropenstack/compute/v2/extensions/quotasets.rb +0 -0
  82. data/lib/ropenstack/compute/v2/extensions/securitygroups.rb +40 -0
  83. data/lib/ropenstack/compute/v2/extensions/servergroups.rb +0 -0
  84. data/lib/ropenstack/compute/v2/extensions/serverpassword.rb +0 -0
  85. data/lib/ropenstack/compute/v2/extensions/services.rb +0 -0
  86. data/lib/ropenstack/compute/v2/extensions/shelvedservers.rb +0 -0
  87. data/lib/ropenstack/compute/v2/extensions/usage.rb +0 -0
  88. data/lib/ropenstack/compute/v2/extensions/virtualinterfaces.rb +0 -0
  89. data/lib/ropenstack/compute/v2/extensions/volumes.rb +20 -0
  90. data/lib/ropenstack/compute/v3.rb +5 -0
  91. data/lib/ropenstack/database.rb +24 -0
  92. data/lib/ropenstack/database/v1.rb +113 -0
  93. data/lib/ropenstack/identity.rb +28 -0
  94. data/lib/ropenstack/identity/v2.rb +178 -0
  95. data/lib/ropenstack/identity/v3.rb +13 -0
  96. data/lib/ropenstack/image.rb +25 -0
  97. data/lib/ropenstack/image/v1.rb +107 -0
  98. data/lib/ropenstack/image/v2.rb +134 -0
  99. data/lib/ropenstack/networking.rb +160 -0
  100. data/lib/ropenstack/networking/v2.rb +5 -0
  101. data/lib/ropenstack/networking/v2/extensions.rb +9 -0
  102. data/lib/ropenstack/networking/v2/extensions/l3.rb +111 -0
  103. data/lib/ropenstack/networking/v2/extensions/lbaas.rb +5 -0
  104. data/lib/ropenstack/networking/v2/extensions/metering.rb +5 -0
  105. data/lib/ropenstack/networking/v2/extensions/quotas.rb +5 -0
  106. data/lib/ropenstack/networking/v2/extensions/securitygroups.rb +5 -0
  107. data/lib/ropenstack/objectStorage.rb +60 -0
  108. data/lib/ropenstack/orchestration.rb +23 -0
  109. data/lib/ropenstack/orchestration/v1.rb +162 -0
  110. data/lib/ropenstack/telemetry.rb +23 -0
  111. data/lib/ropenstack/telemetry/v2.rb +68 -0
  112. data/ropenstack.gemspec +13 -0
  113. metadata +112 -1
@@ -0,0 +1,28 @@
1
+ require 'ropenstack/common/rest'
2
+
3
+ module Ropenstack
4
+ ##
5
+ # * Name: Identity
6
+ # * Description: An implementation of the Identity API Client in Ruby
7
+ # * Author: Sam 'Tehsmash' Betts, John Davidge
8
+ # * Date: 30/16/2014
9
+ ##
10
+ class Identity < OpenstackService
11
+ # Pull in sub-modules.
12
+ require 'ropenstack/identity/v2'
13
+ require 'ropenstack/identity/v3'
14
+
15
+ def initialize(location, port, token, type)
16
+ super(location + ":" + port.to_s, token)
17
+ case type
18
+ when "identityv2" then extend Version2
19
+ when "identityv3" then extend Version3
20
+ else
21
+ raise Ropenstack::RopenstackError, "Invalid Type Passed to Identity"
22
+ end
23
+ unless token.nil?
24
+ @data = { "access" => { "token" => { "id" => token } } }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,178 @@
1
+ module Ropenstack
2
+ ##
3
+ # * Name: IdentityVersion2
4
+ # * Description: An implementation of the V2.0 Identity API Client in Ruby
5
+ # * Author: Sam 'Tehsmash' Betts, John Davidge
6
+ # * Date: 30/06/2014
7
+ ##
8
+ module Identity::Version2
9
+ ##
10
+ # Authenticate via keystone, unless a token and tenant are defined then a unscoped
11
+ # token is returned with all associated data and stored in the @data variable.
12
+ # Does not return anything, but all data is accessible through accessor methods.
13
+ ##
14
+ def authenticate(username, password, tenant = nil)
15
+ data = {
16
+ "auth" => {
17
+ "passwordCredentials" => {
18
+ "username" => username,
19
+ "password" => password
20
+ }
21
+ }
22
+ }
23
+ unless tenant.nil?
24
+ data["auth"]["tenantName"] = tenant
25
+ end
26
+ @data = post_request(address("/tokens"), data, @token)
27
+ end
28
+
29
+ ##
30
+ # Scope token provides two ways to call it:
31
+ # scope_token(tenantName) => Just using the current token and a tenantName it
32
+ # scopes in the token. Token stays the same.
33
+ # scope_token(username, password, tenantName) => This uses the username and
34
+ # password to reauthenticate with a tenant. The
35
+ # token changes.
36
+ ##
37
+ def scope_token(para1, para2 = nil, para3 = nil)
38
+ if ( para2.nil? )
39
+ data = { "auth" => { "tenantName" => para1, "token" => { "id" => token() } } }
40
+ @data = post_request(address("/tokens"), data, token())
41
+ else
42
+ authenticate(para1, para2, token(), para3)
43
+ end
44
+ end
45
+
46
+ ##
47
+ # Return the raw @data hash with all the data from authentication.
48
+ ##
49
+ def raw()
50
+ return @data
51
+ end
52
+
53
+ ##
54
+ # Gets the authentication token from the hash and returns it as a string.
55
+ ##
56
+ def token(token = nil)
57
+ if token.nil?
58
+ return @data["access"]["token"]["id"]
59
+ else
60
+ get_request(address("/tokens/#{token}"), token())
61
+ end
62
+ end
63
+
64
+ ##
65
+ # TODO Add head version of tokens call
66
+ ##
67
+ def token?(token)
68
+ return false
69
+ end
70
+
71
+ ##
72
+ # This returns the token and all metadata associated with the token,
73
+ # including the tenant information.
74
+ ##
75
+ def token_metadata()
76
+ return @data["access"]["token"]
77
+ end
78
+
79
+ ##
80
+ # Return the user hash from the authentication data
81
+ ##
82
+ def user()
83
+ return @data["access"]["user"]
84
+ end
85
+
86
+ ##
87
+ # Returns true if a user is admin.
88
+ ##
89
+ def admin()
90
+ @data["access"]["user"]["roles"].each do |role|
91
+ if role["name"].eql?("admin")
92
+ return true
93
+ end
94
+ end
95
+ return false
96
+ end
97
+
98
+ ##
99
+ # Get the service catalog returned by Identity on authentication.
100
+ ##
101
+ def services()
102
+ return @data["access"]["serviceCatalog"]
103
+ end
104
+
105
+ ##
106
+ # Get the tenant id from the @data
107
+ ##
108
+ def tenant_id()
109
+ return @data["access"]["token"]["tenant"]["id"]
110
+ end
111
+
112
+ def tenant_name()
113
+ return @data["access"]["token"]["tenant"]["name"]
114
+ end
115
+
116
+ # Separate Identity Calls
117
+
118
+ def tenant_list()
119
+ return get_request(address('/tenants'), token())
120
+ end
121
+
122
+ ##
123
+ # Add a service to the keystone services directory
124
+ ##
125
+ def add_to_services(name, type, description)
126
+ data = {
127
+ 'OS-KSADM:service' => {
128
+ 'name' => name,
129
+ 'type' => type,
130
+ 'description' => description
131
+ }
132
+ }
133
+ return post_request(address("/OS-KSADM/services"), data, token())
134
+ end
135
+
136
+ ##
137
+ # Get list of services
138
+ ##
139
+ def get_services()
140
+ return get_request(address("/OS-KSADM/services"), token())
141
+ end
142
+
143
+ ##
144
+ # Add an endpoint list
145
+ ##
146
+ def add_endpoint(region, service_id, publicurl, adminurl, internalurl)
147
+ data = {
148
+ 'endpoint' => {
149
+ 'region' => region,
150
+ 'service_id' => service_id,
151
+ 'publicurl' => publicurl,
152
+ 'adminurl' => adminurl,
153
+ 'internalurl' => internalurl
154
+ }
155
+ }
156
+ return post_request(address("/endpoints"), data, token())
157
+ end
158
+
159
+ ##
160
+ # Get the endpoint list
161
+ ##
162
+ def get_endpoints(token = nil)
163
+ if token.nil?
164
+ return get_request(address("/endpoints"), token())
165
+ else
166
+ return get_request(address("/tokens/#{token}/endpoints"), token())
167
+ end
168
+ end
169
+
170
+ def address(endpoint)
171
+ super("/v2.0/" + endpoint)
172
+ end
173
+
174
+ def version
175
+ "V2"
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,13 @@
1
+ module Ropenstack
2
+ ##
3
+ # * Name: IdentityVersion3
4
+ # * Description: An implementation of the V3.0 Identity API Client in Ruby
5
+ # * Author: Sam 'Tehsmash' Betts, John Davidge
6
+ # * Date: 30/06/2014
7
+ ##
8
+ module Identity::Version3
9
+ def version
10
+ "V3"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'ropenstack/common/rest'
2
+
3
+ module Ropenstack
4
+ ##
5
+ # * Name: Image
6
+ # * Description: Implementation of the Glance API Client in Ruby
7
+ # * Author: Sam 'Tehsmash' Betts, John Davidge
8
+ # * Date: 30/06/2014
9
+ ##
10
+ class Image < OpenstackService
11
+ # Pull in sub-modules
12
+ require 'ropenstack/image/v1'
13
+ require 'ropenstack/image/v2'
14
+
15
+ def initialize(location, token, type)
16
+ super(location, token)
17
+ case type
18
+ when "image" then extend Version1
19
+ when "imagev2" then extend Version2
20
+ else
21
+ raise Ropenstack::RopenstackError, "Invalid type passed to Image"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,107 @@
1
+ module Ropenstack
2
+ ##
3
+ # * Name: ImageVersion1
4
+ # * Description: Implementation of the Glance V1.0 API Client in Ruby
5
+ # * Author: Sam 'Tehsmash' Betts, John Davidge
6
+ # * Date: 30/06/2014
7
+ ##
8
+ module Image::Version1
9
+
10
+ ##
11
+ # No ID provided - Lists details for available images.
12
+ # ID provided - Shows the image details as headers and the image binary in the body.
13
+ ##
14
+ def images(id, tenant_id)
15
+ if id.nil?
16
+ return get_request(address(tenant_id, "images/detail"), @token)
17
+ else
18
+ return get_request(address(tenant_id, "images/" + id), @token)
19
+ end
20
+ end
21
+
22
+ ##
23
+ # Registers a virtual machine image.
24
+ ##
25
+ def image_create(name, disk_format, container_format, create_image, tenant_id)
26
+ data = {
27
+ :name => name,
28
+ :disk_format => disk_format,
29
+ :container_format => container_format
30
+ }
31
+ unless create_image.nil?
32
+ data[:create_image] = create_image
33
+ end
34
+
35
+ post_request(address(tenant_id, "images"), data, @token)
36
+ end
37
+
38
+ ##
39
+ # Updates an image, uploads an image file, or updates metadata for an image.
40
+ # NOT IMPLEMENTED
41
+ ##
42
+ def image_update(id, tenant_id)
43
+ raise Ropenstack::RopenstackError, "Update Method Not Implemented."
44
+ end
45
+
46
+ ##
47
+ # Deletes the specified image.
48
+ ##
49
+ def image_delete(id, tenant_id)
50
+ delete_request(address(tenant_id, "images/" + id), @token)
51
+ end
52
+
53
+ ##
54
+ # Replaces the membership list for an image.
55
+ # @param memberships List of memberships in format [{'member_id': 'tenant1', 'can_share': 'false'}]
56
+ ##
57
+ def replace_memberships(id, memberships, tenant_id)
58
+ data = {
59
+ :memberships => memberships
60
+ }
61
+ put_request(address(tenant_id, "images/" + id + "/members"), data, @token)
62
+ end
63
+
64
+ ##
65
+ # Adds a member to an image.
66
+ # @param member_id The member to be added
67
+ # @param can_share Optional boolean specifiying can_share value. Will default to false.
68
+ ##
69
+ def add_member(id, member_id, can_share, tenant_id)
70
+ if can_share.nil?
71
+ data = {
72
+ :member => {:can_share => false}
73
+ }
74
+ else
75
+ data = {
76
+ :member => {:can_share => can_share}
77
+ }
78
+ end
79
+ put_request(address(tenant_id, "images/" + id + "/members/" + member_id), data, @token)
80
+ end
81
+
82
+ ##
83
+ # Removes a member from an image
84
+ ##
85
+ def delete_member(id, member_id, tenant_id)
86
+ delete_request(address(tenant_id, "images/" + id + "/members/" + member_id), @token)
87
+ end
88
+
89
+ ##
90
+ # Lists the images shared with a specified owner.
91
+ ##
92
+ def shared_images(id, owner_id, tenant_id)
93
+ get_request(address(tenant_id, "shared-images/" + owner_id), @token)
94
+ end
95
+
96
+ ##
97
+ # Returns the v1 address location of an endpoint.
98
+ ##
99
+ def address(tenant_id, endpoint)
100
+ address("/v1/#{tenant_id}/#{endpoint}")
101
+ end
102
+
103
+ def version
104
+ "V1"
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,134 @@
1
+ module Ropenstack
2
+ ##
3
+ # * Name: ImageVersion2
4
+ # * Description: Implementation of the Glance V2.0 API Client in Ruby
5
+ # * Author: Sam 'Tehsmash' Betts, John Davidge
6
+ # * Date: 30/06/2014
7
+ ##
8
+ module Image::Version2
9
+ ##
10
+ # Returns a list of images with all associated meta-data in
11
+ # hash format.
12
+ ##
13
+ def images(id)
14
+ if id.nil?
15
+ return get_request(address("images"), @token)["images"]
16
+ else
17
+ return get_request(address("images/" + id), @token)
18
+ end
19
+ end
20
+
21
+ def image_create(name, id, visibilty, tags)
22
+ data = {
23
+ :name => name
24
+ }
25
+ unless id.nil?
26
+ data[:id] = id
27
+ end
28
+ unless visibility.nil?
29
+ data[:visibility] = visibility
30
+ end
31
+ unless tags.nil?
32
+ data[:tags] = tags
33
+ end
34
+
35
+ post_request(address("images"), data, @token)
36
+ end
37
+
38
+ def image_delete(id)
39
+ delete_request(address("images/" + id), @token)
40
+ end
41
+
42
+ # TODO Ruby HTTP Binary Download to FILE
43
+ def image_download(id)
44
+ end
45
+
46
+ def image_add_tag(id, tag)
47
+ put_request(address("images/"+id+"/tags/"+tag), @token)
48
+ end
49
+
50
+ def image_delete_tag(id)
51
+ delete_request(address("images/"+id+"/tags/"+tag), @token)
52
+ end
53
+
54
+ ## Members
55
+ def members(id)
56
+ end
57
+
58
+ def member_add()
59
+ end
60
+
61
+ def member_delete()
62
+ end
63
+
64
+ def member_update()
65
+ end
66
+
67
+ ## Schemas
68
+ def schemas(type)
69
+ return get_request(address("schemas/" + type), @token)
70
+ end
71
+
72
+
73
+ ## BELOW HERE IS OLD CODE THAT MAY OR MAYNOT WORK, THAR BE DRAGONS
74
+
75
+ ##
76
+ # Upload an image to the Image Service from a file, takes in a ruby file object.
77
+ # More convoluted than it should be because for a bug in Quantum
78
+ # which just returns an error no matter the outcome.
79
+ ##
80
+ def upload_image_from_file(name, disk_format, container_format, minDisk, minRam, is_public, file)
81
+ data = {
82
+ "name" => name,
83
+ "disk_format" => disk_format,
84
+ "container_format" => container_format,
85
+ "minDisk" => minDisk,
86
+ "minRam" => minRam,
87
+ "public" => is_public
88
+ }
89
+ imagesBefore = images()
90
+ post_request(address("images"), data, @token, false)
91
+ imagesAfter = images()
92
+ foundNewImage = true
93
+ image = nil
94
+ imagesAfter.each do |imageA|
95
+ imagesBefore.each do |imageB|
96
+ if(imageA == imageB)
97
+ foundNewImage = false
98
+ end
99
+ end
100
+ if(foundNewImage)
101
+ image = imageA
102
+ break
103
+ end
104
+ end
105
+ return put_octect(address(image["file"]), file.read, false)
106
+ end
107
+
108
+ ##
109
+ # Special rest call for sending a file stream using an octet-stream
110
+ # main change is just custom headers.
111
+ # Still implemented using do_request function.
112
+ ##
113
+ def put_octect(uri, data, manage_errors)
114
+ headers = build_headers(@token)
115
+ headers["Content-Type"] = 'application/octet-stream'
116
+ req = Net::HTTP::Put.new(uri.request_uri, initheader = headers)
117
+ req.body = data
118
+ return do_request(uri, req, manage_errors, 0)
119
+ end
120
+
121
+ private
122
+
123
+ ##
124
+ # Function to get the v2 address location of an endpoint.
125
+ ##
126
+ def address(endpoint)
127
+ address("/v2/#{endpoint}")
128
+ end
129
+
130
+ def version
131
+ "V2"
132
+ end
133
+ end
134
+ end