Esempio n. 1
0
class XendOptionsFile(XendOptions):
    """Default path to the config file."""
    config_default = auxbin.xen_configdir() + "/xend-config.sxp"
    """Environment variable used to override config_default."""
    config_var = "XEND_CONFIG"

    def set_config(self):
        """If the config file exists, read it. If not, ignore it.

        The config file is a sequence of sxp forms.
        """
        self.config_path = os.getenv(self.config_var, self.config_default)
        if os.path.exists(self.config_path):
            try:
                fin = file(self.config_path, 'rb')
                try:
                    config = sxp.parse(fin)
                finally:
                    fin.close()
                if config is None:
                    config = ['xend-config']
                else:
                    config.insert(0, 'xend-config')
                self.config = config
            except Exception, ex:
                self._logError('Reading config file %s: %s', self.config_path,
                               str(ex))
                raise
        else:
Esempio n. 2
0
 def get_vnc_x509_cert_dir(self):
     name = 'vnc-x509-cert-dir'
     vncdir = self.get_config_string(name, self.xend_vnc_x509_cert_dir)
     if os.path.dirname(vncdir) == "":
         vncdir = auxbin.xen_configdir() + '/' + vncdir
     if not os.path.exists(vncdir):
         raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, vncdir))
     return vncdir
Esempio n. 3
0
 def get_xend_relocation_server_ssl_cert_file(self):
     name = 'xend-relocation-server-ssl-cert-file'
     file = self.get_config_string(name)
     if os.path.dirname(file) == "":
         file = auxbin.xen_configdir() + '/' + file;
     if not os.path.exists(file):
         raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, file))
     return file
Esempio n. 4
0
 def get_xend_tcp_xmlrpc_server_ssl_key_file(self):
     name = 'xend-tcp-xmlrpc-server-ssl-key-file'
     file = self.get_config_string(name)
     if file and os.path.dirname(file) == "":
         file = auxbin.xen_configdir() + '/' + file;
     if file and not os.path.exists(file):
         raise XendError("invalid xend config %s: directory '%s' does not exist" % (name, file))
     return file
Esempio n. 5
0
 def get_xend_tcp_xmlrpc_server_ssl_key_file(self):
     name = 'xend-tcp-xmlrpc-server-ssl-key-file'
     file = self.get_config_string(name)
     if os.path.dirname(file) == "":
         file = auxbin.xen_configdir() + '/' + file
     if not os.path.exists(file):
         raise XendError(
             "invalid xend config %s: directory '%s' does not exist" %
             (name, file))
     return file
Esempio n. 6
0
 def get_xend_relocation_server_ssl_cert_file(self):
     name = 'xend-relocation-server-ssl-cert-file'
     file = self.get_config_string(name)
     if os.path.dirname(file) == "":
         file = auxbin.xen_configdir() + '/' + file
     if not os.path.exists(file):
         raise XendError(
             "invalid xend config %s: directory '%s' does not exist" %
             (name, file))
     return file
Esempio n. 7
0
 def get_vnc_x509_cert_dir(self):
     name = 'vnc-x509-cert-dir'
     vncdir = self.get_config_string(name, self.xend_vnc_x509_cert_dir)
     if os.path.dirname(vncdir) == "":
         vncdir = auxbin.xen_configdir() + '/' + vncdir
     if not os.path.exists(vncdir):
         raise XendError(
             "invalid xend config %s: directory '%s' does not exist" %
             (name, vncdir))
     return vncdir
