Class: WeBee::VDC
Overview
A virtual datacenter FIXME: Unimplemented
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #to_xml ⇒ Object
-
#virtual_appliances ⇒ Object
List all the virtual appliances in this virtual datacenter.
Methods included from SAXMachine
Class Method Details
.all(params = {}) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/webee.rb', line 558 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
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'lib/webee.rb', line 489 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 |
Instance Method Details
#delete ⇒ Object
585 586 587 |
# File 'lib/webee.rb', line 585 def delete RestClient.delete(Api.url + "/cloud/virtualdatacenters/#{vdc_id}") end |
#to_xml ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/webee.rb', line 529 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_appliances ⇒ Object
List all the virtual appliances in this virtual datacenter
592 593 594 595 596 597 598 599 600 601 |
# File 'lib/webee.rb', line 592 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 |