tim 0.1.2 → 0.2.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 (74) hide show
  1. data/Gemfile +17 -0
  2. data/README.rdoc +231 -8
  3. data/app/controllers/tim/application_controller.rb +6 -3
  4. data/app/controllers/tim/base_images_controller.rb +10 -18
  5. data/app/controllers/tim/image_versions_controller.rb +10 -9
  6. data/app/controllers/tim/provider_images_controller.rb +13 -10
  7. data/app/controllers/tim/target_images_controller.rb +9 -7
  8. data/app/controllers/tim/templates_controller.rb +7 -7
  9. data/app/exceptions/tim/exceptions.rb +6 -0
  10. data/app/filters/tim/resource_link_filter.rb +56 -0
  11. data/app/models/tim/base_image.rb +7 -3
  12. data/app/models/tim/image_version.rb +4 -2
  13. data/app/models/tim/provider_image.rb +42 -6
  14. data/app/models/tim/target_image.rb +48 -9
  15. data/app/models/tim/template.rb +18 -3
  16. data/app/patches/rails/active_record/autosave_association.rb +29 -0
  17. data/app/validators/template_validator.rb +9 -5
  18. data/app/views/tim/base_images/_base_image.xml.haml +1 -0
  19. data/app/views/tim/target_images/_target_image.xml.haml +1 -0
  20. data/db/migrate/20121115151914_add_import_to_tim_base_images.rb +5 -0
  21. data/db/migrate/20121210131423_add_build_method_to_target_image.rb +5 -0
  22. data/db/migrate/20121216131814_rename_provider_account_id_attribute.rb +13 -0
  23. data/db/migrate/20121216134538_add_factory_base_image_id_to_image_versions.rb +5 -0
  24. data/lib/image_factory/model/base_image.rb +6 -0
  25. data/lib/tim/engine.rb +12 -0
  26. data/lib/tim/version.rb +1 -1
  27. data/spec/controllers/base_images_controller_spec.rb +24 -8
  28. data/spec/controllers/image_versions_controller_spec.rb +20 -7
  29. data/spec/controllers/provider_images_controller_spec.rb +19 -6
  30. data/spec/controllers/target_images_controller_spec.rb +22 -8
  31. data/spec/factories/tim/base_image.rb +5 -1
  32. data/spec/factories/tim/image_factory/target_image.rb +1 -0
  33. data/spec/factories/tim/image_version.rb +4 -0
  34. data/spec/factories/tim/provider_image.rb +4 -1
  35. data/spec/factories/tim/target_image.rb +6 -2
  36. data/spec/filters/resource_link_filter_spec.rb +158 -0
  37. data/spec/models/base_image_spec.rb +5 -5
  38. data/spec/models/dummy/pool_family_spec.rb +1 -1
  39. data/spec/models/dummy/provider_account_spec.rb +3 -1
  40. data/spec/models/dummy/provider_type_spec.rb +2 -1
  41. data/spec/models/dummy/user_spec.rb +1 -1
  42. data/spec/models/image_version_spec.rb +4 -3
  43. data/spec/models/provider_image_spec.rb +28 -5
  44. data/spec/models/target_image_spec.rb +74 -4
  45. data/spec/models/template_spec.rb +11 -2
  46. data/spec/validators/template_validator_spec.rb +10 -0
  47. data/spec/views/base_images_spec.rb +2 -1
  48. data/spec/views/provider_images_spec.rb +1 -0
  49. data/test/dummy/app/decorators/tim/controllers/base_images_controller_decorator.rb +13 -0
  50. data/test/dummy/config/database.yml +0 -3
  51. data/test/dummy/config/initializers/tim.rb +1 -1
  52. data/test/dummy/config/routes.rb +6 -1
  53. data/test/dummy/db/migrate/20121216133232_add_provider_account_id_to_provider_images.rb +5 -0
  54. data/test/dummy/db/schema.rb +28 -24
  55. data/tim.gemspec +32 -0
  56. metadata +46 -60
  57. data/test/dummy/db/development.sqlite3 +0 -0
  58. data/test/dummy/db/test.sqlite3 +0 -0
  59. data/test/dummy/log/development.log +0 -982
  60. data/test/dummy/log/test.log +0 -8629
  61. data/test/dummy/tmp/cache/assets/C7A/BB0/sprockets%2F13445f7a19078dd2df39517062aa6711 +0 -0
  62. data/test/dummy/tmp/cache/assets/C8C/CC0/sprockets%2F95d79f3b3096348427f3e4e38b5202e3 +0 -0
  63. data/test/dummy/tmp/cache/assets/CB0/2B0/sprockets%2F79106b90879c02a115d7f6f1c8390ac4 +0 -0
  64. data/test/dummy/tmp/cache/assets/CE0/690/sprockets%2F04c628c2a636286bfa92a4966b82b92a +0 -0
  65. data/test/dummy/tmp/cache/assets/D03/040/sprockets%2Fd9e94204d4b307145f12efc109b16c1f +0 -0
  66. data/test/dummy/tmp/cache/assets/D06/DC0/sprockets%2Fcd282851b6e4c463409ba3ece67e0510 +0 -0
  67. data/test/dummy/tmp/cache/assets/D23/5F0/sprockets%2F2a521f3183c6bbcd71bd26a5490b201e +0 -0
  68. data/test/dummy/tmp/cache/assets/D64/3A0/sprockets%2F56ac1aed10c39b12a88cb1b30f668f58 +0 -0
  69. data/test/dummy/tmp/cache/assets/D69/BD0/sprockets%2F0aaf75cf34556b33a9fec534fe4d0415 +0 -0
  70. data/test/dummy/tmp/cache/assets/D87/D80/sprockets%2Fefa3c8b210e87358c7add88cd6f49597 +0 -0
  71. data/test/dummy/tmp/cache/assets/D89/200/sprockets%2Ff9b4e953c874ed6a87de6490d055d9db +0 -0
  72. data/test/dummy/tmp/cache/assets/DF4/430/sprockets%2F403bb1de60cae4325cebd7e6c389b8ad +0 -0
  73. data/test/dummy/tmp/cache/assets/E00/500/sprockets%2Faaddc5b6f2cb6b98930cc54cf4c64a95 +0 -0
  74. data/test/dummy/tmp/cache/assets/EB3/CE0/sprockets%2Fd75a89c9fffacd99bce7eed96844eafc +0 -0
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source :rubygems
2
+
3
+ # Declare your gem's dependencies in tim.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ #gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
@@ -26,18 +26,162 @@ cd test/dummy; rails s
26
26
 