Esempio n. 8
0
    def testHVMConfigFile(self):
        (fd, fname) = tempfile.mkstemp()
        try:
            os.write(fd,
                     '''
kernel = "hvmloader"
builder='hvm'
memory = 128
name = "ExampleHVMDomain"
vcpus=1
vif = [ 'type=ioemu, bridge=xenbr0' ]
disk = [ 'file:/var/images/min-el3-i386.img,ioemu:hda,w' ]
device_model = 'qemu-dm'
sdl=0
vnc=1
vncviewer=1
ne2000=0
                     ''')
        finally:
            os.close(fd)

        self.t('-f %s display=fakedisplay' % fname,
               { 'kernel'      : 'hvmloader',
                 'builder'     : 'hvm',
                 'memory'      : 128,
                 'name'        : 'ExampleHVMDomain',
                 'vcpus'       : 1,
                 'nics'        : -1,
                 'vif'         : ['type=ioemu, bridge=xenbr0'],
                 'disk'        : [['file:/var/images/min-el3-i386.img',
                                   'ioemu:hda', 'w', None]],
                 'device_model': 'qemu-dm',

                 'extra'       : ('VNC_VIEWER=%s:%d ' %
                                  (xen.xm.create.get_host_addr(),
                                   xen.xm.create.VNC_BASE_PORT +
                                   xen.xm.create.choose_vnc_display())),
                 'vnc'         : 1,
                 'vncunused'   : 1,
                 'vncviewer'   : 1,

                 'xm_file'     : fname,
                 'defconfig'   : fname,
                 'display'     : 'fakedisplay',

                 'boot'        : 'c',
                 'dhcp'        : 'off',
                 'interface'   : 'eth0',
                 'path'        : '.:' + auxbin.xen_configdir(),

                 'xauthority'  : xen.xm.create.get_xauthority(),
               })
Esempio n. 9
0
    def testConfigFile(self):
        (fd, fname) = tempfile.mkstemp()
        try:
            os.write(fd,
                     '''
kernel = "/boot/vmlinuz-xenU-smp"
memory = 768
name = "dom1"
vcpus = 4
disk = ['phy:/dev/virt-blkdev-backend/dom1,sda1,w',
'phy:/dev/virt-blkdev-backend/usr,sda2,r']
root = "/dev/sda1 ro"
extra = " profile=1 GATEWAY=192.0.2.254 NETMASK=255.255.255.0 IPADDR=192.0.2.1 HOSTNAME=dom1"
on_poweroff = 'destroy'
on_reboot   = 'destroy'
on_crash    = 'destroy'
                     ''')
        finally:
            os.close(fd)

        self.t('-f %s display=fakedisplay' % fname,
               { 'kernel'      : '/boot/vmlinuz-xenU-smp',
                 'memory'      : 768,
                 'name'        : 'dom1',
                 'vcpus'       : 4,
                 'nics'        : -1,
                 'root'        : '/dev/sda1 ro',
                 'extra'       : ' profile=1 GATEWAY=192.0.2.254 NETMASK=255.255.255.0 IPADDR=192.0.2.1 HOSTNAME=dom1',
                 'on_poweroff' : 'destroy',
                 'on_reboot'   : 'destroy',
                 'on_crash'    : 'destroy',
                 'disk'        : [['phy:/dev/virt-blkdev-backend/dom1',
                                   'sda1', 'w', None],
                                  ['phy:/dev/virt-blkdev-backend/usr',
                                   'sda2', 'r', None]],

                 'xm_file'     : fname,
                 'defconfig'   : fname,
                 'display'     : 'fakedisplay',

                 'boot'        : 'c',
                 'dhcp'        : 'off',
                 'interface'   : 'eth0',
                 'path'        : '.:' + auxbin.xen_configdir(),
                 'builder'     : 'linux',

                 'vncunused'   : 1,
                 'xauthority'  : xen.xm.create.get_xauthority(),
               })
Esempio n. 10
0
def rm_domain_label(configfile):
    # open the domain config file
    fd = None
    fil = None
    if configfile[0] == '/':
        fil = configfile
        fd = open(fil, "rb")
    else:
        for prefix in [".", auxbin.xen_configdir()]:
            fil = prefix + "/" + configfile
            if os.path.isfile(fil):
                fd = open(fil, "rb")
                break
    if not fd:
        raise OptionError("Configuration file '%s' not found." % configfile)

    # read in the domain config file, removing label
    ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
    ac_exit_re = re.compile(".*'\].*")
    file_contents = ""
    comment = 0
    removed = 0
    for line in fd.readlines():
        if ac_entry_re.match(line):
            comment = 1
        if comment:
            removed = 1
            line = "#" + line
        if comment and ac_exit_re.match(line):
            comment = 0
        file_contents = file_contents + line
    fd.close()

    # send error message if we didn't find anything to remove
    if not removed:
        raise security.XSMError('Domain not labeled')

    # write the data back out to the file
    fd = open(fil, "wb")
    fd.writelines(file_contents)
    fd.close()
