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,200 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Table of Contents - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body class="indexpage">
24
+ <h1>Table of Contents - RDoc Documentation</h1>
25
+
26
+
27
+ <h2 id="classes">Classes/Modules</h2>
28
+ <ul>
29
+ <li class="module">
30
+ <a href="Ropenstack.html">Ropenstack</a>
31
+ </li>
32
+ <li class="class">
33
+ <a href="Ropenstack/Cinder.html">Ropenstack::Cinder</a>
34
+ </li>
35
+ <li class="class">
36
+ <a href="Ropenstack/Glance.html">Ropenstack::Glance</a>
37
+ </li>
38
+ <li class="class">
39
+ <a href="Ropenstack/Keystone.html">Ropenstack::Keystone</a>
40
+ </li>
41
+ <li class="class">
42
+ <a href="Ropenstack/MalformedRequestError.html">Ropenstack::MalformedRequestError</a>
43
+ </li>
44
+ <li class="class">
45
+ <a href="Ropenstack/NotFoundError.html">Ropenstack::NotFoundError</a>
46
+ </li>
47
+ <li class="class">
48
+ <a href="Ropenstack/Nova.html">Ropenstack::Nova</a>
49
+ </li>
50
+ <li class="class">
51
+ <a href="Ropenstack/OpenstackService.html">Ropenstack::OpenstackService</a>
52
+ </li>
53
+ <li class="class">
54
+ <a href="Ropenstack/Quantum.html">Ropenstack::Quantum</a>
55
+ </li>
56
+ <li class="class">
57
+ <a href="Ropenstack/Rest.html">Ropenstack::Rest</a>
58
+ </li>
59
+ <li class="class">
60
+ <a href="Ropenstack/RopenstackError.html">Ropenstack::RopenstackError</a>
61
+ </li>
62
+ <li class="class">
63
+ <a href="Ropenstack/TimeoutError.html">Ropenstack::TimeoutError</a>
64
+ </li>
65
+ <li class="class">
66
+ <a href="Ropenstack/UnauthorisedError.html">Ropenstack::UnauthorisedError</a>
67
+ </li>
68
+
69
+ </ul>
70
+
71
+ <h2 id="methods">Methods</h2>
72
+ <ul>
73
+
74
+ <li class="method"><a href="Ropenstack/Keystone.html#method-c-new">::new &mdash; Ropenstack::Keystone</a>
75
+
76
+ <li class="method"><a href="Ropenstack/OpenstackService.html#method-c-new">::new &mdash; Ropenstack::OpenstackService</a>
77
+
78
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-action">#action &mdash; Ropenstack::Nova</a>
79
+
80
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-addEndpoint">#addEndpoint &mdash; Ropenstack::Keystone</a>
81
+
82
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-addToServices">#addToServices &mdash; Ropenstack::Keystone</a>
83
+
84
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-add_router_gateway">#add_router_gateway &mdash; Ropenstack::Quantum</a>
85
+
86
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-add_router_interface">#add_router_interface &mdash; Ropenstack::Quantum</a>
87
+
88
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-admin">#admin &mdash; Ropenstack::Keystone</a>
89
+
90
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-attach_volume">#attach_volume &mdash; Ropenstack::Nova</a>
91
+
92
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-authenticate">#authenticate &mdash; Ropenstack::Keystone</a>
93
+
94
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-build_headers">#build_headers &mdash; Ropenstack::Rest</a>
95
+
96
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-build_http">#build_http &mdash; Ropenstack::Rest</a>
97
+
98
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-create_network">#create_network &mdash; Ropenstack::Quantum</a>
99
+
100
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-create_port">#create_port &mdash; Ropenstack::Quantum</a>
101
+
102
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-create_router">#create_router &mdash; Ropenstack::Quantum</a>
103
+
104
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-create_server">#create_server &mdash; Ropenstack::Nova</a>
105
+
106
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-create_subnet">#create_subnet &mdash; Ropenstack::Quantum</a>
107
+
108
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-delete_image">#delete_image &mdash; Ropenstack::Nova</a>
109
+
110
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-delete_network">#delete_network &mdash; Ropenstack::Quantum</a>
111
+
112
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-delete_port">#delete_port &mdash; Ropenstack::Quantum</a>
113
+
114
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-delete_request">#delete_request &mdash; Ropenstack::Rest</a>
115
+
116
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-delete_router">#delete_router &mdash; Ropenstack::Quantum</a>
117
+
118
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-delete_router_gateway">#delete_router_gateway &mdash; Ropenstack::Quantum</a>
119
+
120
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-delete_router_interface">#delete_router_interface &mdash; Ropenstack::Quantum</a>
121
+
122
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-delete_server">#delete_server &mdash; Ropenstack::Nova</a>
123
+
124
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-delete_subnet">#delete_subnet &mdash; Ropenstack::Quantum</a>
125
+
126
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-detach_volume">#detach_volume &mdash; Ropenstack::Nova</a>
127
+
128
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-device_ports">#device_ports &mdash; Ropenstack::Quantum</a>
129
+
130
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-do_request">#do_request &mdash; Ropenstack::Rest</a>
131
+
132
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-error_manager">#error_manager &mdash; Ropenstack::Rest</a>
133
+
134
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-flavors">#flavors &mdash; Ropenstack::Nova</a>
135
+
136
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-getEndpoints">#getEndpoints &mdash; Ropenstack::Keystone</a>
137
+
138
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-getServices">#getServices &mdash; Ropenstack::Keystone</a>
139
+
140
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-get_request">#get_request &mdash; Ropenstack::Rest</a>
141
+
142
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-images">#images &mdash; Ropenstack::Nova</a>
143
+
144
+ <li class="method"><a href="Ropenstack/Glance.html#method-i-images">#images &mdash; Ropenstack::Glance</a>
145
+
146
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-move_port_to_subnets">#move_port_to_subnets &mdash; Ropenstack::Quantum</a>
147
+
148
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-networks">#networks &mdash; Ropenstack::Quantum</a>
149
+
150
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-ports">#ports &mdash; Ropenstack::Quantum</a>
151
+
152
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-post_request">#post_request &mdash; Ropenstack::Rest</a>
153
+
154
+ <li class="method"><a href="Ropenstack/Glance.html#method-i-put_octect">#put_octect &mdash; Ropenstack::Glance</a>
155
+
156
+ <li class="method"><a href="Ropenstack/Rest.html#method-i-put_request">#put_request &mdash; Ropenstack::Rest</a>
157
+
158
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-quotas">#quotas &mdash; Ropenstack::Nova</a>
159
+
160
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-raw">#raw &mdash; Ropenstack::Keystone</a>
161
+
162
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-routers">#routers &mdash; Ropenstack::Quantum</a>
163
+
164
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-scope_token">#scope_token &mdash; Ropenstack::Keystone</a>
165
+
166
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-servers">#servers &mdash; Ropenstack::Nova</a>
167
+
168
+ <li class="method"><a href="Ropenstack/Nova.html#method-i-servers_detailed">#servers_detailed &mdash; Ropenstack::Nova</a>
169
+
170
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-services">#services &mdash; Ropenstack::Keystone</a>
171
+
172
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-subnets">#subnets &mdash; Ropenstack::Quantum</a>
173
+
174
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-tenant_id">#tenant_id &mdash; Ropenstack::Keystone</a>
175
+
176
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-tenant_list">#tenant_list &mdash; Ropenstack::Keystone</a>
177
+
178
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-tenant_name">#tenant_name &mdash; Ropenstack::Keystone</a>
179
+
180
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-token">#token &mdash; Ropenstack::Keystone</a>
181
+
182
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-token_metadata">#token_metadata &mdash; Ropenstack::Keystone</a>
183
+
184
+ <li class="method"><a href="Ropenstack/Quantum.html#method-i-update_port">#update_port &mdash; Ropenstack::Quantum</a>
185
+
186
+ <li class="method"><a href="Ropenstack/Glance.html#method-i-upload_image_from_file">#upload_image_from_file &mdash; Ropenstack::Glance</a>
187
+
188
+ <li class="method"><a href="Ropenstack/Keystone.html#method-i-user">#user &mdash; Ropenstack::Keystone</a>
189
+
190
+ <li class="method"><a href="Ropenstack/Cinder.html#method-i-volumes">#volumes &mdash; Ropenstack::Cinder</a>
191
+
192
+ </ul>
193
+
194
+
195
+ <footer id="validator-badges">
196
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
197
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
198
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
199
+ </footer>
200
+
@@ -0,0 +1,18 @@
1
+ =begin
2
+ * Name: Ropenstack
3
+ * Description: Module used to wrap all Openstack service classes.
4
+ * Author: Sam 'Tehsmash' Betts
5
+ * Date: 01/15/2013
6
+ =end
7
+ module Ropenstack
8
+ require 'ropenstack/blockStorage'
9
+ require 'ropenstack/compute'
10
+ require 'ropenstack/database'
11
+ require 'ropenstack/identity'
12
+ require 'ropenstack/image'
13
+ require 'ropenstack/networking'
14
+ require 'ropenstack/objectStorage'
15
+ require 'ropenstack/orchestration'
16
+ require 'ropenstack/telemetry'
17
+ require 'ropenstack/common/error'
18
+ end
@@ -0,0 +1,25 @@
1
+ require 'ropenstack/common/rest'
2
+ require 'ropenstack/common/openstackservice'
3
+
4
+ module Ropenstack
5
+ ##
6
+ # * Name: BlockStorage
7
+ # * Description: Implementation of the Block Storage API Client in Ruby.
8
+ # * Author: Sam 'Tehsmash' Betts
9
+ # * Date: 01/15/2013
10
+ ##
11
+ class BlockStorage < OpenstackService
12
+ require 'ropenstack/blockStorage/v1'
13
+ require 'ropenstack/blockStorage/v2'
14
+
15
+ def initialize(location, token, type)
16
+ super(location, token)
17
+ case type
18
+ when "volume" then extend Version1
19
+ when "volumev2" then extend Version2
20
+ else
21
+ raise Ropenstack::RopenstackError, "Invalid Type Passed to BlockStorage"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,67 @@
1
+ =begin
2
+ * Name: Version1
3
+ * Description: Module used to contain the version 1 methods.
4
+ * Author: Sam 'Tehsmash' Betts
5
+ * Date: 01/15/2013
6
+ =end
7
+ module Ropenstack::BlockStorage::Version1
8
+ ##
9
+ # Gets the volumes from cinder, and provides them in a ruby hash
10
+ # with all information about them.
11
+ ##
12
+ def volumes(id = nil)
13
+ endpoint = "/volumes"
14
+ endpoint = "#{endpoint}/#{id}" unless id.nil?
15
+ return get_request(address(endpoint), @token)
16
+ end
17
+
18
+ ##
19
+ # Gets the detailed list of volumes from cinder.
20
+ ##
21
+ def volumes_detailed()
22
+ return get_request(address("/volumes/detail"), @token)
23
+ end
24
+
25
+ ##
26
+ # Gets the list of volume types from cinder.
27
+ ##
28
+ def types(id = nil)
29
+ endpoint = "/types"
30
+ endpoint = "#{endpoint}/#{id}" unless id.nil?
31
+ return get_request(address(endpoint), @token)
32
+ end
33
+
34
+ ##
35
+ # Create a new volume given size, volume_type and a name
36
+ # Optional parameters include:
37
+ # * :description -> string
38
+ # * :metadata -> array
39
+ # * :zone -> string
40
+ ##
41
+ def create_volume(display_name, size, volume_type, options = {})
42
+ data = {
43
+ "volume" => {
44
+ "display_name" => display_name,
45
+ "size" => size,
46
+ "volume_type" => volume_type
47
+ }
48
+ }
49
+
50
+ data["volume"]["display_description"] = options[:description] unless options[:description].nil?
51
+ data["volume"]["metadata"] = options[:metadata] unless options[:metadata].nil?
52
+ data["volume"]["availability_zone"] = options[:zone] unless options[:zone].nil?
53
+
54
+ return post_request(address("/volumes"), data, @token)
55
+ end
56
+
57
+ ##
58
+ # Delete a volume given an ID.
59
+ ##
60
+ def delete(id)
61
+ return delete_request(address("/volumes/#{id}"), @token)
62
+ end
63
+
64
+ def version
65
+ "V1"
66
+ end
67
+ end
@@ -0,0 +1,11 @@
1
+ =begin
2
+ * Name: Version 2
3
+ * Description: Module used to wrap all the version 2 methods
4
+ * Author: Sam 'Tehsmash' Betts
5
+ * Date: 01/15/2013
6
+ =end
7
+ module Ropenstack::BlockStorage::Version2
8
+ def version
9
+ "V2"
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Ropenstack
2
+ ## A wrapper class for Standard Error for Ropenstack Errors
3
+ class RopenstackError < StandardError; end
4
+ ## Error fired if openstack returns a Bad Request error
5
+ class MalformedRequestError < RopenstackError; end
6
+ ## Error fired if 403 Error returns from openstack
7
+ class UnauthorisedError < RopenstackError; end
8
+ ## Error fired if the connection to openstack times out
9
+ class TimeoutError < RopenstackError; end
10
+ ## Error fired if a 404 error comes back from openstack
11
+ class NotFoundError < RopenstackError; end
12
+ end
@@ -0,0 +1,28 @@
1
+ require 'ropenstack/common/rest'
2
+
3
+ module Ropenstack
4
+ =begin
5
+ * Name: OpenstackService
6
+ * Description: A parent class for all the openstack service classes, with functions
7
+ which are generic across all services.
8
+ * Author: Sam 'Tehsmash' Betts
9
+ * Date: 01/15/2013
10
+ =end
11
+ class OpenstackService < Rest
12
+ def initialize(location, token)
13
+ @location = location
14
+ @token = token
15
+ end
16
+
17
+ private
18
+
19
+ ##
20
+ # Take the location URI parsed in on creation and append
21
+ # an endpoint. Returns a new URI
22
+ ##
23
+ def address(endpoint)
24
+ uri = URI.parse(@location.to_s + endpoint)
25
+ return uri
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,138 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module Ropenstack
6
+ =begin
7
+ * Name: Rest
8
+ * Description: A generic wrapper for basic rest functions with JSON data which return ruby hashes.
9
+ * Author: Sam "Tehsmash" Betts
10
+ * Date: 12/18/2012
11
+ =end
12
+ class Rest
13
+ ##
14
+ # Build a HTTP object having been given a timeout and a URI object
15
+ # Returns Net::HTTP object.
16
+ ##
17
+ def build_http(uri, timeout)
18
+ http = Net::HTTP.new(uri.host, uri.port)
19
+ if(timeout > 0)
20
+ http.open_timeout = timeout
21
+ http.read_timeout = timeout
22
+ end
23
+ return http
24
+ end
25
+
26
+ ##
27
+ # All responses from openstack where any errors need to be caught are passed through
28
+ # this function. Unless a successful response is passed it will throw a Ropenstack
29
+ # error.
30
+ # If successful returns a hash of response body, unless response body is nil then it
31
+ # returns an empty hash.
32
+ ##
33
+ def error_manager(uri, response)
34
+ case response
35
+ when Net::HTTPSuccess then
36
+ # This covers cases where the response may not validate as JSON.
37
+ begin
38
+ data = JSON.parse(response.body)
39
+ rescue
40
+ data = {}
41
+ end
42
+ ## Get the Headers out of the response object
43
+ data['headers'] = response.to_hash()
44
+ return data
45
+ when Net::HTTPBadRequest
46
+ raise Ropenstack::MalformedRequestError, response.body
47
+ when Net::HTTPNotFound
48
+ raise Ropenstack::NotFoundError, "URI: #{uri} \n" + response.body
49
+ when Net::HTTPUnauthorized
50
+ raise Ropenstack::UnauthorisedError, response.body
51
+ else
52
+ raise Ropenstack::RopenstackError, response.body
53
+ end
54
+ end
55
+
56
+ ##
57
+ # Builds headers for requests which send JSON data, if a keystone token is supplied
58
+ # it adds the X-Auth-Token field with the keystone token.
59
+ # Returns a hash which represents the http headers in a format accepted by Net::HTTP.
60
+ ##
61
+ def build_headers(token)
62
+ headers = {'Content-Type' =>'application/json'}
63
+ unless token.nil?
64
+ headers['X-Auth-Token'] = token
65
+ end
66
+ return headers
67
+ end
68
+
69
+ ##
70
+ # The function which you call to perform a http request
71
+ # using the request object given in the parameters. By
72
+ # default manage errors is true, so all responses are passed
73
+ # through the error manager which converts the into Ropenstack errors.
74
+ ##
75
+ def do_request(uri, request, manage_errors = true, timeout = 10)
76
+ begin
77
+ http = build_http(uri, timeout)
78
+ if(manage_errors)
79
+ return error_manager(uri, http.request(request))
80
+ else
81
+ http.request(request)
82
+ return { "Success" => true }
83
+ end
84
+ rescue Timeout::Error
85
+ raise Ropenstack::TimeoutError, "It took longer than #{timeout} to connect to #{uri.to_s}"
86
+ rescue Errno::ECONNREFUSED
87
+ raise Ropenstack::TimeoutError, "It took longer than #{timeout} to connect to #{uri.to_s}"
88
+ end
89
+ end
90
+
91
+ ##
92
+ # Wrapper function for a get request, just provide a uri
93
+ # and it will return you a hash with the result data.
94
+ # For authenticated transactions a token can be provided.
95
+ # Implemented using the do_request method.
96
+ ##
97
+ def get_request(uri, token = nil, manage_errors = true)
98
+ request = Net::HTTP::Get.new(uri.request_uri, initheader = build_headers(token))
99
+ return do_request(uri, request, manage_errors)
100
+ end
101
+
102
+ ##
103
+ # Wrapper function for delete requests, just provide a uri
104
+ # and it will return you a hash with the result data.
105
+ # For authenticated transactions a token can be provided.
106
+ # Implemented using the do_request method.
107
+ ##
108
+ def delete_request(uri, token = nil, manage_errors = true)
109
+ request = Net::HTTP::Delete.new(uri.request_uri, initheader = build_headers(token))
110
+ return do_request(uri, request, manage_errors)
111
+ end
112
+
113
+ ##
114
+ # Wrapper function for a put request, just provide a uri
115
+ # and a hash of the data to send, then it will return you a hash
116
+ # with the result data.
117
+ # For authenticated transactions a token can be provided.
118
+ # Implemented using the do_request method
119
+ ##
120
+ def put_request(uri, body, token = nil, manage_errors = true)
121
+ request = Net::HTTP::Put.new(uri.request_uri, initheader = build_headers(token))
122
+ request.body = body.to_json
123
+ return do_request(uri, request, manage_errors)
124
+ end
125
+
126
+ ##
127
+ # Wrapper function for a put request, just provide a uri
128
+ # and a hash of the data to send, then it will return you a hash
129
+ # with the result data.
130
+ # For authenticated transactions a token can be provided.
131
+ ##
132
+ def post_request(uri, body, token = nil, manage_errors = true)
133
+ request = Net::HTTP::Post.new(uri.request_uri, initheader = build_headers(token))
134
+ request.body = body.to_json
135
+ return do_request(uri, request, manage_errors)
136
+ end
137
+ end
138
+ end