Beispiel #1
0
def chkopts(opts):
    from karesansui.lib.utils import generate_phrase, generate_uuid, string_from_uuid, is_uuid
    from karesansui.lib.const import DEFAULT_LANGS

    reg_email = re.compile("^[a-zA-Z0-9\./_-]{1,}@[a-zA-Z0-9\./-]{4,}$")
    if opts.email:
        if reg_email.search(opts.email) is None:
            raise Exception('ERROR: Illigal option value. option=%s value=%s' % ('-m or --email', opts.email))
    else:
        raise Exception('ERROR: %s option is required.' % '-m or --email')

    reg_passwd = re.compile("^.{5,}")
    if opts.password:
        if reg_passwd.search(opts.password) is None:
            raise Exception('ERROR: Illigal option value. option=%s value=%s' % ('-p or --password', opts.password))
    else:
        pass

    if opts.password == "":
        opts.password = generate_phrase(8)

    if opts.uuid:
        if is_uuid(opts.uuid) is False:
            raise Exception('ERROR: Illigal option value. option=%s value=%s' % ('-u or --uuid', opts.uuid))
    else:
        pass

    if opts.uuid == "":
        opts.uuid = string_from_uuid(generate_uuid())

    reg_fqdn = re.compile("^[a-z0-9][a-z0-9\.\-]{2,}$")
    if opts.fqdn:
        if reg_fqdn.search(opts.fqdn) is None:
            raise Exception('ERROR: Illigal option value. option=%s value=%s' % ('-f or --fqdn', opts.fqdn))
    else:
        pass

    if opts.fqdn == "":
        opts.fqdn = socket.gethostname() 

    reg_lang = re.compile("^[a-z]{2}_[A-Z]{2}$")
    if opts.lang:
        if reg_lang.search(opts.lang) is None:
            raise Exception('ERROR: Illigal option value. option=%s value=%s' % ('-l or --lang', opts.lang))
    else:
        pass

    if opts.lang == "":
        try:
            DEFAULT_LANGS[os.environ["LANG"][0:5]]
            opts.lang = os.environ["LANG"][0:5]
        except:
            opts.lang = "en_US"
Beispiel #2
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-d or --dest-name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-d or --dest-name')

    if opts.src_name:
        if reg.search(opts.src_name):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-s or --src-name', opts.src_name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-s or --src-name')

    if opts.pool:
        if reg.search(opts.pool):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-p or --pool', opts.pool))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-p or --pool')

    if opts.graphics_port:
        reg = re.compile("^[0-9]{1,5}$")
        if not reg.match(opts.graphics_port):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-v or --graphics-port', opts.graphics_port))
        if int(opts.graphics_port) < PORT_MIN_NUMBER or PORT_MAX_NUMBER < int(
                opts.graphics_port):
            raise KssCommandOptException(
                'ERROR: Illigal port number. port=%s' % (opts.graphics_port))

    if opts.mac:
        reg = re.compile("^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
        if not reg.match(opts.mac):
            raise KssCommandOptException('ERROR: Illigal MAC address. mac=%s' %
                                         (opts.mac))

    if opts.uuid:
        if not is_uuid(opts.uuid):
            raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' %
                                         (opts.uuid))