Esempio n. 11
0
def rm_domain_label(configfile):
    # open the domain config file
    fd = None
    fil = None
    if configfile[0] == '/':
        fil = configfile
        fd = open(fil, "rb")
    else:
        for prefix in [".", auxbin.xen_configdir() ]:
            fil = prefix + "/" + configfile
            if os.path.isfile(fil):
                fd = open(fil, "rb")
                break
    if not fd:
        raise OptionError("Configuration file '%s' not found." % configfile)
        
    # read in the domain config file, removing label
    ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
    ac_exit_re = re.compile(".*'\].*")
    file_contents = ""
    comment = 0
    removed = 0
    for line in fd.readlines():
        if ac_entry_re.match(line):
            comment = 1
        if comment:
            removed = 1
            line = "#"+line
        if comment and ac_exit_re.match(line):
            comment = 0
        file_contents = file_contents + line
    fd.close()

    # send error message if we didn't find anything to remove
    if not removed:
        raise security.XSMError('Domain not labeled')

    # write the data back out to the file
    fd = open(fil, "wb")
    fd.writelines(file_contents)
    fd.close()
Esempio n. 12
0
 def testCommandLine(self):
     (fd, fname) = tempfile.mkstemp()
     os.close(fd)
     self.t('-f %s kernel=/mykernel display=fakedisplay '
            'macaddr=ab:cd:ef:ed' % fname,
            { 'name'      : os.path.basename(fname),
              'xm_file'   : fname,
              'defconfig' : fname,
              'kernel'    : '/mykernel',
              'display'   : 'fakedisplay',
              'macaddr'   : 'ab:cd:ef:ed',
              'memory'    : 128,
              'vcpus'     : 1,
              'boot'      : 'c',
              'dhcp'      : 'off',
              'interface' : 'eth0',
              'path'      : '.:' + auxbin.xen_configdir(),
              'builder'   : 'linux',
              'nics'      : -1,
              'vncunused' : 1,
              'xauthority': xen.xm.create.get_xauthority(),
              })
Esempio n. 13
0
def get_domain_label(configfile):
    # open the domain config file
    fd = None
    if configfile[0] == '/':
        fd = open(configfile, "rb")
    else:
        for prefix in [".", auxbin.xen_configdir() ]:
            abs_file = prefix + "/" + configfile
            if os.path.isfile(abs_file):
                fd = open(abs_file, "rb")
                break
    if not fd:
        raise OptionError("Configuration file '%s' not found." % configfile)

    # read in the domain config file, finding the label line
    ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
    ac_exit_re = re.compile(".*'\].*")
    acline = ""
    record = 0
    for line in fd.readlines():
        if ac_entry_re.match(line):
            record = 1
        if record:
            acline = acline + line
        if record and ac_exit_re.match(line):
            record = 0
    fd.close()

    # send error message if we didn't find anything
    if acline == "":
        raise security.XSMError("Domain not labeled")

    # print out the label
    (title, data) = acline.split("=", 1)
    data = data.strip()
    data = data.lstrip("[\'")
    data = data.rstrip("\']")
    print "policytype=%s," % xsconstants.ACM_POLICY_ID + data
Esempio n. 14
0
    def testConfigFileAndCommandLine(self):
        (fd, fname) = tempfile.mkstemp()
        try:
            os.write(fd,
                     '''
name       = "testname"
memory     = 256
kernel     = "/mykernel"
maxmem     = 1024
cpu        = 2
cpu_weight = 0.75
                     ''')
        finally:
            os.close(fd)

        self.t('-f %s display=fakedisplay macaddr=ab:cd:ef:ed' %
          fname,
               { 'name'       : 'testname',
                 'xm_file'    : fname,
                 'defconfig'  : fname,
                 'kernel'     : '/mykernel',
                 'display'    : 'fakedisplay',
                 'macaddr'    : 'ab:cd:ef:ed',
                 'memory'     : 256,
                 'maxmem'     : 1024,
                 'cpu'        : 2,
                 'cpu_weight' : 0.75,
                 'vcpus'      : 1,
                 'boot'       : 'c',
                 'dhcp'       : 'off',
                 'interface'  : 'eth0',
                 'path'        : '.:' + auxbin.xen_configdir(),
                 'builder'    : 'linux',
                 'nics'       : -1,

                 'vncunused'   : 1,
                 'xauthority' : xen.xm.create.get_xauthority(),
                 })