27
27
  == API Reference
28
28
 
29
+ === Templates
30
+
31
+ ==== Create Template
32
+
33
+ Request
34
+
35
+ curl -X POST --header "Accept: application/xml" --header "Content-Type: application/xml" --data "
36
+ <template>
37
+ <name>mock</name>
38
+ <os>
39
+ <name>RHEL-6</name>
40
+ <version>1</version>
41
+ <arch>x86_64</arch>
42
+ <install type=\"iso\">
43
+ <iso>http://mockhost/RHELMock1-x86_64-DVD.iso</iso>
44
+ </install>
45
+ <rootpw>password</rootpw>
46
+ </os>
47
+ <description>Mock Template</description>
48
+ </template>
49
+ " http://localhost:3000/tim/templates
50
+
51
+ Response
52
+
53
+ Code: 201
54
+
55
+ Body:
56
+
57
+ <template href='http://localhost:3000/tim/templates/34' id='34'>
58
+ <name>mock</name><os>
59
+ <name>RHEL-6</name>
60
+ <version>1</version>
61
+ <arch>x86_64</arch>
62
+ <install type="iso">
63
+ <iso>http://mockhost/RHELMock1-x86_64-DVD.iso</iso>
64
+ </install>
65
+ <rootpw>password</rootpw>
66
+ </os><description>Mock Template</description>
67
+ <base_images>
68
+ </base_images>
69
+ <custom_content>custom</custom_content>
70
+ </template>
71
+
72
+
73
+ === Show Template
74
+
75
+ Request
76
+
77
+ curl --header "Accept:application/xml" http://localhost:3000/tim/templates/34
78
+
79
+ Response
80
+
81
+ Code: 200
82
+
83
+ Body:
84
+
85
+ <template href='http://localhost:3000/tim/templates/34' id='34'>
86
+ <name>mock</name><os>
87
+ <name>RHEL-6</name>
88
+ <version>1</version>
89
+ <arch>x86_64</arch>
90
+ <install type="iso">
91
+ <iso>http://mockhost/RHELMock1-x86_64-DVD.iso</iso>
92
+ </install>
93
+ <rootpw>password</rootpw>
94
+ </os><description>Mock Template</description>
95
+ <base_images>
96
+ </base_images>
97
+ <custom_content>custom</custom_content>
98
+ </template>
99
+
100
+ === List Templates
101
+
102
+ Request
103
+
104
+ curl --header "Accept:application/xml" http://localhost:3000/tim/templates
105
+
106
+ Response
107
+
108
+ Code: 200
109
+
110
+ Body:
111
+
112
+ <templates>
113
+ <template href='http://localhost:3000/tim/templates/33' id='33'></template>
114
+ <template href='http://localhost:3000/tim/templates/35' id='35'></template>
115
+ <template href='http://localhost:3000/tim/templates/36' id='36'></template>
116
+ </templates>
117
+
118
+ === Update Template - Not Allowed
119
+
120
+ === Delete Template
121
+
122
+ Request
123
+
124
+ curl -X DELETE --header "Accept: application/xml" http://localhost:3000/tim/templates/34
125
+
126
+ Response
127
+
128
+ Code: 204
129
+
130
+ Body:
131
+
29
132
  === Base Images
