Sha256: 1971d43aac7941f80c8e35bf8b2a0b408cbccf2bd6dc648335ae282dfa8780f3

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

class Server < Thor

  desc "list", "list servers"
  option :listall, :type => :boolean
  option :text, :type => :boolean
  option :project
  option :account
  def list
    cs_cli = CloudstackCli::Helper.new
    if options[:project]
      project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first
      exit_now! "Project '#{options[:project]}' not found" unless project
      options[:project_id] = project['id']
      options[:account] = nil
    end
    servers = cs_cli.virtual_machines(options)
    if servers.size < 1
      puts "No servers found"
    else
      if options[:text]
        servers.each do |server|
          puts "#{server['name']} - #{server['state']} - #{server['domain']}"
        end
      else
        cs_cli.virtual_machines_table(servers)
      end
    end
  end

  desc "create NAME", "create a server"
  option :zone, :required => true
  option :template, :required => true
  option :offering, :required => true
  option :networks, :type => :array, :required => true
  option :project
  option :port_forwarding, :type => :array, :aliases => :pf, :default => [], :description => "public_ip:port"
  option :interactive, :type => :boolean
  def create(name)
    CloudstackCli::Cli.new.bootstrap_server(
        name,
        options[:zone],
        options[:template],
        options[:offering],
        options[:networks],
        options[:port_forwarding],
        options[:project]
      )
  end

  desc "stop NAME", "stop a server"
  def stop(name)
    CloudstackCli::Cli.new.stop_server(name)
  end

  desc "start NAME", "start a server"
  def start(name)
    CloudstackCli::Cli.new.start_server(name)
  end

  desc "reboot NAME", "reboot a server"
  def restart(name)
    CloudstackCli::Cli.new.reboot_server(name)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloudstack-cli-0.0.1 lib/cloudstack-cli/commands/server.rb