Beispiel #3
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-d or --dest-name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-d or --dest-name')

    if opts.src_name:
        if reg.search(opts.src_name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-s or --src-name', opts.src_name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-s or --src-name')

    if opts.pool:
        if reg.search(opts.pool):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-p or --pool', opts.pool))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-p or --pool')

    if opts.vnc_port:
        reg = re.compile("^[0-9]{1,5}$")
        if not reg.match(opts.vnc_port):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-v or --vnc-port', opts.vnc_port))
        if int(opts.vnc_port) < PORT_MIN_NUMBER or PORT_MAX_NUMBER < int(opts.vnc_port):
            raise KssCommandOptException('ERROR: Illigal port number. port=%s' % (opts.vnc_port))

    if opts.mac:
        reg = re.compile("^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
        if not reg.match(opts.mac):
            raise KssCommandOptException('ERROR: Illigal MAC address. mac=%s' % (opts.mac))

    if opts.uuid:
        if not is_uuid(opts.uuid):
            raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' % (opts.uuid))
Beispiel #4
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        kvc = KaresansuiVirtConnection()
        # #1 libvirt process
        try:
            # inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            export = []
            for pool_name in pools:
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]
                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        e_param = ExportConfigParam()
                        e_param.load_xml_config(_afile)

                        if e_param.get_uuid() != opts.uuid:
                            continue

                        e_name = e_param.get_domain()
                        _dir = os.path.dirname(_afile)

                        param = ConfigParam(e_name)

                        path = "%s/%s.xml" % (_dir, e_name)
                        if os.path.isfile(path) is False:
                            raise KssCommandException("Export corrupt data.(file not found) - path=%s" % path)

                        param.load_xml_config(path)

                        if e_name != param.get_domain_name():
                            raise KssCommandException(
                                "Export corrupt data.(The name does not match) - info=%s, xml=%s"
                                % (e_name, param.get_name())
                            )

                        _dir = os.path.dirname(_afile)

                        export.append({"dir": _dir, "pool": pool_name, "uuid": e_param.get_uuid(), "name": e_name})

            if len(export) < 1:
                # refresh pool.
                conn = KaresansuiVirtConnection(readonly=False)
                try:
                    conn.refresh_pools()
                finally:
                    conn.close()
                raise KssCommandException("libvirt data did not exist. - uuid=%s" % opts.uuid)
            else:
                export = export[0]

        finally:
            kvc.close()

        self.up_progress(30)
        # #2 physical process
        if os.path.isdir(export["dir"]) is False:
            raise KssCommandException(
                _("Failed to delete export data. - %s") % (_("Export data directory not found. [%s]") % (export["dir"]))
            )

        uuid = os.path.basename(export["dir"])
        pool_dir = os.path.dirname(export["dir"])

        if not is_uuid(export["uuid"]):
            raise KssCommandException(
                _("Failed to delete export data. - %s")
                % (_("'%s' is not valid export data directory.") % (export["dir"]))
            )

        shutil.rmtree(export["dir"])

        for _afile in glob.glob("%s*img" % (export["dir"])):
            os.remove(_afile)

        self.up_progress(30)
        # refresh pool.
        conn = KaresansuiVirtConnection(readonly=False)
        try:
            try:
                conn.refresh_pools()
            finally:
                conn.close()
        except:
            pass

        self.logger.info("Deleted export data. - uuid=%s" % (opts.uuid))
        print >>sys.stdout, _("Deleted export data. - uuid=%s") % (opts.uuid)
        return True
Beispiel #5
0
def chkopts(opts):
    if opts.uuid:
        if not is_uuid(opts.uuid):
            raise KssCommandOptException("ERROR: Illigal UUID. uuid=%s" % (opts.uuid))
    else:
        raise KssCommandOptException("ERROR: -u or --uuid option is required.")