30
133
 
31
- ==== Create Base Image
134
+ ==== Create Base Image with Template
135
+
136
+ ===== with Existing Template
32
137
 
33
138
  Request
34
139
 
35
- curl -X POST --header "Accept: application/xml" --header \
36
- "Content-Type: application/xml" http://localhost:3000/tim/base_images --data \
37
- "<base_image>
140
+ curl -X POST --header "Accept: application/xml" --header "Content-Type: application/xml" --data "
141
+ <base_image>
142
+ <name>MyFirstBaseImage</name>
143
+ <description>This is my very first base image</description>
144
+ <template href='http://localhost:3000/tim/templates/3' id='3'></template>
145
+ </base_image>
146
+ " http://localhost:3000/tim/base_images
147
+
148
+ Response
149
+
150
+ Code: 201
151
+
152
+ Body:
153
+
154
+ <base_image href='http://localhost:3000/tim/base_images/15' id='15'>
155
+ <name>MyFirstBaseImage</name>
156
+ <description>This is my very first base image</description>
157
+ <template href='http://localhost:3000/tim/templates/36' id='36'></template>
158
+ <image_versions>
159
+ </image_versions>
160
+ </base_image>
161
+
162
+ ===== with New Template
163
+
164
+ Request
165
+
166
+ curl -X POST --header "Accept: application/xml" --header "Content-Type: application/xml" --data "
167
+ <base_image>
38
168
  <name>MyFirstBaseImage</name>
39
169
  <description>This is my very first base image</description>
40
- </base_image>"
170
+ <template>
171
+ <name>mock</name>
172
+ <os>
173
+ <name>RHEL-6</name>
174
+ <version>1</version>
175
+ <arch>x86_64</arch>
176
+ <install type=\"iso\">
177
+ <iso>http://mockhost/RHELMock1-x86_64-DVD.iso</iso>
178
+ </install>
179
+ <rootpw>password</rootpw>
180
+ </os>
181
+ <description>Mock Template</description>
182
+ </template>
183
+ </base_image>
184
+ " http://localhost:3000/tim/base_images
41
185
 
42
186
  Response
43
187
 
@@ -45,10 +189,88 @@ Response
45
189
 
46
190
  Body:
47
191
 