Esempio n. 15
0
def main(argv):
    policyref = None
    policy_type = ""
    if len(argv) not in (4, 5):
        raise OptionError('Needs either 2 or 3 arguments')

    label = argv[1]

    if len(argv) == 5:
        policyref = argv[4]
    elif security.on() == xsconstants.XS_POLICY_ACM:
        policyref = security.active_policy
        policy_type = xsconstants.ACM_POLICY_ID
    else:
        raise OptionError("ACM security is not enabled. You must specify "\
                          "the policy on the command line.")

    if argv[2].lower() == "dom":
        configfile = argv[3]
        if configfile[0] != '/':
            for prefix in [os.path.realpath(os.path.curdir), auxbin.xen_configdir()]:
                configfile = prefix + "/" + configfile
                if os.path.isfile(configfile):
                    break
        if not validate_config_file(configfile):
            raise OptionError('Invalid config file')
        else:
            add_domain_label(label, configfile, policyref)
    elif argv[2].lower() == "mgt":
        domain = argv[3]
        if policy_type == "":
            tmp = policyref.split(":")
            if len(tmp) != 2:
                raise OptionError("Policy name in wrong format.")
            policy_type, policyref = tmp
        add_domain_label_xapi(label, domain, policyref, policy_type)
    elif argv[2].lower() == "res":
        resource = argv[3]
        if policy_type == "":
            tmp = policyref.split(":")
            if len(tmp) == 1:
                policy_type = xsconstants.ACM_POLICY_ID
            elif len(tmp) == 2:
                policy_type, policyref = tmp
            else:
                raise OptionError("Policy name in wrong format.")
        add_resource_label(label, resource, policyref, policy_type)
    elif argv[2].lower().startswith("vif-"):
        try:
            idx = int(argv[2][4:])
            if idx < 0:
                raise
        except:
            raise OptionError("Bad VIF device index.")
        vmname = argv[3]
        if policy_type == "":
            tmp = policyref.split(":")
            if len(tmp) != 2:
                raise OptionError("Policy name in wrong format.")
            policy_type, policyref = tmp
        add_vif_label(label, vmname, idx, policyref, policy_type)
    else:
        raise OptionError('Need to specify either "dom", "mgt" or "res" as '
                          'object to add label to.')
