aeolus-image 0.0.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/COPYING +161 -0
  2. data/Rakefile +32 -19
  3. data/lib/aeolus_image.rb +35 -0
  4. data/lib/aeolus_image/active_resource_oauth_client.rb +62 -0
  5. data/lib/aeolus_image/import.rb +44 -0
  6. data/lib/aeolus_image/model/factory/base.rb +93 -0
  7. data/lib/aeolus_image/model/factory/build.rb +23 -0
  8. data/lib/aeolus_image/model/factory/builder.rb +46 -0
  9. data/lib/aeolus_image/model/factory/image.rb +23 -0
  10. data/lib/aeolus_image/model/factory/provider_image.rb +35 -0
  11. data/lib/aeolus_image/model/factory/target_image.rb +45 -0
  12. data/lib/aeolus_image/model/warehouse/icicle.rb +60 -0
  13. data/lib/aeolus_image/model/warehouse/image.rb +135 -0
  14. data/lib/aeolus_image/model/warehouse/image_build.rb +60 -0
  15. data/lib/aeolus_image/model/warehouse/provider_image.rb +36 -0
  16. data/lib/aeolus_image/model/warehouse/target_image.rb +53 -0
  17. data/lib/aeolus_image/model/warehouse/template.rb +35 -0
  18. data/lib/aeolus_image/model/warehouse/warehouse_client.rb +201 -0
  19. data/lib/aeolus_image/model/warehouse/warehouse_model.rb +236 -0
  20. data/spec/aeolus_image/model/factory/provider_image_spec.rb +12 -0
  21. data/spec/models/factory/base_spec.rb +94 -0
  22. data/spec/models/factory/builder_spec.rb +31 -0
  23. data/spec/models/factory/provider_image_spec.rb +21 -0
  24. data/spec/models/factory/target_image_spec.rb +21 -0
  25. data/spec/models/warehouse/image_build_spec.rb +189 -0
  26. data/spec/models/warehouse/image_spec.rb +241 -0
  27. data/spec/models/warehouse/provider_image_spec.rb +115 -0
  28. data/spec/models/warehouse/target_image_spec.rb +180 -0
  29. data/spec/models/warehouse/template_spec.rb +76 -0
  30. data/spec/models/warehouse/warehouse_client_spec.rb +445 -0
  31. data/spec/models/warehouse/warehouse_model_spec.rb +94 -0
  32. data/spec/spec_helper.rb +34 -47
  33. data/spec/vcr/cassettes/builder.yml +24 -0
  34. data/spec/vcr/cassettes/oauth.yml +80 -0
  35. data/spec/vcr/cassettes/oauth_fail_invalid.yml +30 -0
  36. data/spec/vcr/cassettes/oauth_fail_no.yml +22 -0
  37. data/spec/vcr/cassettes/oauth_success_valid.yml +30 -0
  38. data/spec/vcr_setup.rb +26 -0
  39. metadata +70 -46
  40. data/bin/aeolus-image +0 -6
  41. data/examples/aeolus-cli +0 -9
  42. data/examples/custom_repo.tdl +0 -18
  43. data/examples/image_description.xml +0 -3
  44. data/examples/tdl.rng +0 -207
  45. data/lib/base_command.rb +0 -134
  46. data/lib/build_command.rb +0 -68
  47. data/lib/config_parser.rb +0 -212
  48. data/lib/delete_command.rb +0 -9
  49. data/lib/import_command.rb +0 -44
  50. data/lib/list_command.rb +0 -141
  51. data/lib/push_command.rb +0 -72
  52. data/man/aeolus-image-build.1 +0 -36
  53. data/man/aeolus-image-import.1 +0 -57
  54. data/man/aeolus-image-list.1 +0 -80
  55. data/man/aeolus-image-push.1 +0 -40
  56. data/man/aeolus-image.1 +0 -16
  57. data/spec/base_command_spec.rb +0 -76
  58. data/spec/build_command_spec.rb +0 -63
  59. data/spec/config_parser_spec.rb +0 -82
  60. data/spec/import_command_spec.rb +0 -43
  61. data/spec/list_command_spec.rb +0 -21
  62. data/spec/push_command_spec.rb +0 -56
  63. data/spec/spec.opts +0 -3
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Aeolus
17
+ module Image
18
+ module Factory
19
+ class Build < Base
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Aeolus
17
+ module Image
18
+ module Factory
19
+ class Builder < Base
20
+ ACTIVE_STATES = ['FAILED', 'COMPLETED']
21
+
22
+ def find_active_build(build_id, target)
23
+ builders.find {|b| !ACTIVE_STATES.include?(b.status) && b.operation == 'build' && b.build_id == build_id && b.target == target}
24
+ end
25
+
26
+ def find_active_build_by_imageid(image_id, target)
27
+ builders.find {|b| !ACTIVE_STATES.include?(b.status) && b.operation == 'build' && b.image_id == image_id && b.target == target}
28
+ end
29
+
30
+ def find_active_push(target_image_id, provider, account)
31
+ builders.find {|b| !ACTIVE_STATES.include?(b.status) && b.operation == 'push' && b.target_image_id == target_image_id &&
32
+ b.provider == provider && b.provider_account_identifier == account}
33
+ end
34
+
35
+ def failed_build_count(build_id, target)
36
+ builders.count {|b| b.status == 'FAILED' && b.operation == 'build' && b.build_id == build_id && b.target == target}
37
+ end
38
+
39
+ def failed_push_count(target_image_id, provider, account)
40
+ builders.count {|b| b.status == 'FAILED' && b.operation == 'push' && b.target_image_id == target_image_id &&
41
+ b.provider == provider && b.provider_account_identifier == account}
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Aeolus
17
+ module Image
18
+ module Factory
19
+ class Image < Base
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Aeolus
17
+ module Image
18
+ module Factory
19
+ class ProviderImage < Base
20
+ def self.status(id)
21
+ begin
22
+ builder = Aeolus::Image::Factory::Builder.find(id)
23
+ if builder.operation == "push"
24
+ builder.status
25
+ else
26
+ nil
27
+ end
28
+ rescue ActiveResource::ResourceNotFound
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Aeolus
17
+ module Image
18
+ module Factory
19
+ class TargetImage < Base
20
+ attr_accessor :target
21
+
22
+ def self.status(id)
23
+ begin
24
+ builder = Aeolus::Image::Factory::Builder.find(id)
25
+ if builder.operation == "build"
26
+ builder.status
27
+ else
28
+ nil
29
+ end
30
+ rescue ActiveResource::ResourceNotFound
31
+ nil
32
+ end
33
+ end
34
+
35
+ def target
36
+ begin
37
+ @target = @target.nil? ? Aeolus::Image::Factory::Builder.find(id).target : @target
38
+ rescue ActiveResource::ResourceNotFound
39
+ nil
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,60 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Aeolus
16
+ module Image
17
+ module Warehouse
18
+ class Icicle < WarehouseModel
19
+ @bucket_name = 'icicles'
20
+
21
+ def packages
22
+ unless @packages
23
+ begin
24
+ package_elems = get_icicle.xpath('icicle/packages/package')
25
+ @packages = package_elems.map { |node| node.attributes['name'].text }
26
+ rescue
27
+ @packages = []
28
+ end
29
+ end
30
+ @packages
31
+ end
32
+
33
+ def description
34
+ unless @description
35
+ begin
36
+ @description = get_icicle.xpath('icicle/description').text
37
+ rescue
38
+ @description = []
39
+ end
40
+ end
41
+ @description
42
+ end
43
+
44
+ def get_icicle
45
+ unless @icicle_xml
46
+ icicle = Icicle.bucket.objects.find(@uuid) if @uuid
47
+ begin
48
+ @icicle_xml = Nokogiri::XML icicle.first.body
49
+ rescue
50
+ @icicle_xml = Nokogiri::XML '<icicle></icicle>'
51
+ end
52
+ end
53
+ @icicle_xml
54
+ end
55
+
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,135 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Aeolus
16
+ module Image
17
+ module Warehouse
18
+ class Image < WarehouseModel
19
+ OS = Struct.new(:name, :version, :arch)
20
+
21
+ @bucket_name = 'images'
22
+
23
+ def initialize(obj)
24
+ super
25
+ @xml_body = Nokogiri::XML obj.body
26
+ end
27
+
28
+ # This can now return nil
29
+ def template_xml
30
+ unless @template_xml
31
+ begin
32
+ # if an image is directly associated with template, use this
33
+ if @template
34
+ @template_xml = Template.find(@template).xml_body
35
+ else
36
+ @template_xml = Nokogiri::XML image_builds.first.target_images.first.target_template.body
37
+ end
38
+ rescue
39
+ @template_xml = nil
40
+ end
41
+ end
42
+ @template_xml
43
+ end
44
+
45
+ def latest_pushed_build
46
+ ImageBuild.find(@latest_build) if @latest_build
47
+ end
48
+
49
+ def latest_pushed_or_unpushed_build
50
+ build = @latest_build ? ImageBuild.find(@latest_build) : nil
51
+ push = @latest_unpushed ? ImageBuild.find(@latest_unpushed) : nil
52
+ if build and push
53
+ return push.timestamp > build.timestamp ? push : build
54
+ end
55
+ return build || push || nil
56
+ end
57
+
58
+ def image_builds
59
+ ImageBuild.where("($image == \"" + @uuid.to_s + "\")")
60
+ end
61
+
62
+ # Return all Provider Images associated with this Image
63
+ def provider_images
64
+ provider_images = []
65
+ image_builds.each do |b|
66
+ provider_images = provider_images + b.provider_images
67
+ end
68
+ provider_images
69
+ end
70
+
71
+ #TODO: We should get the image fields from the object body once we have it defined.
72
+ def name
73
+ unless @name
74
+ @name = @xml_body.xpath("/image/name").text
75
+ if @name.empty?
76
+ @name = template_xml.xpath("/template/name").text
77
+ end
78
+ end
79
+ @name
80
+ end
81
+
82
+ def os
83
+ unless @os
84
+ @os = OS.new(template_xpath("/template/os/name"), template_xpath("/template/os/version"), template_xpath("/template/os/arch"))
85
+ end
86
+ @os
87
+ end
88
+
89
+ def description
90
+ unless @description
91
+ @description = template_xpath("/template/description")
92
+ end
93
+ @description
94
+ end
95
+
96
+ def environment
97
+ @environment
98
+ end
99
+
100
+ # Delete this image and all child objects
101
+ def delete!
102
+ begin
103
+ image_builds.each do |build|
104
+ build.delete!
105
+ end
106
+ rescue NoMethodError
107
+ end
108
+ Image.delete(@uuid)
109
+ end
110
+
111
+ # No template is created on imported images
112
+ def imported?
113
+ !@template
114
+ end
115
+
116
+ # template_xml.xpath(PATH).text => template_xpath(PATH)
117
+ # Rescues exceptions and returns an empty string if necessary
118
+ def template_xpath(path)
119
+ xml = template_xml
120
+ xml.present? ? xml.xpath(path).text : ""
121
+ end
122
+
123
+ def architecture
124
+ @architecture || os.arch
125
+ end
126
+
127
+ class << self
128
+ def by_environment(environment)
129
+ self.where("($environment == \"" + environment + "\")")
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,60 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Aeolus
16
+ module Image
17
+ module Warehouse
18
+ class ImageBuild < WarehouseModel
19
+ @bucket_name = 'builds'
20
+
21
+ def image
22
+ Image.find(@image) if @image
23
+ end
24
+
25
+ def target_images
26
+ TargetImage.where("($build == \"" + @uuid.to_s + "\")")
27
+ end
28
+
29
+ # Convenience Method to get all provider images for this build
30
+ def provider_images
31
+ provider_images = []
32
+ target_images.each do |t|
33
+ provider_images = provider_images + t.provider_images
34
+ end
35
+ provider_images
36
+ end
37
+ def provider_images_by_provider_and_account(provider, provider_account)
38
+ provider_images = []
39
+ target_images.each do |t|
40
+ provider_images = provider_images +
41
+ t.find_provider_image_by_provider_and_account(provider,
42
+ provider_account)
43
+ end
44
+ provider_images
45
+ end
46
+
47
+ # Deletes this image and all child objects
48
+ def delete!
49
+ begin
50
+ target_images.each do |ti|
51
+ ti.delete!
52
+ end
53
+ rescue NoMethodError
54
+ end
55
+ ImageBuild.delete(@uuid)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,36 @@
1
+ # Copyright 2011 Red Hat, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Aeolus
16
+ module Image
17
+ module Warehouse
18
+ class ProviderImage < WarehouseModel
19
+ @bucket_name = 'provider_images'
20
+
21
+ def target_image
22
+ TargetImage.find(@target_image) if @target_image
23
+ end
24
+
25
+ def provider_name
26
+ @provider
27
+ end
28
+
29
+ # Deletes this provider image
30
+ def delete!
31
+ ProviderImage.delete(@uuid)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end