48
- <base_image href='http://localhost:3000/tim/base_images/1' id='1'>
192
+ <base_image href='http://localhost:3000/tim/base_images/15' id='15'>
49
193
  <name>MyFirstBaseImage</name>
50
194
  <description>This is my very first base image</description>
195
+ <template href='http://localhost:3000/tim/templates/36' id='36'></template>
196
+ <image_versions>
197
+ </image_versions>
198
+ </base_image>
199
+
200
+
201
+ ==== Create Base Image with Template, a single Image Version with a Single Target Image
202
+
203
+ Request
204
+
205
+ curl -X POST --header "Accept: application/xml" --header "Content-Type: application/xml" --data "
206
+ <base_image>
207
+ <name>MyFirstBaseImage</name>
208
+ <description>ThisIsABaseImage</description>
209
+ <template>
210
+ <name>mock</name>
211
+ <os>
212
+ <name>RHEL-6</name>
213
+ <version>1</version>
214
+ <arch>x86_64</arch>
215
+ <install type=\"iso\">
216
+ <iso>http://mockhost/RHELMock1-x86_64-DVD.iso</iso>
217
+ </install>
218
+ <rootpw>password</rootpw>
219
+ </os>
220
+ <description>Mock Template</description>
221
+ </template>
222
+ <image_versions type='array'>
223
+ <image_version>
224
+ <target_images type='array'>
225
+ <target_image>
226
+ <target>MockSphere</target>
227
+ </target_image>
228
+ </target_images>
229
+ </image_version>
230
+ </image_versions>
231
+ </base_image>
232
+ " http://localhost:3000/tim/base_images
233
+
234
+ Response
235
+
236
+ Code: 201
237
+
238
+ Body:
239
+
240
+ <base_image href='http://localhost:3000/tim/base_images/16' id='16'>
241
+ <name>MyFirstBaseImage</name>
242
+ <description>ThisIsABaseImage</description>
243
+ <template href='http://localhost:3000/tim/templates/37' id='37'></template>
244
+ <image_versions>
245
+ <image_version href='http://localhost:3000/tim/image_versions/12' id='12'></image_version>
246
+ </image_versions>
247
+ </base_image>
248
+
249
+ ==== Import Image
250
+
251
+ curl -X POST --header "Accept: application/xml" --header "Content-Type: application/xml" --data "
252
+ <base_image>
253
+ <name>MyFirstBaseImage</name>
254
+ <description>This is my very first base image</description>
255
+ <template href='http://localhost:3000/tim/templates/3' id='3'></template>
256
+ <import>true</import>
257
+ <image_versions type='array'>
258
+ <image_version>
259
+ <target_images type='array'>
260
+ <target_image>
261
+ <target>ec2</target>
262
+ <provider_images type='array'>
263
+ <provider_image>
264
+ <provider>Amazon EC2</provider>
265
+ <external_image_id>ami-123456</external_image_id>
266
+ </provider_image>
267
+ </provider_images>
268
+ </target_image>
269
+ </target_images>
270
+ </image_version>
271
+ </image_versions>
51
272
  </base_image>
273
+ " http://localhost:3000/tim/base_images
52
274
 
53
275
  ==== Show Base Image
54
276
 
@@ -66,6 +288,7 @@ Response
66
288
  <name>MyFirstBaseImage</name>
67
289
  <description>This is my very first base image</description>
68
290
  <image_versions>
291
+ <image_version href='http://localhost:3000/tim/image_versions/1' id='1'></image_version>
69
292
  </image_versions>
70
293
  </base_image>
71
294
 
@@ -91,7 +314,7 @@ Response
91
314
 
92
315
  Request
93
316
 
94
- curl -X DELETE--header "Accept: application/xml" http://localhost:3000/tim/base_images/1
317
+ curl -X DELETE --header "Accept: application/xml" http://localhost:3000/tim/base_images/1
95
318
 
96
319
  Response
97
320
 
@@ -108,7 +331,7 @@ Request
108
331
  curl -X POST --header "Accept: application/xml" --header \
