Class: Stack
- Inherits:
-
CloudstackCli::Base
- Object
- Thor
- CloudstackCli::Base
- Stack
- Defined in:
- lib/cloudstack-cli/commands/stack.rb
Constant Summary
Constants included from CloudstackCli::Helper
CloudstackCli::Helper::ASYNC_STATES
Instance Attribute Summary
Attributes inherited from CloudstackCli::Base
Instance Method Summary collapse
Methods inherited from CloudstackCli::Base
Methods included from CloudstackCli::Helper
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #print_job_status, #print_options, #update_job_status, #watch_jobs
Instance Method Details
#create(stackfile) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cloudstack-cli/commands/stack.rb', line 4 def create(stackfile) stack = parse_stackfile(stackfile) say "Create stack #{stack["name"]}...", :green projectid = find_project(stack["project"])['id'] if stack["project"] jobs = [] client.verbose = false stack["servers"].each do |instance| instance["name"].gsub(', ', ',').split(',').each do |name| server = client.get_server(name: name, project_id: projectid) if server say "Server #{name} (#{server["state"]}) already exists.", :yellow jobs << { id: 0, name: "Create server #{name}", status: 1 } else jobs << { id: client.create_server( { name: name, displayname: instance["decription"], zone: instance["zone"] || stack["zone"], template: instance["template"], iso: instance["iso"] , offering: instance["offering"], networks: load_string_or_array(instance["networks"]), project: stack["project"], disk_offering: instance["disk_offering"], disk_size: instance["disk_size"], group: instance["group"] || stack["group"], keypair: instance["keypair"] || stack["keypair"], sync: true } )['jobid'], name: "Create server #{name}" } end end end watch_jobs(jobs) say "Check for port forwarding rules...", :green jobs = [] stack["servers"].each do |instance| instance["name"].gsub(', ', ',').split(',').each do |name| if port_rules = string_to_array(instance["port_rules"]) server = client(quiet: true).get_server(name, project_id: projectid) create_port_rules(server, port_rules, false).each_with_index do |job_id, index| jobs << { id: job_id, name: "Create port forwarding ##{index + 1} rules for server #{name}" } end end end end watch_jobs(jobs) say "Finished.", :green end |
#destroy(stackfile) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cloudstack-cli/commands/stack.rb', line 71 def destroy(stackfile) stack = parse_stackfile(stackfile) projectid = find_project(stack["project"])['id'] if stack["project"] client.verbose = false servers = [] stack["servers"].each do |server| server["name"].gsub(', ', ',').split(',').each {|name| servers << name} end if [:force] || yes?("Destroy the following servers #{servers.join(', ')}? [y/N]:", :yellow) jobs = [] servers.each do |name| server = client(quiet: true).get_server(name, project_id: projectid) if server jobs << { id: client.destroy_server( server['id'], false )['jobid'], name: "Destroy server #{name}" } end end watch_jobs(jobs) say "Finished.", :green end end |