Beispiel #6
0
def chkconfig(config):
    """<comment-ja>
    Karesansui設定ファイル情報をチェックします。
    @param config: 設定ファイル情報
    @type config: dict
    @rtype: bool
    @return: チェック結果
    </comment-ja>
    <comment-en>
    TODO: English Comment
    </comment-en>
    """
    check = True

    # application.log.config
    if check and config.has_key("application.log.config") is False:
        print >>sys.stderr, 'Configuration information is missing. - application.log.config'
        check = False

    if check and os.path.isfile(config["application.log.config"]) is False:
        print >>sys.stderr, 'There is a mistake in the configuration information. - application.log.config=%s' % config["application.log.config"]
        check = False

    # application.tmp.dir
    if check and config.has_key("application.tmp.dir") is False:
        print >>sys.stderr, 'Configuration information is missing. - application.tmp.dir'
        check = False

    if check and os.path.isdir(config["application.tmp.dir"]) is False:
        print >>sys.stderr, 'There is a mistake in the configuration information. - application.tmp.dir=%s' % config["application.tmp.dir"]
        check = False

    if check and os.access(config["application.tmp.dir"], os.R_OK | os.W_OK) is False:
        print >>sys.stderr, 'Not set the appropriate permissions to that directory. - application.tmp.dir=%s' % config["application.tmp.dir"]
        check = False

    # application.bin.dir
    if check and config.has_key("application.bin.dir") is False:
        print >>sys.stderr, 'Configuration information is missing. - application.bin.dir'
        check = False

    if check and os.path.isdir(config["application.bin.dir"]) is False:
        print >>sys.stderr, 'There is a mistake in the configuration information. - application.bin.dir=%s' % config["application.bin.dir"]
        check = False

    if check and os.access(config["application.bin.dir"], os.R_OK) is False:
        print >>sys.stderr, 'Not set the appropriate permissions to that directory. - application.bin.dir=%s' % config["application.bin.dir"]
        check = False

    # application.generate.dir
    if check and config.has_key("application.generate.dir") is False:
        print >>sys.stderr, 'Configuration information is missing. - application.generate.dir'
        check = False
   
    if check and os.path.isdir(config["application.generate.dir"]) is False:
        print >>sys.stderr, 'There is a mistake in the configuration information. - application.generate.dir=%s' % config["application.generate.dir"]
        check = False

    if check and os.access(config["application.generate.dir"], os.R_OK) is False:
        print >>sys.stderr, 'Not set the appropriate permissions to that directory. - application.generate.dir=%s' % config["application.generate.dir"]
        check = False

    # pysilhouette.conf.path
    if check and config.has_key("pysilhouette.conf.path") is False:
        print >>sys.stderr, 'Configuration information is missing. - pysilhouette.conf.path'
        check = False
        
    if check and os.path.isfile(config["pysilhouette.conf.path"]) is False:
        print >>sys.stderr, 'There is a mistake in the configuration information. - pysilhouette.conf.path=%s' % config["pysilhouette.conf.path"]
        check = False

    if check and os.access(config["pysilhouette.conf.path"], os.R_OK) is False:
        print >>sys.stderr, 'Not set the appropriate permissions to that file. - pysilhouette.conf.path=%s' % config["pysilhouette.conf.path"]
        check = False

    # application.uniqkey
    if check and config.has_key("application.uniqkey") is False:
        print >>sys.stderr, 'Configuration information is missing. - application.uniqkey'
        check = False

    if check and is_uuid(config["application.uniqkey"]) is False:
        print >>sys.stderr, 'UUID format is not set. - application.uniqkey'
        check = False

    # database.pool.status
    if check and config.has_key("database.pool.status") is False:
        print >>sys.stderr, 'Configuration information is missing. - database.pool.status'
        check = False

    if check and (config["database.pool.status"] in ("0","1")) is False:
        print >>sys.stderr, 'The mistake is found in the set value. Please set 0 or 1. - database.pool.status'
        check = False

    if check and config["database.pool.status"] == "1":
        # database.pool.max.overflow
        if check and config.has_key("database.pool.max.overflow") is False:
            print >>sys.stderr, 'Configuration information is missing. - database.pool.max.overflow'
            check = False

        # database.pool.size
        if check and config.has_key("database.pool.size") is False:
            print >>sys.stderr, 'Configuration information is missing. - database.pool.size'
            check = False

        # int
        if check and is_int(config["database.pool.max.overflow"]) is False:
            print >>sys.stderr, 'Please set it by the numerical value. - database.pool.max.overflow'
            check = False

        if check and is_int(config["database.pool.size"]) is False:
            print >>sys.stderr, 'Please set it by the numerical value. - database.pool.size'
            check = False

        if check and int(config["database.pool.size"]) <= 0:
            print >>sys.stderr, 'Please set values that are larger than 0. - database.pool.size'
            check = False

        # Comparison
        if check and int(config["database.pool.max.overflow"]) < int(config["database.pool.size"]):
            print >>sys.stderr, 'Please set "database.pool.max.overflow" to a value that is larger than "database.pool.size".'
            check = False

    return check