109
332
  "Content-Type: application/xml" http://localhost:3000/tim/image_versions --data \
110
333
  "<image_version>
111
- <base_image id='1'></base_image>
334
+ <base_image id='3'></base_image>
112
335
  </image_version>"
113
336
 
114
337
  Response
@@ -1,10 +1,8 @@
1
1
  module Tim
2
2
  class ApplicationController < ::ApplicationController
3
- protect_from_forgery
4
-
5
3
  respond_to :html, :xml
6
4
 
7
- self.responder = CustomResponder
5
+ append_before_filter :set_default_respond_options
8
6
 
9
7
  # FIXME Remove filter once support for custom XML with nested resources is
10
8
  # supported by rails.
@@ -15,5 +13,10 @@ module Tim
15
13
  def render_not_found
16
14
  render :nothing => true, :status => :not_found
17
15
  end
16
+
17
+ private
18
+ def set_default_respond_options
19
+ @respond_options = { :responder => CustomResponder } unless defined? @respond_options
20
+ end
18
21
  end
19
22
  end
@@ -2,26 +2,27 @@ require 'nokogiri'
2
2
 
3
3
  module Tim
4
4
  class BaseImagesController < Tim::ApplicationController
5
- append_before_filter :set_template_xml, :only => [:create, :update]
5
+ prepend_before_filter ResourceLinkFilter.new({ :base_image => :template }),
6
+ :only => [:create]
6
7
 
7
8
  def index
8
9
  @base_images = Tim::BaseImage.all unless defined? @base_images
9
- respond_with @base_images
10
+ respond_with(@base_images, @respond_options)
10
11
  end
11
12
 
12
13
  def show
13
14
  @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
14
- respond_with @base_image
15
+ respond_with(@base_image, @respond_options)
15
16
  end
16
17
 
17
18
  def new
18
- @base_image = Tim::BaseImage.new
19
- respond_with @base_image
19
+ @base_image = Tim::BaseImage.new unless defined? @base_image
20
+ respond_with(@base_image, @respond_options)
20
21
  end
21
22
 
22
23
  def edit
23
24
  @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
24
- respond_with @base_image
25
+ respond_with(@base_image, @respond_options)
25
26
  end
26
27
 
27
28
  def create
@@ -29,7 +30,7 @@ module Tim
29
30
  if @base_image.save
30
31
  flash[:notice] = "Successfully created Base Image"
31
32
  end
32
- respond_with @base_image
33
+ respond_with(@base_image, @respond_options)
33
34
  end
34
35
 
35
36
  def update
@@ -37,22 +38,13 @@ module Tim
37
38
  if @base_image.update_attributes(params[:base_image])
38
39
  flash[:notice] = "Successfully updated Base Image"
39
40
  end
40
- respond_with @base_image
41
+ respond_with(@base_image, @respond_options)
41
42
  end
42
43
 
43
44
  def destroy
44
45
  @base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
45
46
  @base_image.destroy
46
- respond_with(@base_image)
47
- end
48
-
49
- private
50
- # Handles the cases when the template xml is supplied within request
51
- def set_template_xml
52
- doc = ::Nokogiri::XML request.body.read
53
- if !doc.xpath("//base_image/template").empty?
54
- params[:base_image][:template] = { :xml => doc.xpath("//base_image/template").children.to_s}
55
- end
47
+ respond_with(@base_image, @respond_options)
56
48
  end
57
49
 
58
50
  end
@@ -1,25 +1,26 @@
1
1
  module Tim
2
2
  class ImageVersionsController < Tim::ApplicationController
3
+ prepend_before_filter ResourceLinkFilter.new({ :image_version => :base_image }),
4
+ :only => [:create]
3
5
 
4
6
  def index
5
7
  @image_versions = Tim::ImageVersion.all unless defined? @image_versions
6
- respond_with @image_versions
8
+ respond_with(@image_versions, @respond_options)
7
9
  end
8
10
 
9
11
  def show
10
12
  @image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
11
- respond_with @image_version
13
+ respond_with(@image_version, @respond_options)
12
14
  end
