Revision 8cd7d0df

View differences:

src/cli/one_helper/onehost_helper.rb
20 20

  
21 21
class OneHostHelper < OpenNebulaHelper::OneHelper
22 22
    TEMPLATE_XPATH  = '//HOST/TEMPLATE'
23
    HYBRID = {
24
        :ec2 => {
25
            :help => <<-EOT.unindent,
26
                #-----------------------------------------------------------------------
27
                # Supported EC2 AUTH ATTRIBUTTES:
28
                #
29
                #  REGION_NAME = <the name of the ec2 region>
30
                #
31
                #  EC2_ACCESS = <Your ec2 access key id>
32
                #  EC2_SECRET = <Your ec2 secret key>
33
                #
34
                #  CAPACITY = [
35
                #    M1SMALL  = <number of machines m1.small>,
36
                #    M1XLARGE = <number of machines m1.xlarge>,
37
                #    M1LARGE  = <number of machines m1.large>
38
                #  ]
39
                #
40
                # You can set any machine type supported by ec2
41
                # See your ec2_driver.conf for more information
42
                #
43
                #-----------------------------------------------------------------------
44
                EOT
45
        }
46
    }
47

  
48

  
23 49
    VERSION_XPATH   = "#{TEMPLATE_XPATH}/VERSION"
24 50

  
25 51
    def self.rname
......
164 190
        table
165 191
    end
166 192

  
193
    def set_hybrid(type, path)
194
        k = type.to_sym
195
        if HYBRID.key?(k)
196
            str = path.nil? ?  OpenNebulaHelper.editor_input(HYBRID[k][:help]): File.read(path)
197
        end
198
    end
167 199

  
168 200
    NUM_THREADS = 15
169 201
    def sync(host_ids, options)
src/cli/onehost
79 79
            " rsync command must be installed in the frontend and nodes."
80 80
    }
81 81

  
82
    EC2_ACCESS = {
83
        :name   => "ec2access",
84
        :large  => "--ec2access id",
85
        :description => "Set the id access for EC2 Driver",
82
    TYPE = {
83
        :name  => "type",
84
        :short => "-t remote_provider",
85
        :large => "--type remote_provider",
86
        :description => "Use type to create a host using Cloud Bursting ",
86 87
        :format => String
87 88
    }
88 89

  
89
    EC2_SECRET = {
90
        :name   => "ec2secret",
91
        :large  => "--ec2secret key",
92
        :description => "Set the secret key for EC2 Driver",
93
        :format => String
94
    }
95

  
96
    CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, EC2_ACCESS, EC2_SECRET ]
90
    CREAT_OPTIONS = [ IM, VMM, OneClusterHelper::CLUSTER, TYPE ]
97 91
    SYNC_OPTIONS  = [ OneClusterHelper::CLUSTER, FORCE, RSYNC ]
98 92

  
99 93
    ########################################################################
......
116 110
        Creates a new Host
117 111
    EOT
118 112

  
119
    command :create, create_desc, :hostname, :options=>CREAT_OPTIONS do
113
    command :create, create_desc, :hostname, [:file, nil], :options=>CREAT_OPTIONS do
120 114
        if options[:im].nil? || options[:vm].nil?
121 115
            STDERR.puts "Drivers are mandatory to create a host:"
122 116
            STDERR.puts "\t -i information driver"
......
124 118
            exit -1
125 119
        end
126 120

  
127
        ec2_host = !options[:ec2access].nil? && !options[:ec2secret].nil?
128

  
129 121
        cid = options[:cluster] || ClusterPool::NONE_CLUSTER_ID
130 122
        helper.create_resource(options) do |host|
131
                rc = host.allocate(args[0], options[:im], options[:vm], cid)
132

  
133
                if ec2_host && !OpenNebula.is_error?(rc)
134
               	    template = "EC2_ACCESS=\"#{options[:ec2access]}\"\n"\
135
               		    "EC2_SECRET=\"#{options[:ec2secret]}\"\n"\
136

  
137
                    rc = host.update(template, true)
138
                end
123
            if !options[:type].nil?
124
                str = helper.set_hybrid(options[:type], args[1])
125
            end
126
            rc = host.allocate(args[0], options[:im], options[:vm], cid)
127
            host.update(str, true) if !OpenNebula.is_error?(rc) && !options[:type].nil?
139 128

  
140
                rc
129
            rc
141 130
        end
142 131
    end
143 132

  
src/vmm_mad/remotes/ec2/cancel
32 32
deploy_id = ARGV[0]
33 33
host      = ARGV[1]
34 34

  
35
ec2_drv = EC2Driver.new(host)
36 35

  
37 36

  
38 37
begin
38
    ec2_drv = EC2Driver.new(host)
39 39
    ec2_drv.cancel(deploy_id)
40 40
rescue Exception => e
41 41
    handle_exception("Cancel", e, host, deploy_id)