Esempio n. 16
0
class XendOptions:
    """Configuration options."""
    """Where network control scripts live."""
    network_script_dir = auxbin.scripts_dir()
    """Where block control scripts live."""
    block_script_dir = auxbin.scripts_dir()
    """Default path to the log file. """
    logfile_default = "/var/log/xen/xend.log"
    """Default level of information to be logged."""
    loglevel_default = 'DEBUG'
    """Default Xen-API server configuration. """
    xen_api_server_default = [['unix']]
    """Default for the flag indicating whether xend should run an http server
    (deprecated)."""
    xend_http_server_default = 'no'

    xend_tcp_xmlrpc_server_default = 'no'

    xend_tcp_xmlrpc_server_address_default = 'localhost'

    xend_tcp_xmlrpc_server_port_default = 8006

    xend_unix_xmlrpc_server_default = 'yes'
    """Default interface address xend listens at. """
    xend_address_default = ''
    """Default for the flag indicating whether xend should run a relocation server."""
    xend_relocation_server_default = 'no'
    """Default for the flag indicating whether xend should run a ssl relocation server."""
    xend_relocation_ssl_server_default = 'no'
    """Default for the flag indicating whether xend should run a udev event server."""
    xend_udev_event_server_default = 'no'
    """Default interface address the xend relocation server listens at. """
    xend_relocation_address_default = ''
    """Default port xend serves HTTP at. """
    xend_port_default = 8000
    """Default port xend serves relocation at. """
    xend_relocation_port_default = 8002
    """Default port xend serves ssl relocation at. """
    xend_relocation_ssl_port_default = 8003

    xend_relocation_hosts_allow_default = ''
    """Default for the flag indicating whether xend should run a unix-domain
    server (deprecated)."""
    xend_unix_server_default = 'no'
    """Default external migration tool """
    external_migration_tool_default = ''
    """Default path the unix-domain server listens at."""
    xend_unix_path_default = '/var/lib/xend/xend-socket'

    dom0_min_mem_default = 0

    dom0_vcpus_default = 0

    vncpasswd_default = None
    """Default interface to listen for VNC connections on"""
    xend_vnc_listen_default = '127.0.0.1'
    """Use of TLS mode in QEMU VNC server"""
    xend_vnc_tls = 0
    """x509 certificate directory for QEMU VNC server"""
    xend_vnc_x509_cert_dir = auxbin.xen_configdir() + "/vnc"
    """Verify incoming client x509 certs"""
    xend_vnc_x509_verify = 0
    """Default session storage path."""
    xend_domains_path_default = '/var/lib/xend/domains'
    """Default xend management state storage."""
    xend_state_path_default = '/var/lib/xend/state'
    """Default xend QCoW storage repository location."""
    xend_storage_path_default = '/var/lib/xend/storage'
    """Default xend security state storage path."""
    xend_security_path_default = '/var/lib/xend/security'
    """Default script to configure a backend network interface"""
    vif_script = osdep.vif_script
    """Default Xen Security Module"""
    xsm_module_default = 'dummy'
    """Default rotation count of qemu-dm log file."""
    qemu_dm_logrotate_count = 10
    """Default timeout for device creation."""
    device_create_timeout_default = 100
    """Default timeout for device destruction."""
    device_destroy_timeout_default = 100

    def __init__(self):
        self.configure()

    def _logError(self, fmt, *args):
        """Logging function to log to stderr. We use this for XendOptions log
        messages because they may be logged before the logger has been
        configured.  Other components can safely use the logger.
        """
        print >> sys.stderr, "xend [ERROR]", fmt % args

    def configure(self):
        self.set_config()
        XendLogging.init(
            self.get_config_string("logfile", self.logfile_default),
            self.get_config_string("loglevel", self.loglevel_default))

    def set_config(self):
        raise NotImplementedError()

    def get_config_bool(self, name, val=None):
        raise NotImplementedError()

    def get_config_int(self, name, val=None):
        raise NotImplementedError()

    def get_config_string(self, name, val=None):
        raise NotImplementedError()

    def get_xen_api_server(self):
        raise NotImplementedError()

    def get_xend_http_server(self):
        """Get the flag indicating whether xend should run an http server.
        """
        return self.get_config_bool("xend-http-server",
                                    self.xend_http_server_default)

    def get_xend_tcp_xmlrpc_server(self):
        return self.get_config_bool("xend-tcp-xmlrpc-server",
                                    self.xend_tcp_xmlrpc_server_default)

    def get_xend_tcp_xmlrpc_server_port(self):
        return self.get_config_int("xend-tcp-xmlrpc-server-port",
                                   self.xend_tcp_xmlrpc_server_port_default)

    def get_xend_tcp_xmlrpc_server_address(self):
        return self.get_config_string(
            "xend-tcp-xmlrpc-server-address",
            self.xend_tcp_xmlrpc_server_address_default)

    def get_xend_tcp_xmlrpc_server_ssl_key_file(self):
        name = 'xend-tcp-xmlrpc-server-ssl-key-file'
        file = self.get_config_string(name)
        if os.path.dirname(file) == "":
            file = auxbin.xen_configdir() + '/' + file
        if not os.path.exists(file):
            raise XendError(
                "invalid xend config %s: directory '%s' does not exist" %
                (name, file))
        return file

    def get_xend_tcp_xmlrpc_server_ssl_cert_file(self):
        name = 'xend-tcp-xmlrpc-server-ssl-cert-file'
        file = self.get_config_string(name)
        if os.path.dirname(file) == "":
            file = auxbin.xen_configdir() + '/' + file
        if not os.path.exists(file):
            raise XendError(
                "invalid xend config %s: directory '%s' does not exist" %
                (name, file))
        return file

    def get_xend_unix_xmlrpc_server(self):
        return self.get_config_bool("xend-unix-xmlrpc-server",
                                    self.xend_unix_xmlrpc_server_default)

    def get_xend_relocation_server(self):
        """Get the flag indicating whether xend should run a relocation server.
        """
        return self.get_config_bool("xend-relocation-server",
                                    self.xend_relocation_server_default)

    def get_xend_relocation_ssl_server(self):
        """Get the flag indicating whether xend should run a ssl relocation server.
        """
        return self.get_config_bool("xend-relocation-ssl-server",
                                    self.xend_relocation_ssl_server_default)

    def get_xend_relocation_server_ssl_key_file(self):
        name = 'xend-relocation-server-ssl-key-file'
        file = self.get_config_string(name)
        if os.path.dirname(file) == "":
            file = auxbin.xen_configdir() + '/' + file
        if not os.path.exists(file):
            raise XendError(
                "invalid xend config %s: directory '%s' does not exist" %
                (name, file))
        return file

    def get_xend_relocation_server_ssl_cert_file(self):
        name = 'xend-relocation-server-ssl-cert-file'
        file = self.get_config_string(name)
        if os.path.dirname(file) == "":
            file = auxbin.xen_configdir() + '/' + file
        if not os.path.exists(file):
            raise XendError(
                "invalid xend config %s: directory '%s' does not exist" %
                (name, file))
        return file

    def get_xend_udev_event_server(self):
        return self.get_config_bool("xend-udev-event-server",
                                    self.xend_udev_event_server_default)

    def get_xend_port(self):
        """Get the port xend listens at for its HTTP interface.
        """
        return self.get_config_int('xend-port', self.xend_port_default)

    def get_xend_relocation_port(self):
        """Get the port xend listens at for connection to its relocation server.
        """
        return self.get_config_int('xend-relocation-port',
                                   self.xend_relocation_port_default)

    def get_xend_relocation_ssl_port(self):
        """Get the port xend listens at for ssl connection to its relocation
        server.
        """
        return self.get_config_int('xend-relocation-ssl-port',
                                   self.xend_relocation_ssl_port_default)

    def get_xend_relocation_ssl(self):
        """Whether to use ssl when relocating.
        """
        return self.get_config_bool('xend-relocation-ssl', 'no')

    def get_xend_relocation_hosts_allow(self):
        return self.get_config_string("xend-relocation-hosts-allow",
                                      self.xend_relocation_hosts_allow_default)

    def get_xend_address(self):
        """Get the address xend listens at for its HTTP port.
        This defaults to the empty string which allows all hosts to connect.
        If this is set to 'localhost' only the localhost will be able to connect
        to the HTTP port.
        """
        return self.get_config_string('xend-address',
                                      self.xend_address_default)

    def get_xend_relocation_address(self):
        """Get the address xend listens at for its relocation server port.
        This defaults to the empty string which allows all hosts to connect.
        If this is set to 'localhost' only the localhost will be able to connect
        to the relocation port.
        """
        return self.get_config_string('xend-relocation-address',
                                      self.xend_relocation_address_default)

    def get_xend_unix_server(self):
        """Get the flag indicating whether xend should run a unix-domain server.
        """
        return self.get_config_bool("xend-unix-server",
                                    self.xend_unix_server_default)

    def get_xend_unix_path(self):
        """Get the path the xend unix-domain server listens at.
        """
        return self.get_config_string("xend-unix-path",
                                      self.xend_unix_path_default)

    def get_xend_domains_path(self):
        """ Get the path for persistent domain configuration storage
        """
        return self.get_config_string("xend-domains-path",
                                      self.xend_domains_path_default)

    def get_xend_state_path(self):
        """ Get the path for persistent domain configuration storage
        """
        return self.get_config_string("xend-state-path",
                                      self.xend_state_path_default)

    def get_xend_storage_path(self):
        """ Get the path for persistent domain configuration storage
        """
        return self.get_config_string("xend-storage-path",
                                      self.xend_storage_path_default)

    def get_xend_security_path(self):
        """ Get the path for security state
        """
        return self.get_config_string("xend-security-path",
                                      self.xend_security_path_default)

    def get_network_script(self):
        """@return the script used to alter the network configuration when
        Xend starts and stops, or None if no such script is specified."""

        s = self.get_config_string('network-script')

        if s:
            result = s.split(" ")
            result[0] = os.path.join(self.network_script_dir, result[0])
            return result
        else:
            return None

    def get_external_migration_tool(self):
        """@return the name of the tool to handle virtual TPM migration."""
        return self.get_config_string('external-migration-tool',
                                      self.external_migration_tool_default)

    def get_enable_dump(self):
        return self.get_config_bool('enable-dump', 'no')

    def get_vif_script(self):
        return self.get_config_string('vif-script', self.vif_script)

    def get_dom0_min_mem(self):
        return self.get_config_int('dom0-min-mem', self.dom0_min_mem_default)

    def get_enable_dom0_ballooning(self):
        enable_dom0_ballooning_default = 'yes'
        if self.get_dom0_min_mem() == 0:
            enable_dom0_ballooning_default = 'no'
        return self.get_config_bool('enable-dom0-ballooning',
                                    enable_dom0_ballooning_default)

    def get_dom0_vcpus(self):
        return self.get_config_int('dom0-cpus', self.dom0_vcpus_default)

    def get_console_limit(self):
        return self.get_config_int('console-limit', 1024)

    def get_vnclisten_address(self):
        return self.get_config_string('vnc-listen',
                                      self.xend_vnc_listen_default)

    def get_vncpasswd_default(self):
        return self.get_config_string('vncpasswd', self.vncpasswd_default)

    def get_keymap(self):
        return self.get_config_string('keymap', None)

    def get_resource_label_change_script(self):
        s = self.get_config_string('resource-label-change-script')
        if s:
            result = s.split(" ")
            result[0] = os.path.join(auxbin.scripts_dir(), result[0])
            return result
        else:
            return None

    def get_vnc_tls(self):
        return self.get_config_string('vnc-tls', self.xend_vnc_tls)

    def get_vnc_x509_cert_dir(self):
        name = 'vnc-x509-cert-dir'
        vncdir = self.get_config_string(name, self.xend_vnc_x509_cert_dir)
        if os.path.dirname(vncdir) == "":
            vncdir = auxbin.xen_configdir() + '/' + vncdir
        if not os.path.exists(vncdir):
            raise XendError(
                "invalid xend config %s: directory '%s' does not exist" %
                (name, vncdir))
        return vncdir

    def get_vnc_x509_verify(self):
        return self.get_config_string('vnc-x509-verify',
                                      self.xend_vnc_x509_verify)

    def get_qemu_dm_logrotate_count(self):
        return self.get_config_int("qemu-dm-logrotate-count",
                                   self.qemu_dm_logrotate_count)

    def get_device_create_timeout(self):
        return self.get_config_int("device-create-timeout",
                                   self.device_create_timeout_default)

    def get_device_destroy_timeout(self):
        return self.get_config_int("device-destroy-timeout",
                                   self.device_destroy_timeout_default)
