Example #1
0
    def _GET(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_int(param[2]) is False:
            return web.badrequest()

        disk_id = int(param[2])

        model = findbyguest1(self.orm, guest_id)

        # virt
        kvc = KaresansuiVirtConnection()

        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.notfound()

            virt = kvc.search_kvg_guests(domname)[0]

            guest = MergeGuest(model, virt)
            self.view.guest = guest
            self.view.disk_info = virt.get_disk_info()[disk_id]
        finally:
            kvc.close()

        return True
Example #2
0
    def _DELETE(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_int(param[2]) is False:
            return web.notfound()       

        nic_id = int(param[2])

        model = findbyguest1(self.orm, guest_id)
        
        # virt
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.conflict(web.ctx.path)
            virt = kvc.search_kvg_guests(domname)[0]
            guest = MergeGuest(model, virt)
            nic_info = virt.get_interface_info()[nic_id]
        finally:
            kvc.close()

        mac = nic_info["mac"]["address"]
        self.logger.debug('spinning off delete_nic_job dom=%s, mac=%s' % (domname, mac))
        if delete_nic_job(self,model,domname,mac) is True:
            return web.accepted()
        else:
            return False
Example #3
0
    def _GET(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_int(param[2]) is False:
            return web.badrequest()

        disk_id = int(param[2])

        model = findbyguest1(self.orm, guest_id)

        # virt
        kvc = KaresansuiVirtConnection()

        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.notfound()

            virt = kvc.search_kvg_guests(domname)[0]

            guest = MergeGuest(model, virt)
            self.view.guest = guest
            self.view.disk_info = virt.get_disk_info()[disk_id]
        finally:
            kvc.close()

        return True
Example #4
0
    def _PUT(self, *param, **params):

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None:
            return web.notfound()

        if is_int(param[2]) is False:
            return web.notfound()
        nic_id = int(param[2])

        if not validates_nicby1(self):
            return web.badrequest(self.view.alert)

        model = findbyguest1(self.orm, guest_id)
        # virt
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname:
                return web.conflict(web.ctx.path)
            virt = kvc.search_kvg_guests(domname)[0]
            guest = MergeGuest(model, virt)
            old_mac = virt.get_interface_info()[nic_id]["mac"]["address"]
            nic_info = virt.get_interface_info()
        finally:
            kvc.close()

        new_mac = self.input.mac_address

        if old_mac != new_mac:
            f_chk = True
            for x in nic_info:
                if x["mac"]["address"] == new_mac:
                    f_chk = False
                    break
            if f_chk is False:
                return web.badrequest(_("Specified MAC address is already defined."))

            self.logger.debug(
                "spinning off change_mac_job dom=%s, from_mac=%s, to_mac=%s" % (domname, old_mac, new_mac)
            )
            if change_mac_job(self, model, domname, old_mac, new_mac) is True:
                return web.accepted(url=web.ctx.path)
            else:
                return False

        else:
            return web.accepted(url=web.ctx.path)
Example #5
0
    def _PUT(self, *param, **params):

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_int(param[2]) is False:
            return web.notfound()       
        nic_id = int(param[2])


        if not validates_nicby1(self):
            return web.badrequest(self.view.alert)

        model = findbyguest1(self.orm, guest_id)
        # virt
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.conflict(web.ctx.path)
            virt = kvc.search_kvg_guests(domname)[0]
            guest = MergeGuest(model, virt)
            old_mac = virt.get_interface_info()[nic_id]['mac']['address']
            nic_info = virt.get_interface_info()
        finally:
            kvc.close()

        new_mac = self.input.mac_address

        if old_mac != new_mac:
            f_chk = True
            for x in nic_info:
                if x['mac']['address'] == new_mac:
                    f_chk = False
                    break
            if f_chk is False:
                return web.badrequest(_('Specified MAC address is already defined.'))

            self.logger.debug('spinning off change_mac_job dom=%s, from_mac=%s, to_mac=%s' % (domname, old_mac, new_mac))
            if change_mac_job(self, model, domname, old_mac, new_mac) is True:
                return web.accepted(url=web.ctx.path)
            else:
                return False

        else:
            return web.accepted(url=web.ctx.path)
Example #6
0
    def chk_hostby1(self, param):
        """<comment-ja>
        param[0] のホストIDの型とデータベースに存在しているかチェックする。

        @param param: rest#param
        @type param: dict
        @return: check ok : int(param[0]) || check ng : None
        @rtype: bool
        </comment-ja>
        <comment-en>
        English Comment
        </comment-en>
        """
        if is_int(param[0]) is True:
            if is_findbyhost1(self.orm, param[0]) == 1:
                return int(param[0])
            else:
                return None
        else:
            return None
Example #7
0
    def chk_hostby1(self, param):
        """<comment-ja>
        param[0] のホストIDの型とデータベースに存在しているかチェックする。

        @param param: rest#param
        @type param: dict
        @return: check ok : int(param[0]) || check ng : None
        @rtype: bool
        </comment-ja>
        <comment-en>
        English Comment
        </comment-en>
        """
        if is_int(param[0]) is True:
            if is_findbyhost1(self.orm, param[0]) == 1:
                return int(param[0])
            else:
                return None
        else:
            return None
Example #8
0
    def chk_guestby1(self, param):
        """<comment-ja>
        param[1] のゲストIDの型とデータベースに存在しているかチェックする。ゲストIDの親ホストIDもチェックする。

        @param param: rest#param
        @type param: dict
        @return: check ok : int(param[0]), int(param[1]) : check ng : None, None
        @rtype: bool
        </comment-ja>
        <comment-en>
        English Comment
        </comment-en>
        """
        if is_int(param[1]) is True:
            if is_findbyguest1(self.orm, param[1]) == 1:
                if not (self.chk_hostby1(param) is None):
                    return int(param[0]), int(param[1])
                else:
                    return None, None
            else:
                return None, None
        else:
            return None, None
Example #9
0
    def chk_guestby1(self, param):
        """<comment-ja>
        param[1] のゲストIDの型とデータベースに存在しているかチェックする。ゲストIDの親ホストIDもチェックする。

        @param param: rest#param
        @type param: dict
        @return: check ok : int(param[0]), int(param[1]) : check ng : None, None
        @rtype: bool
        </comment-ja>
        <comment-en>
        English Comment
        </comment-en>
        """
        if is_int(param[1]) is True:
            if is_findbyguest1(self.orm, param[1]) == 1:
                if not (self.chk_hostby1(param) is None):
                    return int(param[0]), int(param[1])
                else:
                    return None, None
            else:
                return None, None
        else:
            return None, None
Example #10
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
Example #11
0
    def _DELETE(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_int(param[2]) is False:
            return web.badrequest()

        disk_id = int(param[2])

        model = findbyguest1(self.orm, guest_id)
        if not model: return web.notfound()

        # virt
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.conflict(web.ctx.path)

            virt = kvc.search_kvg_guests(domname)[0]
            guest = MergeGuest(model, virt)
            disk_info = virt.get_disk_info()[disk_id]

            if disk_info['source'].has_key('file'):
                pool_type = 'file'
                volume_rpath = disk_info['source']['file']
            elif disk_info['source'].has_key('dev'):
                pool_type = 'iscsi'
                volume_rpath = disk_info['source']['dev']

            disk_type = disk_info['type']
            disk_device = disk_info['device']

            if disk_device != "cdrom":
                pool_name = kvc.get_storage_pool_name_byimage(volume_rpath)
                if not pool_name:
                    return web.badrequest(_("Storage pool not found."))
                else:
                    pool_name = pool_name[0]
                pool_type = kvc.get_storage_pool_type(pool_name)

            order = 0
            volume_job = None
            if pool_type != 'iscsi' and disk_type != "block":
                disk_volumes = kvc.get_storage_volume_bydomain(
                    domname, 'disk', 'key')
                volume = None

                for key in disk_volumes.keys():
                    if volume_rpath == os.path.realpath(disk_volumes[key]):
                        volume = key

                if volume is None:
                    return web.badrequest(
                        _("Storage volume can not be found."))

                volume_job = delete_storage_volume(self,
                                                   key,
                                                   pool_name,
                                                   order,
                                                   use=DISK_USES["DISK"])
                order += 1
        finally:
            kvc.close()

        target = disk_info["target"]["dev"]
        self.logger.debug('spinning off delete_disk_job dom=%s, target=%s' %
                          (domname, target))

        disk_job = delete_disk_job(self, domname, target, order)
        if setexec_delete_disk(self, model, disk_job, volume_job) is True:
            return web.accepted()
        else:
            return False
Example #12
0
    def _DELETE(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_int(param[2]) is False:
            return web.badrequest()

        disk_id = int(param[2])

        model = findbyguest1(self.orm, guest_id)
        if not model: return web.notfound()

        # virt
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.conflict(web.ctx.path)

            virt = kvc.search_kvg_guests(domname)[0]
            guest = MergeGuest(model, virt)
            disk_info = virt.get_disk_info()[disk_id]

            if disk_info['source'].has_key('file'):
                pool_type = 'file'
                volume_rpath = disk_info['source']['file']
            elif disk_info['source'].has_key('dev'):
                pool_type = 'iscsi'
                volume_rpath = disk_info['source']['dev']

            pool_name = kvc.get_storage_pool_name_byimage(volume_rpath)
            if not pool_name:
                return web.badrequest(_("Storage pool not found."))
            else:
                pool_name = pool_name[0]
            pool_type = kvc.get_storage_pool_type(pool_name)

            order = 0
            volume_job = None
            if pool_type != 'iscsi':
                disk_volumes = kvc.get_storage_volume_bydomain(domname, 'disk', 'key')
                volume = None

                for key in disk_volumes.keys():
                    if volume_rpath == os.path.realpath(disk_volumes[key]):
                        volume = key

                if volume is None:
                    return web.badrequest(_("Storage volume can not be found."))

                volume_job = delete_storage_volume(self,
                                                   key,
                                                   pool_name,
                                                   order,
                                                   use=DISK_USES["DISK"]
                                                   )
                order += 1
        finally:
            kvc.close()

        target = disk_info["target"]["dev"]
        self.logger.debug('spinning off delete_disk_job dom=%s, target=%s' % (domname, target))

        disk_job = delete_disk_job(self, domname, target, order)
        if setexec_delete_disk(self, model, disk_job, volume_job) is True:
            return web.accepted()
        else:
            return False
Example #13
0
    def _PUT(self, *param, **params):
        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        if is_param(self.input, 'id') is False \
            or is_int(self.input.id) is False:
            return web.badrequest("Request data is invalid.")

        snapshot_id = str(self.input.id)

        snapshot = s_findbyname_guestby1(self.orm, snapshot_id, guest_id)
        if snapshot is None:
            pass
            # ignore snapshots that is not in database.
            #return web.badrequest("Request data is invalid.")

        model = findbyguest1(self.orm, guest_id)

        kvs = KaresansuiVirtSnapshot(readonly=False)
        snapshot_list = []
        try:
            domname = kvs.kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.notfound()
            self.view.is_creatable = kvs.isSupportedDomain(domname)
            try:
                snapshot_list = kvs.listNames(domname)[domname]
            except:
                pass

        finally:
            kvs.finish()

        if not snapshot_id in snapshot_list:
            self.logger.debug(_("The specified snapshot does not exist in database. - %s") % snapshot_id)
            # ignore snapshots that is not in database.
            #return web.notfound()

        action_cmd = dict2command(
            "%s/%s" % (karesansui.config['application.bin.dir'],
                       VIRT_COMMAND_APPLY_SNAPSHOT),
            {"name" : domname, "id" : snapshot_id})

        cmdname = 'Apply Snapshot'

        _jobgroup = JobGroup(cmdname, karesansui.sheconf['env.uniqkey'])
        _job = Job('%s command' % cmdname, 0, action_cmd)
        _jobgroup.jobs.append(_job)

        _machine2jobgroup = m2j_new(machine=model,
                                    jobgroup_id=-1,
                                    uniq_key=karesansui.sheconf['env.uniqkey'],
                                    created_user=self.me,
                                    modified_user=self.me,
                                    )
        
        save_job_collaboration(self.orm,
                               self.pysilhouette.orm,
                               _machine2jobgroup,
                               _jobgroup,
                               )        

        self.view.currentsnapshot = snapshot

        return web.accepted(url=web.ctx.path)
Example #14
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