Skip to content

Commit

Permalink
fixedrefactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bublik committed Mar 19, 2012
1 parent 3779305 commit 6aec2eb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/configure.rb
Expand Up @@ -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")
@conn = Libvirt::open("qemu+ssh://#{@hypervisor['user']}@#{@hypervisor['host']}/system")
48 changes: 24 additions & 24 deletions examples/connet_to_hv.rb
Expand Up @@ -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}"
Expand All @@ -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}"
Expand All @@ -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?}"
9 changes: 9 additions & 0 deletions examples/dom_stats.rb
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions examples/domain_destroy.rb
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions examples/domain_start.rb
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -109,6 +109,6 @@
puts "Undefining permanent domain ruby-libvirt-tester"
dom.undefine

conn.close
@conn.close


8 changes: 4 additions & 4 deletions examples/vms_list.rb
Expand Up @@ -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

0 comments on commit 6aec2eb

Please sign in to comment.