Esempio n. 17
0
def main(argv):
    policyref = None
    policy_type = ""
    if len(argv) not in (4, 5):
        raise OptionError('Needs either 2 or 3 arguments')

    label = argv[1]

    if len(argv) == 5:
        policyref = argv[4]
    elif security.on() == xsconstants.XS_POLICY_ACM:
        policyref = security.active_policy
        policy_type = xsconstants.ACM_POLICY_ID
    else:
        raise OptionError("ACM security is not enabled. You must specify "\
                          "the policy on the command line.")

    if argv[2].lower() == "dom":
        configfile = argv[3]
        if configfile[0] != '/':
            for prefix in [
                    os.path.realpath(os.path.curdir),
                    auxbin.xen_configdir()
            ]:
                configfile = prefix + "/" + configfile
                if os.path.isfile(configfile):
                    break
        if not validate_config_file(configfile):
            raise OptionError('Invalid config file')
        else:
            add_domain_label(label, configfile, policyref)
    elif argv[2].lower() == "mgt":
        domain = argv[3]
        if policy_type == "":
            tmp = policyref.split(":")
            if len(tmp) != 2:
                raise OptionError("Policy name in wrong format.")
            policy_type, policyref = tmp
        add_domain_label_xapi(label, domain, policyref, policy_type)
    elif argv[2].lower() == "res":
        resource = argv[3]
        if policy_type == "":
            tmp = policyref.split(":")
            if len(tmp) == 1:
                policy_type = xsconstants.ACM_POLICY_ID
            elif len(tmp) == 2:
                policy_type, policyref = tmp
            else:
                raise OptionError("Policy name in wrong format.")
        add_resource_label(label, resource, policyref, policy_type)
    elif argv[2].lower().startswith("vif-"):
        try:
            idx = int(argv[2][4:])
            if idx < 0:
                raise
        except:
            raise OptionError("Bad VIF device index.")
        vmname = argv[3]
        if policy_type == "":
            tmp = policyref.split(":")
            if len(tmp) != 2:
                raise OptionError("Policy name in wrong format.")
            policy_type, policyref = tmp
        add_vif_label(label, vmname, idx, policyref, policy_type)
    else:
        raise OptionError('Need to specify either "dom", "mgt" or "res" as '
                          'object to add label to.')
