Class: WeBee::VDC

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

Overview

A virtual datacenter FIXME: Unimplemented

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SAXMachine

#old_parse, #parse

Class Method Details

.all(params = {}) ⇒ Object



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/webee.rb', line 637

def self.all(params = {})
  items = []
  if params.empty?
    doc = Nokogiri.parse(RestClient.get(Api.url + "/cloud/virtualdatacenters", :accept => :xml))
    doc.search('//virtualDatacenter').each do |node|
      items << VDC.parse(node.to_s)
    end
  else
    extra = []
    if params[:enterprise_id]
      extra << "enterprise=#{params[:enterprise_id]}"
    end
    if params[:datacenter_id]
      extra << "datacenter=#{params[:datacenter_id]}"
    end
    doc = Nokogiri.parse(RestClient.get(Api.url + "/cloud/virtualdatacenters?#{extra.join('&')}", :accept => :xml))
    doc.search('//virtualDatacenter').each do |node|
      items << VDC.parse(node.to_s)
    end
  end
  items
end

.create(attributes) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/webee.rb', line 568

def self.create(attributes)
  datacenter = attributes[:datacenter].datacenter_id
  enterprise = attributes[:enterprise].resource_id
  if attributes[:network].nil?
    net = VDCNetwork.new
    net.name = 'defaultNetwork'
    net.gateway = '192.168.1.1'
    net.address = '192.168.1.0'
    net.mask = '24'
    net.default_network = true
    attributes[:network] = net
  end
  xm = Builder::XmlMarkup.new
  xm.virtualDatacenter {
    xm.name attributes[:name]
    xm.cpuSoft(attributes[:cpu_soft] || "0")
    xm.cpuHard(attributes[:cpu_hard] || "0")
    xm.vlanSoft(attributes[:vlan_soft] || "0")
    xm.vlanHard(attributes[:vlan_hard] || "0")
    xm.ramSoft(attributes[:ram_soft] || "0")
    xm.ramHard(attributes[:ram_hard] || "0")
    xm.publicIpsSoft(attributes[:public_ip_soft] || "0" ) 
    xm.publicIpsHard(attributes[:public_ip_hard] || "0") 
    xm.hdSoft(attributes[:hd_soft] || "0")
    xm.hdHard(attributes[:hd_hard] || "0" )
    xm.storageSoft(attributes[:storage_soft] || "0")
    xm.storageHard(attributes[:storage_hard] || "0")
    xm.hypervisorType attributes[:hypervisortype]
    xm.network {
      xm.name(attributes[:network].name || 'defaultNetwork')
      xm.gateway(attributes[:network].gateway || '192.168.1.1')
      xm.address(attributes[:network].address || '192.168.1.0')
      xm.mask(attributes[:network].mask || '24')
      xm.defaultNetwork(attributes[:network].default_network || true)
    }
  }
  res = RestClient.post(Api.url + "/cloud/virtualdatacenters/?datacenter=#{datacenter}&enterprise=#{enterprise}", xm.target!, :content_type => :xml)
  VDC.parse(res)
end

.find_by_name(name, options = {}) ⇒ Object



660
661
662
# File 'lib/webee.rb', line 660

def self.find_by_name(name, options = {})
  VDC.all(options).find_all { |vdc| vdc.name =~ /#{name}/ }
end

Instance Method Details

#deleteObject



664
665
666
# File 'lib/webee.rb', line 664

def delete
  RestClient.delete(Api.url + "/cloud/virtualdatacenters/#{vdc_id}")
end

#to_xmlObject



608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/webee.rb', line 608

def to_xml
  xm = Builder::XmlMarkup.new
  xm.virtualDatacenter {
    xm.name name
    xm.cpuSoft(cpu_soft || "0")
    xm.cpuHard(cpu_hard || "0")
    xm.vlanSoft(vlan_soft || "0")
    xm.vlanHard(vlan_hard || "0")
    xm.ramSoft(ram_soft || "0")
    xm.ramHard(ram_hard || "0")
    xm.repositorySoft(repository_soft || "0")  
    xm.repositoryHard(repository_hard || "0") 
    xm.publicIpsSoft(public_ip_soft || "0" ) 
    xm.publicIpsHard(public_ip_hard || "0" ) 
    xm.hdSoft(hd_soft || "0")
    xm.hdHard(hd_hard || "0")
    xm.storageSoft(storage_soft || "0")
    xm.storageHard(storage_hard || "0")
    xm.network {
      xm.name(network.name || 'defaultNetwork')
      xm.gateway(network.gateway || '192.168.1.1')
      xm.address(network.address || '192.168.1.0')
      xm.mask(network.mask || '24')
      xm.defaultNetwork(netowork.default_network || true)
    }
  }
  xm.target!
end

#virtual_appliancesObject

List all the virtual appliances in this virtual datacenter



671
672
673
674
675
676
677
678
679
680
# File 'lib/webee.rb', line 671

def virtual_appliances
  items = []
  doc = Nokogiri.parse(RestClient.get(Api.url + "/cloud/virtualdatacenters/#{vdc_id}/virtualappliances", :accept => :xml))
  doc.search('//virtualAppliance').each do |node|
    vapp = VirtualAppliance.parse(node.to_s)
    vapp.vdc_id = vdc_id
    items << vapp
  end
  items
end