Beispiel #7
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-n or --name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-n or --name')

    if opts.type:
        if opts.type.lower() != "xen" and opts.type.lower() != "kvm":
            raise KssCommandOptException(
                'ERROR: %s option is require %s or %s.' %
                ('-t or --type', 'xen', 'kvm'))

    if opts.storage_pool:
        if reg.search(opts.storage_pool):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-P or --storage-pool', opts.storage_pool))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-P or --storage-pool')

    if opts.storage_volume:
        if reg.search(opts.storage_volume):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-V or --storage-volume', opts.storage_volume))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' %
                                     '-V or --storage-volume')

    if opts.bus:
        if reg.search(opts.bus):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-B or --bus', opts.bus))

    reg = re.compile("[^0-9]")
    if opts.mem_size:
        if reg.search(str(opts.mem_size)):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-m or --mem-size', opts.mem_size))

    if opts.graphics_port:
        if reg.search(str(opts.graphics_port)):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-v or --graphics-port', opts.graphics_port))
        elif int(
                opts.graphics_port
        ) < GRAPHICS_PORT_MIN_NUMBER or GRAPHICS_PORT_MAX_NUMBER < int(
                opts.graphics_port):
            raise KssCommandOptException(
                'ERROR: Illigal port number. option=%s value=%s' %
                ('-v or --graphics-port', opts.graphics_port))

    if opts.vcpus:
        if reg.search(str(opts.vcpus)):
            raise KssCommandOptException(
                'ERROR: Illigal option value. option=%s value=%s' %
                ('-c or --vcpus', opts.vcpus))

    if opts.uuid:
        if not is_uuid(opts.uuid):
            raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' %
                                         (opts.uuid))

    if opts.mac:
        reg = re.compile("^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
        if not reg.match(opts.mac):
            raise KssCommandOptException('ERROR: Illigal MAC address. mac=%s' %
                                         (opts.mac))

    #if opts.disk and os.path.isfile(opts.disk) is False:
    #    raise KssCommandOptException('ERROR: %s not found.' % opts.disk)

    if opts.iso is not None:
        if opts.kernel is not None or opts.initrd is not None:
            raise KssCommandOptException(
                'ERROR: %s option cannot be specified with %s options.' % (
                    '--iso',
                    '--kernel and --initrd',
                ))

        if os.path.isfile(opts.iso) is False:
            raise KssCommandOptException(
                'ERROR: The specified ISO image path does not exist. - %s' %
                opts.iso)

        if is_iso9660_filesystem_format(opts.iso) is False:
            raise KssCommandOptException(
                'ERROR: The specified ISO image is not valid ISO 9660 CD-ROM filesystem data. - %s'
                % opts.iso)

    else:
        _r_get_net = re.compile("^(ftp|http)://")

        if opts.kernel:
            if _r_get_net.match(str(opts.kernel)) is None and os.path.isfile(
                    opts.kernel) is False:
                raise KssCommandOptException(
                    'ERROR: The specified kernel image path does not exist. - %s'
                    % opts.kernel)
        else:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-k or --kernel')

        if opts.initrd:
            if _r_get_net.match(str(opts.initrd)) is None and os.path.isfile(
                    opts.initrd) is False:
                raise KssCommandOptException(
                    'ERROR: The specified initrd image path does not exist. - %s'
                    % opts.initrd)
        else:
            raise KssCommandOptException('ERROR: %s option is required.' %
                                         '-i or --initrd')
Beispiel #8
0
def chkopts(opts):
    reg = re.compile("[^a-zA-Z0-9\./_:-]")

    if opts.name:
        if reg.search(opts.name):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')

    if opts.type:
        if opts.type.lower() != "xen" and opts.type.lower() != "kvm":
            raise KssCommandOptException('ERROR: %s option is require %s or %s.' % ('-t or --type', 'xen', 'kvm'))

    if opts.storage_pool:
        if reg.search(opts.storage_pool):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-P or --storage-pool', opts.storage_pool))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-P or --storage-pool')

    if opts.storage_volume:
        if reg.search(opts.storage_volume):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-V or --storage-volume', opts.storage_volume))
    else:
        raise KssCommandOptException('ERROR: %s option is required.' % '-V or --storage-volume')

    if opts.bus:
        if reg.search(opts.bus):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-B or --bus', opts.bus))

    reg = re.compile("[^0-9]")
    if opts.mem_size:
        if reg.search(str(opts.mem_size)):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-m or --mem-size', opts.mem_size))

    if opts.vnc_port:
        if reg.search(str(opts.vnc_port)):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-v or --vnc-port', opts.vnc_port))
        elif int(opts.vnc_port) < VNC_PORT_MIN_NUMBER or VNC_PORT_MAX_NUMBER < int(opts.vnc_port):
            raise KssCommandOptException('ERROR: Illigal port number. option=%s value=%s' % ('-v or --vnc-port', opts.vnc_port))

    if opts.vcpus:
        if reg.search(str(opts.vcpus)):
            raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-c or --vcpus', opts.vcpus))

    if opts.uuid:
        if not is_uuid(opts.uuid):
            raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' % (opts.uuid))

    if opts.mac:
        reg = re.compile("^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$")
        if not reg.match(opts.mac):
            raise KssCommandOptException('ERROR: Illigal MAC address. mac=%s' % (opts.mac))

    #if opts.disk and os.path.isfile(opts.disk) is False:
    #    raise KssCommandOptException('ERROR: %s not found.' % opts.disk)

    if opts.iso is not None:
        if opts.kernel is not None or opts.initrd is not None:
            raise KssCommandOptException('ERROR: %s option cannot be specified with %s options.' % ('--iso', '--kernel and --initrd',))

        if os.path.isfile(opts.iso) is False:
            raise KssCommandOptException('ERROR: The specified ISO image path does not exist. - %s' % opts.iso)

        if is_iso9660_filesystem_format(opts.iso) is False:
            raise KssCommandOptException('ERROR: The specified ISO image is not valid ISO 9660 CD-ROM filesystem data. - %s' % opts.iso)

    else:
        _r_get_net = re.compile("^(ftp|http)://")

        if opts.kernel:
            if _r_get_net.match(str(opts.kernel)) is None and os.path.isfile(opts.kernel) is False:
                raise KssCommandOptException('ERROR: The specified kernel image path does not exist. - %s' % opts.kernel)
        else:
            raise KssCommandOptException('ERROR: %s option is required.' % '-k or --kernel')

        if opts.initrd:
            if _r_get_net.match(str(opts.initrd)) is None and os.path.isfile(opts.initrd) is False:
                raise KssCommandOptException('ERROR: The specified initrd image path does not exist. - %s' % opts.initrd)
        else:
            raise KssCommandOptException('ERROR: %s option is required.' % '-i or --initrd')
