Class: Smartdc::Cli::Machine

Inherits:
Thor
  • Object
show all
Includes:
Smartdc::CliHelper
Defined in:
lib/smartdc/cli/machine.rb

Instance Method Summary collapse

Methods included from Smartdc::CliHelper

#describe, #horizontal, #output, #use_machine, #vertical

Instance Method Details

#add(name) ⇒ Object



26
27
28
29
# File 'lib/smartdc/cli/machine.rb', line 26

def add(name)
  body = {name: name}.merge(options)
  output Smartdc.create_machine(body), options.merge({table: :vertical})
end

#destroy(id = nil) ⇒ Object



32
33
34
35
# File 'lib/smartdc/cli/machine.rb', line 32

def destroy(id=nil)
  id = use_machine(id)
  output Smartdc.destroy_machine(id), options.merge(message: "Destroy [#{id}] of machine.")
end

#listObject



12
13
14
15
16
# File 'lib/smartdc/cli/machine.rb', line 12

def list
  output Smartdc.machines(options), options.merge(table: :horizontal, include: %i[
    id name state primaryIp memory disk dataset
  ])
end

#reboot(id = nil) ⇒ Object



50
51
52
53
# File 'lib/smartdc/cli/machine.rb', line 50

def reboot(id=nil)
  id = use_machine(id)
  output Smartdc.reboot_machine(id), options.merge(message: "Reboot [#{id}] of machine.")
end

#resize(id = nil) ⇒ Object



57
58
59
60
61
# File 'lib/smartdc/cli/machine.rb', line 57

def resize(id=nil)
  body = {package: options[:package]}
  id = use_machine(id)
  output Smartdc.resize_machine(id, body), options.merge(message: "Resize [#{id}] of machine.")
end

#show(id = nil) ⇒ Object



19
20
21
# File 'lib/smartdc/cli/machine.rb', line 19

def show(id=nil)
  output Smartdc.machine(use_machine(id)), options.merge(table: :vertical)
end

#start(id = nil) ⇒ Object



44
45
46
47
# File 'lib/smartdc/cli/machine.rb', line 44

def start(id=nil)
  id = use_machine(id)
  output Smartdc.start_machine(id), options.merge(message: "Start [#{id}] of machine.")
end

#stop(id = nil) ⇒ Object



38
39
40
41
# File 'lib/smartdc/cli/machine.rb', line 38

def stop(id=nil)
  id = use_machine(id)
  output Smartdc.stop_machine(id), options.merge(message: "Stop [#{id}] of machine.")
end

#use(id = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/smartdc/cli/machine.rb', line 64

def use(id=nil)
  clicfg = Smartdc::CliConfigure.new
  sdccfg = clicfg.read
  if id.nil?
    puts "Use [#{sdccfg[:use_machine]}] of machine."
  else
    sdccfg[:use_machine] = id
    clicfg.write(sdccfg)
  end
end