Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[libvirt] added display attributes and allowed to change display of a…

… running server
  • Loading branch information...
commit 244bc100103f3237745ea54005b532a7f4a728ce 1 parent 1ed7a6b
@ohadlevy ohadlevy authored ohadlevy committed
View
1  lib/fog/libvirt/compute.rb
@@ -44,6 +44,7 @@ class Libvirt < Fog::Service
request :list_interfaces
request :destroy_interface
request :get_node_info
+ request :update_display
module Shared
include Fog::Compute::LibvirtUtil
View
14 lib/fog/libvirt/models/compute/server.rb
@@ -24,11 +24,11 @@ class Server < Fog::Compute::Server
attribute :domain_type
attribute :uuid
attribute :autostart
- attribute :vnc_port
attribute :nics
attribute :volumes
attribute :active
attribute :boot_order
+ attribute :display
attribute :state
@@ -223,6 +223,11 @@ def setup(credentials = {})
Fog::SSH.new(public_ip_address, username, credentials).run(commands)
end
+ def update_display attrs = {}
+ connection.update_display attrs.merge(:uuid => uuid)
+ reload
+ end
+
private
attr_accessor :volumes_path
@@ -385,7 +390,8 @@ def defaults
:network_interface_type => "network",
:network_nat_network => "default",
:network_bridge_name => "br0",
- :boot_order => default_boot_order
+ :boot_order => default_boot_order,
+ :display => default_display
}
end
@@ -401,6 +407,10 @@ def verify_boot_order order = []
end
end
+ def default_display
+ {:port => '-1', :listen => '127.0.0.1', :type => 'vnc', :password => '' }
+ end
+
end
end
View
2  lib/fog/libvirt/models/compute/templates/server.xml.erb
@@ -44,7 +44,7 @@
<target port='0'/>
</console>
<input type='mouse' bus='ps2'/>
- <graphics type='vnc' port='-1' autoport='yes'/>
+ <graphics type='<%= display[:type] %>' port='<%= display[:port] %>' autoport='yes' listen='<%= display[:listen] %>' passwd='<%=display[:password] %>'/>
<video>
<model type='cirrus' vram='9216' heads='1'/>
</video>
View
13 lib/fog/libvirt/requests/compute/list_domains.rb
@@ -20,11 +20,12 @@ def list_domains(filter = { })
module Shared
private
- def vnc_port xml
- xml_element(xml, "domain/devices/graphics[@type='vnc']", "port")
- rescue => e
- # we might be using SPICE display, or no VNC display at all
- nil
+ def domain_display xml
+ attrs = {}
+ [:type, :port, :password, :listen].each do |element|
+ attrs[element] = xml_element(xml, "domain/devices/graphics",element.to_s) rescue nil
+ end
+ attrs.reject{|k,v| v.nil? or v == ""}
end
def domain_volumes xml
@@ -61,7 +62,7 @@ def domain_to_attributes(dom)
:autostart => dom.autostart?,
:os_type => dom.os_type,
:active => dom.active?,
- :vnc_port => vnc_port(dom.xml_desc),
+ :display => domain_display(dom.xml_desc),
:boot_order => boot_order(dom.xml_desc),
:nics => domain_interfaces(dom.xml_desc),
:volumes_path => domain_volumes(dom.xml_desc),
View
31 lib/fog/libvirt/requests/compute/update_display.rb
@@ -0,0 +1,31 @@
+module Fog
+ module Compute
+ class Libvirt
+ class Real
+ 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
+ end
+
+ class Mock
+ def update_display(options = { })
+ raise ArgumentError, "uuid is a required parameter" unless options.has_key? :uuid
+ true
+ end
+ end
+ end
+ end
+end
View
2  tests/libvirt/models/compute/server_tests.rb
@@ -34,7 +34,7 @@
:domain_type,
:uuid,
:autostart,
- :vnc_port,
+ :display,
:nics,
:volumes,
:active,
View
13 tests/libvirt/requests/compute/update_display.rb
@@ -0,0 +1,13 @@
+Shindo.tests('Fog::Compute[:libvirt] | update_display request', ['libvirt']) do
+
+ compute = Fog::Compute[:libvirt]
+
+ reconfig_target = 'f74d728a-5b62-7e2f-1f84-239aead298ca'
+ display_spec = {:password => 'ssaaa'}
+
+ tests('The response should') do
+ response = compute.update_display(:uuid => reconfig_target).merge(display_spec)
+ test('should be true').succeeds { response }
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.