13
15
 
14
16
  def new
15
17
  @image_version = Tim::ImageVersion.new unless defined? @image_version
16
- @image_version = Tim::ImageVersion.new
17
- respond_with @image_version
18
+ respond_with(@image_version, @respond_options)
18
19
  end
19
20
 
20
21
  def edit
21
22
  @image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
22
- respond_with @image_version
23
+ respond_with(@image_version, @respond_options)
23
24
  end
24
25
 
25
26
  def create
@@ -27,7 +28,7 @@ module Tim
27
28
  if @image_version.save
28
29
  flash[:notice] = 'Image version was successfully created.'
29
30
  end
30
- respond_with @image_version
31
+ respond_with(@image_version, @respond_options)
31
32
  end
32
33
 
33
34
  def update
@@ -35,14 +36,14 @@ module Tim
35
36
  if @image_version.update_attributes(params[:image_version])
36
37
  flash[:notice] = 'Image version was successfully updated.'
37
38
  end
38
- respond_with @image_version
39
+ respond_with(@image_version, @respond_options)
39
40
  end
40
41
 
41
42
  def destroy
42
43
  @image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
43
44
  @image_version.destroy
44
- respond_with @image_version
45
+ respond_with(@image_version, @respond_options)
45
46
  end
46
47
 
47
48
  end
48
- end
49
+ end
@@ -2,34 +2,36 @@ module Tim
2
2
  class ProviderImagesController < Tim::ApplicationController
3
3
  respond_to :json, :only => :update
4
4
 
5
+ prepend_before_filter ResourceLinkFilter.new({ :provider_image => :target_image }),
6
+ :only => [:create]
5
7
  before_filter :factory_keys, :only => :update
6
8
 
7
9
  def index
8
10
  @provider_images = Tim::ProviderImage.all unless defined? @provider_images
9
- respond_with @provider_images
11
+ respond_with(@provider_images, @respond_options)
10
12
  end
11
13
 
12
14
  def show
13
15
  @provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
14
- respond_with @provider_image
16
+ respond_with(@provider_image, @respond_options)
15
17
  end
16
18
 
17
19
  def new
18
20
  @provider_image = Tim::ProviderImage.new
19
- respond_with @provider_image
21
+ respond_with(@provider_image, @respond_options)
20
22
  end
21
23
 
22
24
  def edit
23
25
  @provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
24
- respond_with @provider_image
26
+ respond_with(@provider_image, @respond_options)
25
27
  end
26
28
 
27
29
  def create
28
30
  @provider_image = ProviderImage.new(params[:provider_image]) unless defined? @provider_image
29
31
  if @provider_image.save
30
- flash[:notice] = 'Image version was successfully created.'
32
+ flash[:notice] = 'Provider image was successfully created.'
31
33
  end
32
- respond_with @provider_image
34
+ respond_with(@provider_image, @respond_options)
33
35
  end
34
36
 
35
37
  def update
@@ -37,13 +39,13 @@ module Tim
37
39
  if @provider_image.update_attributes(params[:provider_image])
38
40
  flash[:notice] = 'Provider image was successfully updated.'
39
41
  end
40
- respond_with @provider_image
42
+ respond_with(@provider_image, @respond_options)
41
43
  end
42
44
 
43
45
  def destroy
44
46
  @provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
45
47
  @provider_image.destroy
46
- respond_with @provider_image
48
+ respond_with(@provider_image, @respond_options)
47
49
  end
48
50
 
49
51
  private
@@ -52,8 +54,9 @@ module Tim
52
54
  if params[:provider_image][:percent_complete] && params[:provider_image][:status_detail][:activity]
53
55
  params[:provider_image] = { :progress => params[:provider_image][:percent_complete],
54
56
  :status_detail => params[:provider_image][:status_detail][:activity],
55
- :status => params[:provider_image][:status] }
57
+ :status => params[:provider_image][:status],
58
+ :external_image_id => params[:provider_image][:identifier_on_provider] }
56
59
  end
57
60
  end
58
61
  end
59
- end
62
+ end