Beispiel #9
0
def chkconfig(config):
    """<comment-ja>
    Karesansui設定ファイル情報をチェックします。
    @param config: 設定ファイル情報
    @type config: dict
    @rtype: bool
    @return: チェック結果
    </comment-ja>
    <comment-en>
    TODO: English Comment
    </comment-en>
    """
    check = True

    # application.log.config
    if check and config.has_key("application.log.config") is False:
        print >> sys.stderr, 'Configuration information is missing. - application.log.config'
        check = False

    if check and os.path.isfile(config["application.log.config"]) is False:
        print >> sys.stderr, 'There is a mistake in the configuration information. - application.log.config=%s' % config[
            "application.log.config"]
        check = False

    # application.tmp.dir
    if check and config.has_key("application.tmp.dir") is False:
        print >> sys.stderr, 'Configuration information is missing. - application.tmp.dir'
        check = False

    if check and os.path.isdir(config["application.tmp.dir"]) is False:
        print >> sys.stderr, 'There is a mistake in the configuration information. - application.tmp.dir=%s' % config[
            "application.tmp.dir"]
        check = False

    if check and os.access(config["application.tmp.dir"],
                           os.R_OK | os.W_OK) is False:
        print >> sys.stderr, 'Not set the appropriate permissions to that directory. - application.tmp.dir=%s' % config[
            "application.tmp.dir"]
        check = False

    # application.bin.dir
    if check and config.has_key("application.bin.dir") is False:
        print >> sys.stderr, 'Configuration information is missing. - application.bin.dir'
        check = False

    if check and os.path.isdir(config["application.bin.dir"]) is False:
        print >> sys.stderr, 'There is a mistake in the configuration information. - application.bin.dir=%s' % config[
            "application.bin.dir"]
        check = False

    if check and os.access(config["application.bin.dir"], os.R_OK) is False:
        print >> sys.stderr, 'Not set the appropriate permissions to that directory. - application.bin.dir=%s' % config[
            "application.bin.dir"]
        check = False

    # pysilhouette.conf.path
    if check and config.has_key("pysilhouette.conf.path") is False:
        print >> sys.stderr, 'Configuration information is missing. - pysilhouette.conf.path'
        check = False

    if check and os.path.isfile(config["pysilhouette.conf.path"]) is False:
        print >> sys.stderr, 'There is a mistake in the configuration information. - pysilhouette.conf.path=%s' % config[
            "pysilhouette.conf.path"]
        check = False

    if check and os.access(config["pysilhouette.conf.path"], os.R_OK) is False:
        print >> sys.stderr, 'Not set the appropriate permissions to that file. - pysilhouette.conf.path=%s' % config[
            "pysilhouette.conf.path"]
        check = False

    # application.uniqkey
    if check and config.has_key("application.uniqkey") is False:
        print >> sys.stderr, 'Configuration information is missing. - application.uniqkey'
        check = False

    if check and is_uuid(config["application.uniqkey"]) is False:
        print >> sys.stderr, 'UUID format is not set. - application.uniqkey'
        check = False

    # database.pool.status
    if check and config.has_key("database.pool.status") is False:
        print >> sys.stderr, 'Configuration information is missing. - database.pool.status'
        check = False

    if check and (config["database.pool.status"] in ("0", "1")) is False:
        print >> sys.stderr, 'The mistake is found in the set value. Please set 0 or 1. - database.pool.status'
        check = False

    if check and config["database.pool.status"] == "1":
        # database.pool.max.overflow
        if check and config.has_key("database.pool.max.overflow") is False:
            print >> sys.stderr, 'Configuration information is missing. - database.pool.max.overflow'
            check = False

        # database.pool.size
        if check and config.has_key("database.pool.size") is False:
            print >> sys.stderr, 'Configuration information is missing. - database.pool.size'
            check = False

        # int
        if check and is_int(config["database.pool.max.overflow"]) is False:
            print >> sys.stderr, 'Please set it by the numerical value. - database.pool.max.overflow'
            check = False

        if check and is_int(config["database.pool.size"]) is False:
            print >> sys.stderr, 'Please set it by the numerical value. - database.pool.size'
            check = False

        if check and int(config["database.pool.size"]) <= 0:
            print >> sys.stderr, 'Please set values that are larger than 0. - database.pool.size'
            check = False

        # Comparison
        if check and int(config["database.pool.max.overflow"]) < int(
                config["database.pool.size"]):
            print >> sys.stderr, 'Please set "database.pool.max.overflow" to a value that is larger than "database.pool.size".'
            check = False

    return check
