aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xm-test/lib/XmTestLib/xapi.py
blob: de552ef171feb1bd4ce30d95ee5795420b7cd9f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
#============================================================================
# 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
#============================================================================
# Copyright (C) 2006 XenSource Ltd.
# Copyright (C) 2006 IBM Corporation
# Copyright (C) 2009 flonatel GmbH & Co. KG
#============================================================================

import atexit
import os
import sys
from XmTestLib import *
from xen.xm import main as xmmain
from xen.xm import XenAPI
from xen.xm.opts import OptionError
from types import DictType
import xml.dom.minidom

sessions=[]

def connect(*args):
    creds = ("", "")
    uri = "http://localhost:9363"

    try:
        session = XenAPI.Session(uri)
    except:
        raise OptionError("Could not create XenAPI session with Xend." \
                          "URI=%s" % uri)
    try:
        session.login_with_password(*creds)
    except:
        raise OptionError("Could not login to Xend. URI=%s" % uri)
    def logout():
        try:
            for s in sessions:
                s.xenapi.session.logout()
        except:
            pass
    sessions.append(session)
    atexit.register(logout)
    return session