Class: WeBee::Machine

Inherits:
Object
  • Object
show all
Includes:
SAXMachine
Defined in:
lib/webee.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SAXMachine

#old_parse, #parse

Instance Attribute Details

#datacenter_idObject

Returns the value of attribute datacenter_id.



420
421
422
# File 'lib/webee.rb', line 420

def datacenter_id
  @datacenter_id
end

#rawObject

Returns the value of attribute raw.



419
420
421
# File 'lib/webee.rb', line 419

def raw
  @raw
end

Instance Method Details

#find_vms_by_name(name) ⇒ Object



502
503
504
505
506
507
508
# File 'lib/webee.rb', line 502

def find_vms_by_name(name)
  matches = []
    self.virtual_machines.each do |vm|
      matches << vm if vm.name =~ /#{regexp}/i
    end
  matches
end

#rackObject



488
489
490
491
# File 'lib/webee.rb', line 488

def rack
  doc = Nokogiri.parse(RestClient.get(Api.build_url(rack_url) , :accept => :xml))
  Rack.parse doc.root.to_s
end

#to_xmlObject



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/webee.rb', line 450

def to_xml
  xm = Builder::XmlMarkup.new
  xm.machine {
    xm.name name
    xm.description description
    xm.ip ip
    xm.ipService ip_service
    xm.user user
    xm.password password
    xm.realCpu real_cpu
    xm.realHd real_hd
    xm.realRam real_ram
    xm.state state
    xm.type hypervisortype
    xm.cpu cpu
    xm.cpuRatio cpu_ratio
    xm.cpuUsed cpu_used
    xm.hd hd
    xm.hdUsed hd_used
    xm.ram ram
    xm.ramUsed ram_used
    xm.virtualSwitch virtual_switch
    xm.datastores {
      datastores.each do |ds|
        xm.datastore {
          xm.name ds.name
          xm.directory ds.directory
          xm.rootPath ds.root_path
          xm.enabled ds.enabled
          xm.size ds.size
          xm.usedSize ds.used_size
        }
      end
    }
  }
  xm.target!
end

#virtual_machinesObject



493
494
495
496
497
498
499
500
# File 'lib/webee.rb', line 493

def virtual_machines
  items = []
  doc = Nokogiri.parse(RestClient.get(Api.build_url(virtual_machines_url) , :accept => :xml))
  doc.search('//virtualMachine').each do |node|
    items << VirtualMachine.parse(node.to_s)
  end
  items 
end

#virtual_switchesObject



446
447
448
# File 'lib/webee.rb', line 446

def virtual_switches
  virtual_switch.split('/')
end