Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Add the ability to supply a XML string in addition to a XML file
Browse files Browse the repository at this point in the history
when defining domains

In the application if the path to the xml file provided is a local
file it will send that file else it will assume its a remote file

The hvinfo action can now optionally send back all the facts for a
machine
  • Loading branch information
ripienaar committed Sep 24, 2011
1 parent f8e76c5 commit 48c8375
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
28 changes: 27 additions & 1 deletion agent/libvirt/agent/libvirt.ddl
Expand Up @@ -2,13 +2,19 @@ metadata :name => "libvirt",
:description => "SimpleRPC Libvirt Agent",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "ASL2.0",
:version => "0.1",
:version => "0.2",
:url => "http://devco.net/",
:timeout => 10

action "hvinfo", :description => "Hypervisor Information" do
display :always

input :facts,
:prompt => "Include Facts?",
:description => "Also include Facter in the reply",
:type => :boolean,
:optional => true

output :model,
:description => "Hypervisor Model",
:display_as => "Model"
Expand Down Expand Up @@ -112,6 +118,10 @@ action "hvinfo", :description => "Hypervisor Information" do
output :num_of_secrets,
:description => "Number of secrets",
:display_as => "Secrets"

output :facts,
:description => "Facts about this machine",
:display_as => "Facts"
end

action "domaininfo", :description => "Domain Information" do
Expand Down Expand Up @@ -205,6 +215,22 @@ action "definedomain", :description => "Defines a domain from a XML file describ
:optional => false,
:maxlength => 50

input :xmlfile,
:prompt => "XML File",
:description => "Libvirt XML file",
:type => :string,
:validation => '^.+$',
:optional => true,
:maxlength => 200

input :xml,
:prompt => "XML Definition",
:description => "Libvirt XML",
:type => :string,
:validation => '^.+$',
:optional => true,
:maxlength => 0

input :permanent,
:prompt => "Permanent",
:description => "Should the domain persist reboots",
Expand Down
17 changes: 14 additions & 3 deletions agent/libvirt/agent/libvirt.rb
Expand Up @@ -7,7 +7,7 @@ class Libvirt<RPC::Agent
:description => "SimpleRPC Libvirt Agent",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "ASL2.0",
:version => "0.1",
:version => "0.2",
:url => "http://devco.net/",
:timeout => 10

Expand Down Expand Up @@ -46,6 +46,8 @@ class Libvirt<RPC::Agent
reply[:active_domains].sort!

reply[:inactive_domains] = conn.list_defined_domains.sort

reply[:facts] = PluginManager["facts_plugin"].get_facts if request[:facts]
rescue Exception => e
reply.fail! "Could not load hvm info: #{e}"
ensure
Expand Down Expand Up @@ -110,14 +112,23 @@ class Libvirt<RPC::Agent
end

action "definedomain" do
validate :xmlfile, String
validate :xmlfile, String if request.include?[:xmlfile]
validate :xml, String if request.include?[:xml]
validate :domain, String

reply.fail!("Can't find XML file defining instance") unless File.exist?(request[:xmlfile])

begin
conn = connect
xml = File.read(request[:xmlfile])

if request[:xmlfile]
xml = File.read(request[:xmlfile])
elsif request[:xml]
xml = File.read(request[:xml])
else
reply.fail!("Need either xmlfile or xml parameters to define a domain")
end


if request[:permanent]
conn.define_domain_xml(xml)
Expand Down
11 changes: 8 additions & 3 deletions agent/libvirt/application/virt.rb
Expand Up @@ -7,7 +7,7 @@ class MCollective::Application::Virt<MCollective::Application
usage "Usage: mco virt find <pattern>"
usage "Usage: mco virt [stop|start|reboot|suspend|resume|destroy] <domain>"
usage "Usage: mco virt domains"
usage "Usage: mco virt define <domain> <remote xml file> [permanent]"
usage "Usage: mco virt define <domain> <local or remote xml file> [permanent]"
usage "Usage: mco virt undefine <domain> [destroy]"

def post_option_parser(configuration)
Expand Down Expand Up @@ -36,10 +36,15 @@ def define_command
configuration[:xmlfile] = ARGV.shift if ARGV.size > 0
configuration[:perm] = ARGV.shift if ARGV.size > 0

raise "Need a path to a remote XML file to define an instance" unless configuration[:xmlfile]
raise "Need a XML file to define an instance" unless configuration[:xmlfile]

args = {}
args[:xmlfile] = configuration[:xmlfile]
if File.exist?(configuration[:xmlfile])
args[:xml] = File.read(configuration[:xmlfile])
else
args[:xmlfile] = configuration[:xmlfile]
end

args[:permanent] = true if configuration[:perm].to_s =~ /^perm/
args[:domain] = configuration[:domain]

Expand Down

0 comments on commit 48c8375

Please sign in to comment.