Class: Proxmox::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/pve/proxmox.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#sid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

__new__, fetch, #method_missing, #refresh!, #respond_to?

Methods included from RestConnection

#bench, #rest_del, #rest_get, #rest_post, #rest_put

Constructor Details

#initializeNode

Returns a new instance of Node.



189
190
191
192
193
# File 'lib/pve/proxmox.rb', line 189

def initialize
  rest_prefix
  @sid = "nd:#{@node}"
  @name = @node
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Proxmox::Base

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



179
180
181
# File 'lib/pve/proxmox.rb', line 179

def name
  @name
end

Class Method Details

.allObject



174
175
176
# File 'lib/pve/proxmox.rb', line 174

def all
  rest_get( '/nodes').map {|d| __new__ d.merge( t: 'nd') }
end

.find_by_name(name) ⇒ Object



163
164
165
166
167
168
# File 'lib/pve/proxmox.rb', line 163

def find_by_name name
  all.each do |node|
    return node  if node.node == name
  end
  nil
end

.find_by_name!(name) ⇒ Object



170
171
172
# File 'lib/pve/proxmox.rb', line 170

def find_by_name! name
  find_by_name( name) or raise( Proxmox::NotFound, "Node not found: #{name}")
end

Instance Method Details

#===(t) ⇒ Object



181
182
183
# File 'lib/pve/proxmox.rb', line 181

def === t
  @name =~ t or @vmid.to_s =~ t or @sid =~ t
end

#aplinfoObject



203
204
205
206
207
208
# File 'lib/pve/proxmox.rb', line 203

def aplinfo
  return []  if offline?
  rest_get( "#{@rest_prefix}/aplinfo").map do |d|
    AplInfo.send :__new__, d.merge( node: self, t: 'apl')
  end
end

#enter(*command) ⇒ Object



227
228
229
# File 'lib/pve/proxmox.rb', line 227

def enter *command
  Kernel.system 'ssh', '-t', node, command.map( &:to_s).shelljoin
end

#exec(*command) ⇒ Object



231
232
233
# File 'lib/pve/proxmox.rb', line 231

def exec *command
  Kernel.system 'ssh', node, command.map( &:to_s).shelljoin
end

#lxcObject



198
199
200
201
# File 'lib/pve/proxmox.rb', line 198

def lxc
  return []  if offline?
  rest_get( "#{@rest_prefix}/lxc").map {|d| LXC.send :__new__, d.merge( node: self, t: 'ct') }
end

#offline?Boolean

Returns:

  • (Boolean)


195
# File 'lib/pve/proxmox.rb', line 195

def offline?()  @status.nil? or 'offline' == @status  end

#online?Boolean

Returns:

  • (Boolean)


196
# File 'lib/pve/proxmox.rb', line 196

def online?()  'online' == @status  end

#qemuObject



217
218
219
220
# File 'lib/pve/proxmox.rb', line 217

def qemu
  return []  if offline?
  rest_get( "#{@rest_prefix}/qemu").map {|d| Qemu.send :__new__, d.merge( node: self, t: 'qm') }
end

#rest_prefixObject



185
186
187
# File 'lib/pve/proxmox.rb', line 185

def rest_prefix
  @rest_prefix ||= "/nodes/#{@node}"
end

#storageObject



210
211
212
213
214
215
# File 'lib/pve/proxmox.rb', line 210

def storage
  return []  if offline?
  rest_get( "#{@rest_prefix}/storage").map do |d|
    Storage.send :__new__, d.merge( node: self, t: 'sm')
  end
end

#tasksObject



222
223
224
225
# File 'lib/pve/proxmox.rb', line 222

def tasks
  return []  if offline?
  rest_get( "/#{@rest_prefix}/tasks").map {|d| Task.send :__new__, d.merge( node: self, t: 'task') }
end