diff --git a/examples/configure.rb b/examples/configure.rb index 1308950..a8d86ff 100644 --- a/examples/configure.rb +++ b/examples/configure.rb @@ -18,4 +18,4 @@ puts "Libvirt version: #{ver[0]}" puts "Hypervisor Type version: #{ver[1]}" -conn = Libvirt::open("qemu+ssh://#{@hypervisor['user']}@#{@hypervisor['host']}/system") \ No newline at end of file +@conn = Libvirt::open("qemu+ssh://#{@hypervisor['user']}@#{@hypervisor['host']}/system") \ No newline at end of file diff --git a/examples/connet_to_hv.rb b/examples/connet_to_hv.rb index 1ecad1b..6d1c05b 100755 --- a/examples/connet_to_hv.rb +++ b/examples/connet_to_hv.rb @@ -4,7 +4,7 @@ # retrieve basic information about the hypervisor. See the libvirt # documentation for more information about what each of these fields mean. -nodeinfo = conn.node_get_info +nodeinfo = @conn.node_get_info puts "Hypervisor Nodeinfo:" puts " Model: #{nodeinfo.model}" puts " Memory: #{nodeinfo.memory}" @@ -17,7 +17,7 @@ # print the amount of free memory in every NUMA node on the hypervisor begin - cellsmem = conn.node_cells_free_memory + cellsmem = @conn.node_cells_free_memory puts "Hypervisor NUMA node free memory:" cellsmem.each_with_index do |cell,index| puts " Node #{index}: #{cell}" @@ -26,54 +26,54 @@ # this call may not be supported; if so, just ignore end -# print the type of the connection. This will be "QEMU" for qemu, "XEN" for +# print the type of the @connection. This will be "QEMU" for qemu, "XEN" for # xen, etc. -puts "Hypervisor Type: #{conn.type}" +puts "Hypervisor Type: #{@conn.type}" # print the hypervisor version -puts "Hypervisor Version: #{conn.version}" +puts "Hypervisor Version: #{@conn.version}" # print the libvirt version on the hypervisor -puts "Hypervisor Libvirt version: #{conn.libversion}" +puts "Hypervisor Libvirt version: #{@conn.libversion}" # print the hypervisor hostname (deprecated) -puts "Hypervisor Hostname: #{conn.hostname}" -puts "Hypervisor Max Vcpus: #{conn.max_vcpus}" -puts "Domains (VMs - online): #{conn.num_of_domains}" -puts "Retrieve a list of inactive domain names on this connection: #{conn.list_defined_domains.inspect}" +puts "Hypervisor Hostname: #{@conn.hostname}" +puts "Hypervisor Max Vcpus: #{@conn.max_vcpus}" +puts "Domains (VMs - online): #{@conn.num_of_domains}" +puts "Retrieve a list of inactive domain names on this @connection: #{@conn.list_defined_domains.inspect}" -online_domains = conn.list_domains +online_domains = @conn.list_domains puts "Online Domains: #{online_domains.inspect}" puts 'GET get domain info by ID:' -puts conn.lookup_domain_by_id(online_domains.first).inspect +puts @conn.lookup_domain_by_id(online_domains.first).inspect -# print the URI in use on this connection. Note that this may be different +# print the URI in use on this @connection. Note that this may be different # from the one passed into Libvirt::open, since libvirt may decide to # canonicalize the URI -puts "Hypervisor URI: #{conn.uri}" +puts "Hypervisor URI: #{@conn.uri}" # print the amount of free memory on the hypervisor begin - puts "Hypervisor Free Memory: #{conn.node_free_memory}" + puts "Hypervisor Free Memory: #{@conn.node_free_memory}" rescue # this call may not be supported; if so, just ignore end # print the security model in use on the hypervisor -secmodel = conn.node_get_security_model +secmodel = @conn.node_get_security_model puts "Hypervisor Security Model:" puts " Model: #{secmodel.model}" puts " DOI: #{secmodel.doi}" -# print whether the connection to the hypervisor is encrypted -puts "Hypervisor connection encrypted?: #{conn.encrypted?}" -# print whether the connection to the hypervisor is secure -puts "Hypervisor connection secure?: #{conn.secure?}" +# print whether the @connection to the hypervisor is encrypted +puts "Hypervisor @connection encrypted?: #{@conn.encrypted?}" +# print whether the @connection to the hypervisor is secure +puts "Hypervisor @connection secure?: #{@conn.secure?}" # print the capabilities XML for the hypervisor. A detailed explanation of # the XML format can be found in the libvirt documentation. #puts "Hypervisor capabilities XML:" -#puts conn.capabilities +#puts @conn.capabilities # -# # close the connection - conn.close +# # close the @connection + @conn.close # # # after close, the closed? should return true - puts "After close, connection closed?: #{conn.closed?}" + puts "After close, @connection closed?: #{@conn.closed?}" diff --git a/examples/dom_stats.rb b/examples/dom_stats.rb index cd1de70..a927054 100644 --- a/examples/dom_stats.rb +++ b/examples/dom_stats.rb @@ -2,3 +2,12 @@ require './configure.rb' +active_domains = conn.list_domains + +begin + dom = @conn.lookup_domain_by_id(active_domains.first) +rescue + puts 'There is not found avtive domains' +end + +dom.block_stats(path) \ No newline at end of file diff --git a/examples/domain_destroy.rb b/examples/domain_destroy.rb index 2e4dd81..6959861 100755 --- a/examples/domain_destroy.rb +++ b/examples/domain_destroy.rb @@ -8,14 +8,14 @@ #puts 'GET get domain info by ID:' #dom = conn.lookup_domain_by_id(online_domains.first) -dom = conn.lookup_domain_by_name('hw21tb33hlum1a') +dom = @conn.lookup_domain_by_name('hw21tb33hlum1a') puts "Domain name: #{dom.name}" puts "Domain info: #{dom.info.inspect}" -puts "Active domains: #{conn.list_domains}.inspect" +puts "Active domains: #{@conn.list_domains}.inspect" puts "ACTIVE ? " + dom.active?.inspect puts "Shutdown" dom.shutdown -puts "Active domains: #{conn.list_domains}.inspect" +puts "Active domains: #{@conn.list_domains}.inspect" diff --git a/examples/domain_start.rb b/examples/domain_start.rb index de5382a..4952280 100755 --- a/examples/domain_start.rb +++ b/examples/domain_start.rb @@ -62,7 +62,7 @@ # once they are stopped, libvirt forgets about them. puts "Creating transient domain ruby-libvirt-tester" begin - dom = conn.create_domain_xml(new_dom_xml) + dom = @conn.create_domain_xml(new_dom_xml) rescue dom.undefine end @@ -75,7 +75,7 @@ # makes libvirt aware of the domain as a persistent entity; it does not start # or otherwise change the domain puts "Defining permanent domain ruby-libvirt-tester" -dom = conn.define_domain_xml(new_dom_xml) +dom = @conn.define_domain_xml(new_dom_xml) # start the domain puts "Starting permanent domain ruby-libvirt-tester" @@ -86,7 +86,7 @@ puts "Domain name: #{dom.name}" puts "Domain info: #{dom.info.inspect}" puts "ACTIVE ? " + dom.active?.inspect -puts "Active domains: #{conn.list_domains}.inspect" +puts "Active domains: #{@conn.list_domains}.inspect" begin @@ -109,6 +109,6 @@ puts "Undefining permanent domain ruby-libvirt-tester" dom.undefine -conn.close +@conn.close diff --git a/examples/vms_list.rb b/examples/vms_list.rb index 5571671..cd128af 100755 --- a/examples/vms_list.rb +++ b/examples/vms_list.rb @@ -3,20 +3,20 @@ require './configure.rb' # list of inactive domain names on this connection. -list_defined_domains = conn.list_defined_domains +list_defined_domains = @conn.list_defined_domains puts "Offline domains: #{list_defined_domains.inspect}" list_defined_domains.each do |name| - dom = conn.lookup_domain_by_name(name) + dom = @conn.lookup_domain_by_name(name) puts dom.name end puts '==============' # list active VMs -online_domains = conn.list_domains +online_domains = @conn.list_domains puts "Online domains: #{online_domains.inspect}" online_domains.each do |dom_id| - _dom = conn.lookup_domain_by_id(dom_id.to_i) + _dom = @conn.lookup_domain_by_id(dom_id.to_i) puts _dom.name end