Esempio n. 18
0
from xen.xend.XendLogging import log
from xen.xend.XendError import XendError, VmError
import sys
import os.path
from xen.xend.sxp import *
from xen.util import auxbin

QUIRK_SYSFS_NODE = "/sys/bus/pci/drivers/pciback/quirks"
QUIRK_CONFIG_FILE = auxbin.xen_configdir() + "/xend-pci-quirks.sxp"
PERMISSIVE_CONFIG_FILE = auxbin.xen_configdir() + "/xend-pci-permissive.sxp"
PERMISSIVE_SYSFS_NODE = "/sys/bus/pci/drivers/pciback/permissive"


class PCIQuirk:
    def __init__(self, dev):
        self.vendor = dev.vendor
        self.device = dev.device
        self.subvendor = dev.subvendor
        self.subdevice = dev.subdevice
        self.domain = dev.domain
        self.bus = dev.bus
        self.slot = dev.slot
        self.func = dev.func

        self.devid = "%04x:%04x:%04x:%04x" % (self.vendor, self.device,
                                              self.subvendor, self.subdevice)
        self.pciid = dev.name
        self.quirks = self.__getQuirksByID()

        self.__sendQuirks()
        self.__sendPermDevs()
Esempio n. 19
0
from xen.xend.XendLogging import log
from xen.xend.XendError import XendError, VmError
import sys
import os.path
from xen.xend.sxp import *
from xen.util import auxbin

QUIRK_SYSFS_NODE = "/sys/bus/pci/drivers/pciback/quirks"
QUIRK_CONFIG_FILE = auxbin.xen_configdir() + "/xend-pci-quirks.sxp"
PERMISSIVE_CONFIG_FILE = auxbin.xen_configdir() + "/xend-pci-permissive.sxp"
PERMISSIVE_SYSFS_NODE = "/sys/bus/pci/drivers/pciback/permissive"

class PCIQuirk:
    def __init__(self, dev):
        self.vendor = dev.vendor
        self.device = dev.device
        self.subvendor = dev.subvendor
        self.subdevice = dev.subdevice
        self.domain = dev.domain
        self.bus = dev.bus
        self.slot = dev.slot
        self.func = dev.func

        self.devid = "%04x:%04x:%04x:%04x" % (self.vendor, self.device,
                                              self.subvendor, self.subdevice)
        self.pciid = dev.name
        self.quirks = self.__getQuirksByID()

        self.__sendQuirks()
        self.__sendPermDevs()