lib/rbovirt.rb in rbovirt-0.0.2 vs lib/rbovirt.rb in rbovirt-0.0.3

- old
+ new

@@ -3,10 +3,12 @@ require "ovirt/datacenter" require "ovirt/host" require "ovirt/storage_domain" require "ovirt/template" require "ovirt/vm" +require "ovirt/disk" +require "ovirt/nic" require "nokogiri" require "rest_client" module OVIRT @@ -31,20 +33,26 @@ @credentials = { :username => username, :password => password } @datacenter_id = datacenter_id @api_entrypoint = api_entrypoint end - def vm(vm_id) + def vm(vm_id, opts={}) headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"} - vm = http_get("/vms/%s" % vm_id, headers).root - OVIRT::VM::new(self, vm) + vm = OVIRT::VM::new(self, http_get("/vms/%s" % vm_id, headers).root) + vm.nics = http_get("/vms/%s/nics" % vm_id, headers).xpath('/nics/nic').collect do |nic| + OVIRT::Nic::new(self, nic) + end if opts[:nics] + vm.disks = http_get("/vms/%s/disks" % vm_id, headers).xpath('/disks/disk').collect do |disk| + OVIRT::Disk::new(self, disk) + end if opts[:disks] + vm end def vms(opts={}) headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"} - search= opts[:search] || ("datacenter=$s" % current_datacenter.name) - http_get("/vms?search=%s" % search, headers).xpath('/vms/vm').collect do |vm| + search= opts[:search] || ("datacenter=%s" % current_datacenter.name) + http_get("/vms?search=%s" % CGI.escape(search), headers).xpath('/vms/vm').collect do |vm| OVIRT::VM::new(self, vm) end end def vm_action(id, action, opts={}) @@ -76,15 +84,15 @@ OVIRT::VM::new(self, result_xml.root) end def add_disk(vm_id, opts={}) storage_domain_id = opts[:storage_domain] || storagedomains.first.id - result_xml = http_post("/vms/%s/disks" % vm_id, VM.disk_xml(storage_domain_id, opts)) + result_xml = http_post("/vms/%s/disks" % vm_id, OVIRT::Disk.to_xml(storage_domain_id, opts)) end def add_nic(vm_id, opts={}) - http_post("/vms/%s/nics" % vm_id, VM.nic_xml( opts)) + http_post("/vms/%s/nics" % vm_id, OVIRT::Nic.to_xml( opts)) end def create_template(vm_id, opts) template = http_post("/templates", Template.to_xml(vm_id, opts)) OVIRT::Template::new(self, template.root) \ No newline at end of file