# File lib/fog/libvirt/compute.rb, line 80 def initialize(options={}) @uri = ::Fog::Compute::LibvirtUtil::URI.new(enhance_uri(options[:libvirt_uri])) @ip_command = options[:libvirt_ip_command] # libvirt is part of the gem => ruby-libvirt begin require 'libvirt' rescue LoadError => e retry if require('rubygems') raise e.message end begin if options[:libvirt_username] and options[:libvirt_password] @client = ::Libvirt::open_auth(uri.uri, [::Libvirt::CRED_AUTHNAME, ::Libvirt::CRED_PASSPHRASE]) do |cred| case cred['type'] when ::Libvirt::CRED_AUTHNAME options[:libvirt_username] when ::Libvirt::CRED_PASSPHRASE options[:libvirt_password] end end else @client = ::Libvirt::open(uri.uri) end rescue ::Libvirt::ConnectionError raise Fog::Errors::Error.new("Error making a connection to libvirt URI #{uri.uri}:\n#{$!}") end end
# File lib/fog/libvirt/requests/compute/create_domain.rb, line 5 def create_domain(xml) client.create_domain_xml(xml) end
# File lib/fog/libvirt/requests/compute/create_volume.rb, line 5 def create_volume(pool_name, xml) client.lookup_storage_pool_by_name(pool_name).create_vol_xml(xml) end
# File lib/fog/libvirt/requests/compute/define_domain.rb, line 5 def define_domain(xml) client.define_domain_xml(xml) end
# File lib/fog/libvirt/requests/compute/define_pool.rb, line 5 def define_pool(xml) client.define_storage_pool_xml(xml) end
shutdown the interface
# File lib/fog/libvirt/requests/compute/destroy_interface.rb, line 6 def destroy_interface(uuid) client.lookup_interface_by_uuid(uuid).destroy end
# File lib/fog/libvirt/requests/compute/destroy_network.rb, line 5 def destroy_network(uuid) client.lookup_network_by_uuid(uuid).destroy end
# File lib/fog/libvirt/compute.rb, line 116 def enhance_uri(uri) require 'cgi' append="" # on macosx, chances are we are using libvirt through homebrew # the client will default to a socket location based on it's own location (/opt) # we conveniently point it to /var/run/libvirt/libvirt-sock # if no socket option has been specified explicitly if RUBY_PLATFORM =~ /darwin/ querystring=::URI.parse(uri).query if querystring.nil? append="?socket=/var/run/libvirt/libvirt-sock" else if !::CGI.parse(querystring).has_key?("socket") append="&socket=/var/run/libvirt/libvirt-sock" end end end uri+append end
# File lib/fog/libvirt/requests/compute/get_node_info.rb, line 5 def get_node_info node_hash = Hash.new node_info = client.node_get_info [:model, :memory, :cpus, :mhz, :nodes, :sockets, :cores, :threads].each do |param| node_hash[param] = node_info.send(param) rescue nil end [:type, :version, :node_free_memory, :max_vcpus].each do |param| node_hash[param] = client.send(param) rescue nil end node_hash[:uri] = client.uri xml = client.sys_info rescue nil [:uuid, :manufacturer, :product, :serial].each do |attr| node_hash[attr] = node_attr(attr, xml) rescue nil end if xml node_hash[:hostname] = client.hostname [node_hash] end
# File lib/fog/libvirt/requests/compute/list_domains.rb, line 5 def list_domains(filter = { }) data=[] if filter.has_key?(:uuid) data << client.lookup_domain_by_uuid(filter[:uuid]) elsif filter.has_key?(:name) data << client.lookup_domain_by_name(filter[:name]) else client.list_defined_domains.each { |name| data << client.lookup_domain_by_name(name) } unless filter[:defined] == false client.list_domains.each { |id| data << client.lookup_domain_by_id(id) } unless filter[:active] == false end data.compact.map { |d| domain_to_attributes d } end
# File lib/fog/libvirt/requests/compute/list_interfaces.rb, line 5 def list_interfaces(filter = { }) data=[] if filter.keys.empty? active_networks = client.list_interfaces rescue [] defined_networks = client.list_defined_interfaces rescue [] (active_networks + defined_networks).each do |ifname| data << interface_to_attributes(client.lookup_interface_by_name(ifname)) end else data = [interface_to_attributes(get_interface_by_filter(filter))] end data.compact end
# File lib/fog/libvirt/requests/compute/list_networks.rb, line 5 def list_networks(filter = { }) data=[] if filter.keys.empty? (client.list_networks + client.list_defined_networks).each do |network_name| data << network_to_attributes(client.lookup_network_by_name(network_name)) end else data = [network_to_attributes(get_network_by_filter(filter))] end data end
# File lib/fog/libvirt/requests/compute/list_pool_volumes.rb, line 5 def list_pool_volumes(uuid) pool = client.lookup_storage_pool_by_uuid uuid pool.list_volumes.map do |volume_name| volume_to_attributes(pool.lookup_volume_by_name(volume_name)) end end
# File lib/fog/libvirt/requests/compute/list_pools.rb, line 5 def list_pools(filter = { }) data=[] if filter.has_key?(:name) data << find_pool_by_name(filter[:name]) elsif filter.has_key?(:uuid) data << find_pool_by_uuid(filter[:uuid]) else (client.list_storage_pools + client.list_defined_storage_pools).each do |name| data << find_pool_by_name(name) end end data.compact end
# File lib/fog/libvirt/requests/compute/list_volumes.rb, line 5 def list_volumes(filter = { }) data = [] if filter.keys.empty? raw_volumes do |pool| pool.list_volumes.each do |volume_name| data << volume_to_attributes(pool.lookup_volume_by_name(volume_name)) end end else return [get_volume(filter)] end data.compact end
# File lib/fog/libvirt/requests/compute/pool_action.rb, line 5 def pool_action(uuid, action) pool = client.lookup_storage_pool_by_uuid uuid pool.send(action) true end
# File lib/fog/libvirt/compute.rb, line 112 def terminate @client.close if @client and !@client.closed? end
# File lib/fog/libvirt/requests/compute/update_display.rb, line 5 def update_display(options = { }) raise ArgumentError, "uuid is a required parameter" unless options.has_key? :uuid display = { } display[:type] = options[:type] || 'vnc' display[:port] = (options[:port] || -1).to_s display[:listen] = options[:listen].to_s if options[:listen] display[:passwd] = options[:password].to_s if options[:password] display[:autoport] = 'yes' if display[:port] == '-1' builder = Nokogiri::XML::Builder.new { graphics_ (display) } xml = Nokogiri::XML(builder.to_xml).root.to_s client.lookup_domain_by_uuid(options[:uuid]).update_device(xml, 0) # if we got no exceptions, then we're good' true end
Generated with the Darkfish Rdoc Generator 2.