Class: Dcmgr::Cli::Host

Inherits:
Base
  • Object
show all
Includes:
Models
Defined in:
lib/dcmgr/cli/host.rb

Instance Method Summary collapse

Instance Method Details

#add(node_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dcmgr/cli/host.rb', line 20

def add(node_id)
  UnknownUUIDError.raise(options[:account_id]) if Account[options[:account_id]].nil?
  UnsupportedArchError.raise(options[:arch]) unless HostNode::SUPPORTED_ARCH.member?(options[:arch])
  UnsupportedHypervisorError.raise(options[:hypervisor]) unless HostNode::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])

  unless (options[:force] || Isono::Models::NodeState.find(:node_id=>node_id))
    abort("Node ID is not registered yet: #{node_id}")
  end
  
  fields = {
            :name=>options[:name],
            :node_id=>node_id,
            :offering_cpu_cores=>options[:cpu_cores],
            :offering_memory_size=>options[:memory_size],
            :hypervisor=>options[:hypervisor],
            :arch=>options[:arch],
            :account_id=>options[:account_id],
  }
  fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
  puts super(HostNode,fields)
end

#del(uuid) ⇒ Object



62
63
64
# File 'lib/dcmgr/cli/host.rb', line 62

def del(uuid)
  super(HostNode,uuid)
end

#modify(uuid) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dcmgr/cli/host.rb', line 48

def modify(uuid)
  UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && Account[options[:account_id]].nil?
  UnsupportedHypervisorError.raise(options[:hypervisor]) unless options[:hypervisor].nil? || HostNode::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
  fields = {
            :name=>options[:name],
            :offering_memory_size=>options[:memory_size],
            :offering_cpu_cores=>options[:cpu_cores],
            :account_id=>options[:account_id],
            :hypervisor=>options[:hypervisor]
  }
  super(HostNode,uuid,fields)
end

#show(uuid = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dcmgr/cli/host.rb', line 67

def show(uuid=nil)
  if uuid
    host = HostNode[uuid] || UnknownUUIDError.raise(uuid)
    puts ERB.new(<<__END, nil, '-').result(binding)
Host UUID:
<%= host.canonical_uuid %>
Node ID:
<%= host.node_id %>
CPU Cores (offerring):
<%= host.offering_cpu_cores %>
Memory (offerring):
<%= host.offering_memory_size %>MB
Hypervisor:
<%= host.hypervisor %>
__END
  else
    cond = {}
    all = HostNode.filter(cond).all
    puts ERB.new(<<__END, nil, '-').result(binding)
<%- all.each { |row| -%>
<%= "%-15s %-20s %-10s" % [row.canonical_uuid, row.node_id, row.status] %>
<%- } -%>
__END
  end
end

#shownodesObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/dcmgr/cli/host.rb', line 94

def shownodes
  nodes = Isono::Models::NodeState.filter.all
  
  puts ERB.new(<<__END, nil, '-').result(binding)
Node ID              State
<%- nodes.each { |row| -%>
<%= "%-20s %-10s" % [row.node_id, row.state] %>
<%- } -%>
__END
end