WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Added support for configuration file for

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Added support for configuration file for xm, and use that to specify
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 06 Dec 2006 22:10:19 +0000
Delivery-date: Wed, 06 Dec 2006 14:10:07 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Node ID cf1ca06154147cb49b41fc56835ee2cffea31e32
# Parent  92127156ec49568f737b54ff093bdca56e877097
Added support for configuration file for xm, and use that to specify
contact and authentication details for the Xen-API server.

The default behaviour is still to use the existing legacy XML-RPC server.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/examples/xm-config.xml    |   43 +++++++++++++++++++
 tools/python/xen/xm/create.py   |    2 
 tools/python/xen/xm/main.py     |   89 +++++++++++++++++++++++++++++++++++++---
 tools/python/xen/xm/migrate.py  |    3 -
 tools/python/xen/xm/new.py      |    5 --
 tools/python/xen/xm/shutdown.py |    4 -
 6 files changed, 134 insertions(+), 12 deletions(-)

diff -r 92127156ec49 -r cf1ca0615414 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Wed Dec 06 10:47:31 2006 +0000
+++ b/tools/python/xen/xm/create.py     Wed Dec 06 11:02:32 2006 +0000
@@ -29,13 +29,13 @@ from xen.xend import sxp
 from xen.xend import sxp
 from xen.xend import PrettyPrint
 import xen.xend.XendClient
-from xen.xend.XendClient import server
 from xen.xend.XendBootloader import bootloader
 from xen.util import blkif
 from xen.util import security
 
 from xen.xm.opts import *
 
+from main import server
 import console
 
 
diff -r 92127156ec49 -r cf1ca0615414 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Wed Dec 06 10:47:31 2006 +0000
+++ b/tools/python/xen/xm/main.py       Wed Dec 06 11:02:32 2006 +0000
@@ -21,6 +21,7 @@
 
 """Grand unified management application for Xen.
 """
+import atexit
 import os
 import sys
 import re
@@ -31,6 +32,7 @@ import traceback
 import traceback
 import datetime
 from select import select
+import xml.dom.minidom
 
 import warnings
 warnings.filterwarnings('ignore', category=FutureWarning)
@@ -38,18 +40,26 @@ from xen.xend import PrettyPrint
 from xen.xend import PrettyPrint
 from xen.xend import sxp
 from xen.xend import XendClient
-from xen.xend.XendClient import server
 from xen.xend.XendConstants import *
 
 from xen.xm.opts import OptionError, Opts, wrap, set_true
 from xen.xm import console
 from xen.util import security
+from xen.util.xmlrpclib2 import ServerProxy
+
+import XenAPI
 
 # getopt.gnu_getopt is better, but only exists in Python 2.3+.  Use
 # getopt.getopt if gnu_getopt is not available.  This will mean that options
 # may only be specified before positional arguments.
 if not hasattr(getopt, 'gnu_getopt'):
     getopt.gnu_getopt = getopt.getopt
+
+XM_CONFIG_FILE = '/etc/xen/xm-config.xml'
+
+# Supported types of server
+SERVER_LEGACY_XMLRPC = 'LegacyXMLRPC'
+SERVER_XEN_API = 'Xen-API'
 
 # General help message
 
@@ -319,6 +329,35 @@ all_commands = (domain_commands + host_c
 all_commands = (domain_commands + host_commands + scheduler_commands +
                 device_commands + vnet_commands + acm_commands)
 
+
+##
+# Configuration File Parsing
+##
+
+if os.path.isfile(XM_CONFIG_FILE):
+    config = xml.dom.minidom.parse(XM_CONFIG_FILE)
+else:
+    config = None
+
+def parseServer():
+    if config:
+        server = config.getElementsByTagName('server')
+        if server:
+            st = server[0].getAttribute('type')
+            if st != SERVER_XEN_API:
+                st = SERVER_LEGACY_XMLRPC
+            return (st, server[0].getAttribute('uri'))
+
+    return SERVER_LEGACY_XMLRPC, XendClient.uri
+
+def parseAuthentication():
+    server = config.getElementsByTagName('server')[0]
+    return (server.getAttribute('username'),
+            server.getAttribute('password'))
+
+serverType, serverURI = parseServer()
+
+
 ####################################################################
 #
 #  Help/usage printing functions
@@ -467,6 +506,16 @@ def int_unit(str, dest):
 
 def err(msg):
     print >>sys.stderr, "Error:", msg
+
+
+def get_single_vm(dom):
+    uuids = server.xenapi.VM.get_by_name_label(dom)
+    n = len(uuids)
+    if n == 1:
+        return uuids[0]
+    else:
+        dominfo = server.xend.domain(dom, False)
+        return dominfo['uuid']
 
 
 #########################################################################
@@ -767,17 +816,26 @@ def xm_start(args):
         sys.exit(1)
 
     dom = params[0]
-    server.xend.domain.start(dom, paused)
+    if serverType == SERVER_XEN_API:
+        server.xenapi.VM.start(get_single_vm(dom), paused)
+    else:
+        server.xend.domain.start(dom, paused)
 
 def xm_delete(args):
     arg_check(args, "delete", 1)
     dom = args[0]
-    server.xend.domain.delete(dom)
+    if serverType == SERVER_XEN_API:
+        server.xenapi.VM.destroy(dom)
+    else:
+        server.xend.domain.delete(dom)
 
 def xm_suspend(args):
     arg_check(args, "suspend", 1)
     dom = args[0]
-    server.xend.domain.suspend(dom)
+    if serverType == SERVER_XEN_API:
+        server.xenapi.VM.suspend(get_single_vm(dom))
+    else:
+        server.xend.domain.suspend(dom)
 
 def xm_resume(args):
     arg_check(args, "resume", 1, 2)
@@ -799,7 +857,10 @@ def xm_resume(args):
         sys.exit(1)
 
     dom = params[0]
-    server.xend.domain.resume(dom, paused)
+    if serverType == SERVER_XEN_API:
+        server.xenapi.VM.resume(dom, paused)
+    else:
+        server.xend.domain.resume(dom, paused)
     
 def xm_reboot(args):
     arg_check(args, "reboot", 1, 3)
@@ -1577,6 +1638,8 @@ def deprecated(old,new):
         "Command %s is deprecated.  Please use xm %s instead." % (old, new))
 
 def main(argv=sys.argv):
