Class: Server
- Inherits:
-
CloudstackCli::Base
- Object
- Thor
- CloudstackCli::Base
- Server
- Includes:
- CloudstackCli::Helper
- Defined in:
- lib/cloudstack-cli/commands/server.rb
Instance Attribute Summary
Attributes inherited from CloudstackCli::Base
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #create(name) ⇒ Object
- #destroy(*name) ⇒ Object
- #list ⇒ Object
- #restart(name) ⇒ Object
- #start(name) ⇒ Object
- #stop(name) ⇒ Object
Methods included from CloudstackCli::Helper
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #print_options
Instance Method Details
#bootstrap ⇒ Object
95 96 97 |
# File 'lib/cloudstack-cli/commands/server.rb', line 95 def bootstrap bootstrap_server_interactive end |
#create(name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cloudstack-cli/commands/server.rb', line 45 def create(name) if project = @cs.get_project(project) project_id = project["id"] end server = client.get_server(name, project_id) unless server say "Create server #{name}...", :yellow server = client.create_server( name, [:offering], [:template], [:zone], [:networks], [:project] ) puts say "Server #{name} has been created.", :green client.wait_for_server_state(server["id"], "Running") say "Server #{name} is running.", :green else say "Server #{name} already exists.", :green # TODO: check status of server end if [:port_rules] && [:port_rules].size > 0 invoke "port_rule:create", name, project: [:project], network: [:networks].first, rules: [:port_rules] end end |
#destroy(*name) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cloudstack-cli/commands/server.rb', line 76 def destroy(*name) projectid = find_project['id'] if [:project] name.each do |server_name| server = client.get_server(server_name, projectid) unless server say "Server #{server_name} not found.", :red else ask = "Destroy #{server_name} (#{server['state']})?" if [:force] == true || yes?(ask) say "Destroying #{server_name} " client.destroy_server(server["id"]) puts end end end end |
#list ⇒ Object
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 |
# File 'lib/cloudstack-cli/commands/server.rb', line 7 def list if [:project] if [:project].downcase == "all" [:project_id] = -1 else project = find_project [:project_id] = project['id'] end end servers = client.list_servers() if servers.size < 1 puts "No servers found." else table = [["Name", "State", "Offering", "Zone", [:project] ? "Project" : "Account", "IP's"]] servers.each do |server| table << [ server['name'], server['state'], server['serviceofferingname'], server['zonename'], [:project] ? server['project'] : server['account'], server['nic'].map { |nic| nic['ipaddress']}.join(' ') ] end print_table table end end |
#restart(name) ⇒ Object
112 113 114 115 |
# File 'lib/cloudstack-cli/commands/server.rb', line 112 def restart(name) client.reboot_server(name) puts end |
#start(name) ⇒ Object
106 107 108 109 |
# File 'lib/cloudstack-cli/commands/server.rb', line 106 def start(name) client.start_server(name) puts end |
#stop(name) ⇒ Object
100 101 102 103 |
# File 'lib/cloudstack-cli/commands/server.rb', line 100 def stop(name) client.stop_server(name) puts end |