src/vmm_mad/remotes/ec2/deploy
34 34
host  = ARGV[1]
35 35
id    = ARGV[2]
36 36

  
37
vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new)
38
vm.info
37
begin
38
    vm = OpenNebula::VirtualMachine.new_with_id(id, OpenNebula::Client.new)
39
    vm.info
39 40

  
40
lcm_state = vm.lcm_state_str
41
deploy_id = vm.deploy_id
41
    lcm_state = vm.lcm_state_str
42
    deploy_id = vm.deploy_id
42 43

  
43
ec2_drv = EC2Driver.new(host)
44
    ec2_drv = EC2Driver.new(host)
44 45

  
45
text=File.read(dfile)
46
    text=File.read(dfile)
46 47

  
47
begin
48 48
    puts ec2_drv.deploy(id, host, text, lcm_state, deploy_id)
49 49

  
50 50
rescue Exception => e
51

  
52 51
    handle_exception("Deploy", e, host, deploy_id, id, dfile)
53 52
end
src/vmm_mad/remotes/ec2/ec2_driver.rb
273 273
    # to retrieve connection information
274 274
    # needed for Amazon
275 275
    def get_connect_info(host)
276

  
277 276
        conn_opts={}
278 277

  
279 278
        client   = OpenNebula::Client.new
......
284 283

  
285 284
        system = OpenNebula::System.new(client)
286 285
        config = system.get_configuration
287
        if OpenNebula.is_error?(config)
288
            puts "Error getting oned configuration : #{config.message}"
289
            exit -1
290
        end
286
        raise "Error getting oned configuration : #{config.message}" if OpenNebula.is_error?(config)
287

  
291 288
        token = config["ONE_KEY"]
292 289

  
293 290
        conn_opts = {
294 291
            :access => xmlhost["TEMPLATE/EC2_ACCESS"],
295 292
            :secret => xmlhost["TEMPLATE/EC2_SECRET"]
296 293
        }
294

  
297 295
        begin
298 296
            conn_opts = OpenNebula.decrypt(conn_opts, token)
299 297
            conn_opts[:region] = xmlhost["TEMPLATE/REGION_NAME"]
......
479 477
                totalmemory += mem * value.to_i
480 478
                totalcpu    += cpu * value.to_i
481 479
            }
480
        else
481
            raise "you must define CAPACITY section properly! check the template"
482 482
        end
483 483

  
484 484
        host_info =  "HYPERVISOR=ec2\n"
src/vmm_mad/remotes/ec2/poll
33 33
host      = ARGV[1]
34 34
id        = ARGV[2]
35 35

  
36
ec2_drv = EC2Driver.new(host)
37 36

  
38
begin 
37
begin
38
    ec2_drv = EC2Driver.new(host)
39 39
    ec2_drv.poll(id, deploy_id)
40 40
rescue Excetion => e
41 41
    handle_exception("Poll", e, host, deploy_id, id)
src/vmm_mad/remotes/ec2/reboot
32 32
deploy_id = ARGV[0]
33 33
host      = ARGV[1]
34 34

  
35
ec2_drv = EC2Driver.new(host)
36

  
37 35

  
38 36
begin
37
    ec2_drv = EC2Driver.new(host)
39 38
    ec2_drv.reboot(deploy_id)
40 39
rescue Exception => e
41 40
    handle_exception("Reboot", e, host, deploy_id)
src/vmm_mad/remotes/ec2/restore
33 33
host            = ARGV[1]
34 34
deploy_id       = ARGV[2]
35 35

  
36
ec2_drv = EC2Driver.new(host)
37 36

  
38 37
begin
38
    ec2_drv = EC2Driver.new(host)
39 39
    ec2_drv.restore(deploy_id)
40 40
rescue Exception => e
41 41
    handle_exception("Restore", e, host, deploy_id)
src/vmm_mad/remotes/ec2/save
33 33
file      = ARGV[1]
34 34
host      = ARGV[2]
35 35

  
36
ec2_drv = EC2Driver.new(host)
37 36

  
38 37
begin
38
    ec2_drv = EC2Driver.new(host)
39 39
    ec2_drv.save(deploy_id)
40 40
rescue Exception => e
41 41
    handle_exception("Save", e, host, deploy_id, nil, file)
src/vmm_mad/remotes/ec2/shutdown
34 34
host      = ARGV[1]
35 35
vm_id     = ARGV[2]
36 36

  
37
vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new)
38
vm.info
37
begin
38
    vm = OpenNebula::VirtualMachine.new_with_id(vm_id, OpenNebula::Client.new)
39
    vm.info
39 40

  
40
lcm_state = vm.lcm_state_str
41
    lcm_state = vm.lcm_state_str
41 42

  
42
ec2_drv = EC2Driver.new(host)
43
    ec2_drv = EC2Driver.new(host)
43 44

  
44
begin
45 45
    ec2_drv.shutdown(deploy_id, lcm_state)
46 46
rescue Exception => e
47 47
    handle_exception("Save", e, host, deploy_id, vm_id)

Also available in: Unified diff