Beispiel #10
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        kvc = KaresansuiVirtConnection()
        # #1 libvirt process
        try:
            #inactive_pool = kvc.list_inactive_storage_pool()
            inactive_pool = []
            active_pool = kvc.list_active_storage_pool()
            pools = inactive_pool + active_pool
            pools.sort()

            export = []
            for pool_name in pools:
                pool = kvc.search_kvn_storage_pools(pool_name)
                path = pool[0].get_info()["target"]["path"]
                if os.path.exists(path):
                    for _afile in glob.glob("%s/*/info.dat" % (path,)):
                        e_param = ExportConfigParam()
                        e_param.load_xml_config(_afile)

                        if e_param.get_uuid() != opts.uuid:
                            continue

                        e_name = e_param.get_domain()
                        _dir = os.path.dirname(_afile)

                        param = ConfigParam(e_name)

                        path = "%s/%s.xml" % (_dir, e_name)
                        if os.path.isfile(path) is False:
                            raise KssCommandException(
                                'Export corrupt data.(file not found) - path=%s' % path)

                        param.load_xml_config(path)

                        if e_name != param.get_domain_name():
                            raise KssCommandException(
                                'Export corrupt data.(The name does not match) - info=%s, xml=%s' \
                                % (e_name, param.get_name()))

                        _dir = os.path.dirname(_afile)

                        export.append({"dir" : _dir,
                                       "pool" : pool_name,
                                       "uuid" : e_param.get_uuid(),
                                       "name" : e_name,
                                       })

            if len(export) < 1:
                # refresh pool.
                conn = KaresansuiVirtConnection(readonly=False)
                try:
                    conn.refresh_pools()
                finally:
                    conn.close()
                raise KssCommandException('libvirt data did not exist. - uuid=%s' % opts.uuid)
            else:
                export = export[0]

        finally:
            kvc.close()

        self.up_progress(30)
        # #2 physical process
        if os.path.isdir(export['dir']) is False:
            raise KssCommandException(_("Failed to delete export data. - %s") % (_("Export data directory not found. [%s]") % (export['dir'])))

        uuid = os.path.basename(export['dir'])
        pool_dir = os.path.dirname(export['dir'])

        if not is_uuid(export['uuid']):
            raise KssCommandException(_("Failed to delete export data. - %s") % (_("'%s' is not valid export data directory.") % (export['dir'])))

        shutil.rmtree(export['dir'])

        for _afile in glob.glob("%s*img" % (export['dir'])):
            os.remove(_afile)

        self.up_progress(30)
        # refresh pool.
        conn = KaresansuiVirtConnection(readonly=False)
        try:
            try:
                conn.refresh_pools()
            finally:
                conn.close()
        except:
            pass

        self.logger.info('Deleted export data. - uuid=%s' % (opts.uuid))
        print >>sys.stdout, _('Deleted export data. - uuid=%s') % (opts.uuid)
        return True
Beispiel #11
0
def chkopts(opts):
    if opts.uuid:
        if not is_uuid(opts.uuid):
            raise KssCommandOptException('ERROR: Illigal UUID. uuid=%s' % (opts.uuid))
    else:
        raise KssCommandOptException('ERROR: -u or --uuid option is required.')