Class: Server
- Inherits:
-
CloudstackCli::Base
- Object
- Thor
- CloudstackCli::Base
- Server
- 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
Instance Method Details
#bootstrap ⇒ Object
74 75 76 |
# File 'lib/cloudstack-cli/commands/server.rb', line 74 def bootstrap CloudstackCli::Helper.new([:config]).bootstrap_server_interactive() end |
#create(name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cloudstack-cli/commands/server.rb', line 42 def create(name) CloudstackCli::Helper.new([:config]).bootstrap_server( name, [:zone], [:template], [:offering], [:networks], [:port_forwarding], [:project] ) end |
#destroy(name) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cloudstack-cli/commands/server.rb', line 56 def destroy(name) server = client.get_server(name) unless server error "Server not found." exit end ask = "Are you sure you want to destroy the following server?\n" ask += "#{server['name']} (#{server['state']})?" unless [:force] == true || yes?(ask) exit end client.destroy_server(server["id"]) puts end |
#list ⇒ Object
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 |
# File 'lib/cloudstack-cli/commands/server.rb', line 6 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
91 92 93 94 |
# File 'lib/cloudstack-cli/commands/server.rb', line 91 def restart(name) client.reboot_server(name) puts end |
#start(name) ⇒ Object
85 86 87 88 |
# File 'lib/cloudstack-cli/commands/server.rb', line 85 def start(name) client.start_server(name) puts end |
#stop(name) ⇒ Object
79 80 81 82 |
# File 'lib/cloudstack-cli/commands/server.rb', line 79 def stop(name) client.stop_server(name) puts end |