aeolus-image 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ require 'rest_client'
2
+
3
+ module Aeolus
4
+ module Image
5
+ class PushCommand < BaseCommand
6
+ attr_accessor :console
7
+ def initialize(opts={}, logger=nil)
8
+ super(opts, logger)
9
+ default = {
10
+ :provider => [],
11
+ :id => '',
12
+ :build => ''
13
+ }
14
+ @options = default.merge(@options)
15
+ @console = ImageFactoryConsole.new()
16
+ @console.start
17
+ end
18
+ def run
19
+ begin
20
+ if combo_implemented?
21
+ if !@options[:id].empty? && pushed?(@options[:id])
22
+ puts "ERROR: This image has already been pushed, to push to another provider please push via build-id rather than image-id"
23
+ puts "e.g. aeolus-image push --provider <provider> --build <build-id>"
24
+ quit(1)
25
+ end
26
+
27
+ sleep(5)
28
+ @console.push(@options[:provider], get_creds, @options[:id], @options[:build]).each do |adaptor|
29
+ puts ""
30
+ puts "Provider Image: #{adaptor.image_id}"
31
+ puts "Image: #{adaptor.image}"
32
+ puts "Build: #{adaptor.build}"
33
+ puts "Status: #{adaptor.status}"
34
+ puts "Percent Complete: #{adaptor.percent_complete}"
35
+ end
36
+ quit(0)
37
+ end
38
+ rescue
39
+ puts "An Error occured whilst trying to push this build, please check aeolus-image --help for details on how to use this command"
40
+ quit(1)
41
+ end
42
+ end
43
+
44
+ def get_creds
45
+ conductor['provider_accounts'].get
46
+ end
47
+
48
+ def combo_implemented?
49
+ if @options[:provider].empty? || (@options[:build].empty? && @options[:id].empty?)
50
+ puts "This combination of parameters is not currently supported"
51
+ quit(1)
52
+ end
53
+ true
54
+ end
55
+
56
+ private
57
+ def quit(code)
58
+ @console.shutdown
59
+ exit(code)
60
+ end
61
+
62
+ def pushed?(image)
63
+ begin
64
+ uuid = Regexp.new('[\w]{8}[-][\w]{4}[-][\w]{4}[-][\w]{4}[-][\w]{12}')
65
+ uuid.match(iwhd["/images/" + image + "/latest_unpushed"].get).nil? ? true : false
66
+ rescue
67
+ true
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,36 @@
1
+ .TH aeolus-image 1 "July 07, 2011" "version 0.4" "USER COMMANDS"
2
+ .SH NAME
3
+ aeolus-image build \- command for building aeolus images
4
+ .SH SYNOPSIS
5
+ .B aeolus-image build [\-h|--help] [\-u|--username] [\-w|--password] [\-I|--image [image-id]] [\-e|--template [path-to-template]] [\-t|--targets [targets]] [\-d|--daemon]
6
+ .SH DESCRIPTION
7
+ aeolus-image build command allows users to build new images based on a given TDL template file for a set of specified targets such e.g. EC2, RHEVM etc...
8
+ .SH OPTIONS
9
+ .TP
10
+ \-u, --user <username>
11
+ Conductor username
12
+ .TP
13
+ \-w, --password <password>
14
+ Conductor password
15
+ .TP
16
+ \-T, --target
17
+ Provide a list of targets for the build
18
+ .TP
19
+ \-e, --template
20
+ Provide path to a TDL template file for building against
21
+ .TP
22
+ \-d, --daemon
23
+ Run as a background process
24
+ .TP
25
+ Get usage information for this command and associated commmands
26
+ \-h, --help
27
+ .SH EXAMPLES
28
+ .TP
29
+ Build a new image for ec2 based on the specified template TDL file template.tdl
30
+ .B aeolus-image build
31
+ \--targets ec2
32
+ \--template ./template.tdl
33
+ .TP
34
+ Martyn Taylor (mtaylor@redhat.com), Jason Guiditta (jguiditta@redhat.com)
35
+ .SH SEE ALSO
36
+ aeolus-image-list(1), aeolus-image-push(1), aeolus-image-import(1)
@@ -0,0 +1,57 @@
1
+ .TH aeolus-image 1 "July 07, 2011" "version 0.4" "USER COMMANDS"
2
+ .SH NAME
3
+ aeolus-image import \- command for importing existing provider images into aeolus
4
+ .SH SYNOPSIS
5
+ .B aeolus-image import [\-h|--help] [\-u|--username] [\-w|--password] [\-r|--provider [provider-name]] [\--id [provider-image-id]] [--description [path-to-file|xml string]] [\T|--target [target]] [\-d|--daemon]
6
+ .SH DESCRIPTION
7
+ aeolus-image import allows users to import pre-existing images that exist in cloud provders for example AMI from EC2, into aeolus.
8
+ .SH OPTIONS
9
+ .TP
10
+ \-u, --user <username>
11
+ Conductor username
12
+ .TP
13
+ \-w, --password <password>
14
+ Conductor password
15
+ .TP
16
+ \-r, --provider <provider-name>
17
+ The provider name as it exists in conductor from where the importing image resides
18
+ .TP
19
+ \--id <provider-image-id>
20
+ The providers ID given to the importing image
21
+ .TP
22
+ \-T, --target
23
+ The target type for the given provider
24
+ .TP
25
+ \--description <path-to-xml-description|xml string>
26
+ A user defined description to associate with the importing image
27
+ .TP
28
+ \-d, --daemon
29
+ Run as a background process
30
+ .TP
31
+ Get usage information for this command and associated commmands
32
+ \-h, --help
33
+ .SH EXAMPLES
34
+ .TP
35
+ Import the AMI ami-1234567 from the provider ec2-us-east-1 into aeolus
36
+ .B aeolus-image import
37
+ \--provider ec2-us-east-1
38
+ \--target ec2
39
+ \--id ami-1234567
40
+ .TP
41
+ Import the AMI ami-1234567 from the provider ec2-us-west-1 into aeolus with a given xml description
42
+ .B aeolus-image import
43
+ \--provider ec2-us-west-1
44
+ \--target ec2
45
+ \--id ami-1234567
46
+ \--description '<image><name>myAMI</name></image>'
47
+ .TP
48
+ Import the AMI ami-1234567 from the provider ec2-us-west-1 into aeolus providing a path to the description XML file
49
+ .B aeolus-image import
50
+ \--provider ec2-us-west-1
51
+ \--target ec23
52
+ \--id ami-1234567
53
+ \--description /foo/bar/description.xml
54
+ .SH AUTHOR
55
+ Martyn Taylor (mtaylor@redhat.com), Jason Guiditta (jguiditta@redhat.com)
56
+ .SH SEE ALSO
57
+ aeolus-image-list(1), aeolus-image-push(1), aeolus-image-build(1)
@@ -0,0 +1,80 @@
1
+ .TH aeolus-image 1 "July 07, 2011" "version 0.4" "USER COMMANDS"
2
+ .SH NAME
3
+ aeolus-image \- command for listing aeolus image associated objects.
4
+ .SH SYNOPSIS
5
+ .B aeolus-image list [\-h|--help] [\-u|--username] [\-w|--password] [\-i|--images] [\-b|--builds [image id]] [\-t|--targetimages [build id]] [\-g|--targets] [\-a|--accounts] [\-p|--providers]
6
+ .SH DESCRIPTION
7
+ aeolus-image list commands allows users to list information on the contents of particular objects in image warehouse including:
8
+ .P
9
+ images: high level image representation associated with underlying provider and target images
10
+ .br
11
+ builds: an object representation of a particular build that has taken place for a high level image
12
+ .br
13
+ targets: particular targets available to build against, for example 'ec2'
14
+ .br
15
+ targetimages: represents builds of particular image against a target. For example building against target 'ec2' would create an AMI specific image
16
+ .br
17
+ providerimages: represents the actual images that have been uploaded to a provider. Similiar to a target image but specific to a particular provider
18
+ .SH OPTIONS
19
+ .TP
20
+ \-u, --user <username>
21
+ Conductor username
22
+ .TP
23
+ \-w, --password <password>
24
+ Conductor password
25
+ Get usage information for this command and associated commmands
26
+ .TP
27
+ \-i, --images
28
+ Retrieve a list of images
29
+ .TP
30
+ \-b, --builds <image id>
31
+ Retrieve the builds of an image
32
+ .TP
33
+ \-t, --targetimages <build id>
34
+ Retrieve the target images from a build
35
+ .TP
36
+ \-P, --providerimages
37
+ Retrieve the provider images from a target image
38
+ .TP
39
+ \-g, --targets
40
+ Retrieve a list of available targets
41
+ .TP
42
+ \-p, --providers
43
+ Retrieve a list of available providers
44
+ .TP
45
+ \-a, --accounts
46
+ Retrieve a list of available accounts
47
+ .TP
48
+ \-d, --daemon
49
+ Run as a background process
50
+ .TP
51
+ \-h, --help
52
+ .SH EXAMPLES
53
+ .TP
54
+ List all images
55
+ .B aeolus-image list
56
+ \--images
57
+ .TP
58
+ List all builds for an image with id: 12345678-aaaa-1234--1234567890ab
59
+ .B aeolus-image list
60
+ \--builds 12345678-aaaa-1234--1234567890ab
61
+ .TP
62
+ List all target images for a given build with id: 12345678-bbbb-1234--1234567890ab
63
+ .B aeolus-image list
64
+ \--builds 12345678-bbbb-1234--1234567890ab
65
+ .TP
66
+ List all available targets
67
+ .B aeolus-image list
68
+ \--targets
69
+ .TP
70
+ List all available providers
71
+ .B aeolus-image list
72
+ \--providers
73
+ .TP
74
+ List all available accounts
75
+ .B aeolus-image list
76
+ \--account
77
+ .SH AUTHOR
78
+ Martyn Taylor (mtaylor@redhat.com), Jason Guiditta (jguiditta@redhat.com)
79
+ .SH SEE ALSO
80
+ aeolus-image-build(1), aeolus-image-push(1), aeolus-image-import(1), aeolus-image-delete(1)
@@ -0,0 +1,40 @@
1
+ .TH aeolus-image 1 "July 07, 2011" "version 0.4" "USER COMMANDS"
2
+ .SH NAME
3
+ aeolus-image push \- command for pushing aeolus images to back end providers
4
+ .SH SYNOPSIS
5
+ .B aeolus-image push [\-h|--help] [\-u|--username] [\-w|--password] [\-id [image-id]] [-r|--provider [provider-name]]
6
+ .SH DESCRIPTION
7
+ aeolus-image push allows users to push built images to a particular backend provider
8
+ .SH OPTIONS
9
+ .TP
10
+ \-u, --user <username>
11
+ Conductor username
12
+ .TP
13
+ \-w, --password <password>
14
+ Conductor password
15
+ .TP
16
+ \-r|--provider
17
+ The provider name this image should be pushed to
18
+ .TP
19
+ \--id <id>
20
+ The id of the image for pushing
21
+ .TP
22
+ \-d, --daemon
23
+ Run as a background process
24
+ .TP
25
+ Get usage information for this command and associated commmands
26
+ \-h, --help
27
+ .SH EXAMPLES
28
+ .TP
29
+ Initial push of an image with id 12345678-bbbb-1234--1234567890ab to provider ec2-us-east-1
30
+ .B aeolus-image push
31
+ \--id 12345678-bbbb-1234--1234567890ab
32
+ \--provider ec2-us-east-1
33
+ Push a build with id 12345678-bbbb-1234--1234567890ab to provider ec2-us-east-1
34
+ .B aeolus-image push
35
+ \--build 12345678-bbbb-1234--1234567890ab
36
+ \--provider ec2-us-east-1
37
+ .SH AUTHOR
38
+ Martyn Taylor (mtaylor@redhat.com), Jason Guiditta (jguiditta@redhat.com)
39
+ .SH SEE ALSO
40
+ aeolus-image-list(1), aeolus-image-build(1), aeolus-image-import(1)
@@ -0,0 +1,16 @@
1
+ .TH aeolus-image 1 "July 07, 2011" "version 0.4" "USER COMMANDS"
2
+ .SH NAME
3
+ aeolus-image \- command line tool for managing aeolus images
4
+ .SH SYNOPSIS
5
+ .B aeolus-image
6
+ [\-h]
7
+ .SH DESCRIPTION
8
+ aeolus-image is a tool that allows users to control their aeolus images through image builder and aeolus conductor. aeolus-image offers four commands options; list, build, push, import. For more information on each command please run man aeolus-image <command> or aeolus-image --help
9
+ .SH OPTIONS
10
+ .TP
11
+ \-h, --help
12
+ Get usage information for this tool and subcommands
13
+ .SH AUTHOR
14
+ Martyn Taylor (mtaylor@redhat.com), Jason Guiditta (jguiditta@redhat.com)
15
+ .SH SEE ALSO
16
+ aeolus-image-build(1), aeolus-image-push(1), aeolus-image-list(1), aeolus-image-import(1)
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ module Aeolus
4
+ module Image
5
+ describe BaseCommand do
6
+
7
+ it "should determine the correct credentials for HTTP Authentication" do
8
+ basec = BaseCommand.new
9
+ iwhd = basec.send :iwhd
10
+ iwhd.user.should == nil
11
+
12
+ conductor = basec.send :conductor
13
+ conductor.user.should == "admin"
14
+ conductor.password.should == "password"
15
+
16
+ basec = BaseCommand.new({:username => "testusername", :password=> "testpassword"})
17
+ conductor = basec.send :conductor
18
+ conductor.user.should == "testusername"
19
+ conductor.password.should == "testpassword"
20
+ end
21
+
22
+ describe "#read_file" do
23
+
24
+ it "should return nil when it cannot find file" do
25
+ b = BaseCommand.new
26
+ b.send(:read_file, "foo.fake").should be_nil
27
+ end
28
+
29
+ it "should read file content into string variable" do
30
+ b = BaseCommand.new
31
+ template_str = b.send(:read_file, "#{File.dirname(__FILE__)}" + "/../examples/custom_repo.tdl")
32
+ template_str.should include("<template>")
33
+ end
34
+ end
35
+
36
+ describe "#is_file?" do
37
+ it "should return false if no file found" do
38
+ b = BaseCommand.new
39
+ b.send(:is_file?, "foo.fake").should be_false
40
+ end
41
+ it "should return true if file found" do
42
+ b = BaseCommand.new
43
+ valid_file = "#{File.dirname(__FILE__)}" + "/../examples/aeolus-cli"
44
+ b.instance_eval {@config_location = valid_file}
45
+ b.send(:is_file?, valid_file).should be_true
46
+ end
47
+ end
48
+
49
+ describe "#write_file" do
50
+ it "should write a new file" do
51
+ b = BaseCommand.new
52
+ new_file = "/tmp/foo.fake"
53
+ b.instance_eval {@config_location = new_file}
54
+ b.send(:write_file)
55
+ conf = YAML::load(File.open(File.expand_path(new_file)))
56
+ conf.has_key?(:iwhd).should be_true
57
+ File.delete(new_file)
58
+ end
59
+ end
60
+
61
+ describe "#validate_xml_document?" do
62
+ it "should return errors given non compliant xml" do
63
+ b = BaseCommand.new
64
+ errors = b.send(:validate_xml_document, "examples/tdl.rng", File.read("spec/fixtures/invalid_template.tdl"))
65
+ errors.length.should > 0
66
+ end
67
+
68
+ it "should return no errors" do
69
+ b = BaseCommand.new
70
+ errors = b.send(:validate_xml_document, "examples/tdl.rng", File.read("spec/fixtures/valid_template.tdl"))
71
+ errors.length.should == 0
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ module Aeolus
4
+ module Image
5
+ describe BuildCommand do
6
+ before(:each) do
7
+ @options[:target] = ['mock','ec2']
8
+ @options[:template] = "#{File.dirname(__FILE__)}" + "/../examples/custom_repo.tdl"
9
+ end
10
+
11
+ describe "#run" do
12
+ it "should kick off a build with valid options" do
13
+ b = BuildCommand.new(@options, @output)
14
+ begin
15
+ b.run
16
+ rescue SystemExit => e
17
+ e.status.should == 0
18
+ end
19
+ $stdout.string.should include("Image:")
20
+ $stdout.string.should include("Target Image:")
21
+ $stdout.string.should include("Build:")
22
+ end
23
+ it "should exit with a message if only image id is provided" do
24
+ @options.delete(:template)
25
+ @options.delete(:target)
26
+ @options[:image] = '825c94d1-1353-48ca-87b9-36f02e069a8d'
27
+ b = BuildCommand.new(@options, @output)
28
+ begin
29
+ b.run
30
+ rescue SystemExit => e
31
+ e.status.should == 1
32
+ end
33
+ $stdout.string.should include("This combination of parameters is not currently supported")
34
+ end
35
+ it "should exit with appropriate message when a non compliant template is given" do
36
+ @options[:template] = "spec/fixtures/invalid_template.tdl"
37
+ @options[:image] = '825c94d1-1353-48ca-87b9-36f02e069a8d'
38
+ b = BuildCommand.new(@options, @output)
39
+ begin
40
+ b.run
41
+ rescue SystemExit => e
42
+ e.status.should == 1
43
+ end
44
+ $stdout.string.should include("ERROR: The given Template does not conform to the TDL Schema")
45
+ end
46
+ end
47
+
48
+ describe "#combo_implemented?" do
49
+ it "should give useful feedback if no template or target is specified" do
50
+ @options[:template] = ''
51
+ @options[:target] = []
52
+ b = BuildCommand.new(@options, @output)
53
+ begin
54
+ b.combo_implemented?
55
+ rescue SystemExit => e
56
+ e.status.should == 1
57
+ end
58
+ $stdout.string.should include("This combination of parameters is not currently supported")
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end