+    global server
+
     if len(argv) < 2:
         usage()
 
@@ -1595,6 +1658,19 @@ def main(argv=sys.argv):
     args = argv[2:]
     if cmd:
         try:
+            if serverType == SERVER_XEN_API:
+                server = XenAPI.Session(serverURI)
+                username, password = parseAuthentication()
+                server.login_with_password(username, password)
+                def logout():
+                    try:
+                        server.xenapi.session.logout()
+                    except:
+                        pass
+                atexit.register(logout)
+            else:
+                server = ServerProxy(serverURI)
+
             rc = cmd(args)
             if rc:
                 usage()
@@ -1614,6 +1690,9 @@ def main(argv=sys.argv):
                 err("Unable to connect to xend: %s." % ex[1])
             sys.exit(1)
         except SystemExit:
+            sys.exit(1)
+        except XenAPI.Failure, exn:
+            err(str(exn))
             sys.exit(1)
         except xmlrpclib.Fault, ex:
             if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
diff -r 92127156ec49 -r cf1ca0615414 tools/python/xen/xm/migrate.py
--- a/tools/python/xen/xm/migrate.py    Wed Dec 06 10:47:31 2006 +0000
+++ b/tools/python/xen/xm/migrate.py    Wed Dec 06 11:02:32 2006 +0000
@@ -21,8 +21,9 @@
 
 import sys
 
-from xen.xend.XendClient import server
 from xen.xm.opts import *
+
+from main import server
 
 gopts = Opts(use="""[options] DOM HOST
 
diff -r 92127156ec49 -r cf1ca0615414 tools/python/xen/xm/new.py
--- a/tools/python/xen/xm/new.py        Wed Dec 06 10:47:31 2006 +0000
+++ b/tools/python/xen/xm/new.py        Wed Dec 06 11:02:32 2006 +0000
@@ -21,10 +21,9 @@ from xen.xend import PrettyPrint
 from xen.xend import PrettyPrint
 from xen.xend import sxp
 from xen.xend import XendClient
-from xen.xend.XendClient import server
 
-from xen.xm.opts import *
-from xen.xm.create import *
+from opts import *
+from create import *
 
 def make_unstarted_domain(opts, config):
     """Create an unstarted domain.
diff -r 92127156ec49 -r cf1ca0615414 tools/python/xen/xm/shutdown.py
--- a/tools/python/xen/xm/shutdown.py   Wed Dec 06 10:47:31 2006 +0000
+++ b/tools/python/xen/xm/shutdown.py   Wed Dec 06 11:02:32 2006 +0000
@@ -19,9 +19,9 @@
 """
 import time
 
-from xen.xend.XendClient import server
 from xen.xend import sxp
-from xen.xm.opts import *
+from opts import *
+from main import server
 
 gopts = Opts(use="""[options] [DOM]
 
diff -r 92127156ec49 -r cf1ca0615414 tools/examples/xm-config.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/examples/xm-config.xml      Wed Dec 06 11:02:32 2006 +0000
@@ -0,0 +1,43 @@
+<!--
+
+Copyright (C) 2006 XenSource Inc.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of version 2.1 of the GNU Lesser General Public
+License as published by the Free Software Foundation.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+-->
+
+<!--
+
+This is a configuration file for xm; it should be placed in
+/etc/xen/xm-config.xml.  If this file is missing, then xm will fall back to
+the normal behaviour that's in Xen 3.0.4 and below.  The settings here are
+most useful for experimenting with the Xen-API preview in Xen 3.0.4.
+
+-->
+
+<xm>
+  <!-- The server element describes how to talk to Xend.  The type may be 
+       Xen-API or LegacyXMLRPC (the default).  The URI is that of the
+       server; you might try http://server:9363/ or
+       httpu:///var/run/xend/xen-api.sock for the Xen-API, or
+       httpu:///var/run/xend/xmlrpc.sock for the legacy server.
+
+       The username and password attributes will be used to log in if Xen-API
+       is being used.
+    -->
+  <server type='Xen-API'
+          uri='http://localhost:9363/'
+          username='me'
+          password='mypassword' />
+</xm>

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Added support for configuration file for xm, and use that to specify, Xen patchbot-unstable <=