Esempio n. 1
0
    def add_license(self):
        cluster_id = self.get_cluster_id()

        rlt = self.client.add_license(cluster_id, self.license_str)
        if not rlt.success:
            Log(
                1, 'InitStorageWork.add_license [%s][%s]fail,as[%s]' %
                (self.cluster_name, self.ip0, rlt.message))
            return rlt

        cluster_info = rlt.content

        arr = [self.ip0]
        if self.ip1:
            arr.append(self.ip1)

        if self.ip2:
            arr.append(self.ip2)

        cluster_info['ip'] = ','.join(arr)
        cluster_info['cluster_id'] = self.cluster_id
        rlt = StoregeClusterDB.instance().create_cluster(
            self.cluster_name, cluster_info)
        if not rlt.success:
            Log(
                1,
                'InitStorageWork.create_cluster[%s][%s]to etcd fail,as[%s]' %
                (self.cluster_name, self.ip0, rlt.message))
        return rlt
Esempio n. 2
0
    def delete_cluster_info(self):
        StrategyNodeDB.instance().delete_cluster(self.cluster_name)

        rlt = StoregeClusterDB.instance().delete_cluster(self.cluster_name)
        if not rlt.success:
            Log(
                1, 'DeleteStorageWork.delete_node_info [%s][%s]fail,as[%s]' %
                (self.cluster_name, self.ip, rlt.message))

        return rlt
Esempio n. 3
0
 def get_cluster_id(self):
     if self.cluster_id:
         return self.cluster_id
     
     rlt = StoregeClusterDB.instance().get_cluster_info(self.cluster_name)
     if not rlt.success:
         Log(1, 'DeleteStorageNodeWork.get_cluster_id get_cluster_info[%s][%s]fail,as[%s]'%(self.cluster_name, self.ip, rlt.message))
         raise InternalException("get_cluster_info[%s] fail,as[%s]."%(self.cluster_name, rlt.message), rlt.result)
     
     self.cluster_id = rlt.content.get('cluster_id')
     return self.cluster_id
Esempio n. 4
0
    def clusters(self):
        rlt = StoregeClusterDB.instance().read_cluster_list()
        if not rlt.success:
            Log(
                1, 'Storage.cluster_list read_cluster_list fail,as[%s]' %
                (rlt.message))
            return rlt

        arr = []
        for cluster in rlt.content:
            info = self.calc_cluster_info(cluster['name'])
            if info['host_number'] > 0:
                cluster.update(info)
                arr.append(cluster)

        return Result(arr)
Esempio n. 5
0
    def disks(self, cluster_name, host_ip, **args):
        rlt = StoregeClusterDB.instance().get_cluster_info(cluster_name)
        if not rlt.success:
            Log(1,
                'Storage.disks get_cluster_info fail,as[%s]' % (rlt.message))
            if rlt.result == ETCD_KEY_NOT_FOUND_ERR:
                self._init_storage_cluster(cluster_name)
            return rlt

        rlt = StorageNodeDB.instance().read_node_info(cluster_name, host_ip)
        if not rlt.success:
            Log(1, 'Storage.disks read_node_info fail,as[%s]' % (rlt.message))
            if rlt.result == ETCD_KEY_NOT_FOUND_ERR:
                self._add_storage_node(cluster_name, host_ip)
            return rlt

        return self._get_disk_info(cluster_name, rlt.content)
Esempio n. 6
0
    def load_all_client(self):
        """
        # 加载所有集群客户端
        """
        # 获取有主机的集群名
        rlt = StoregeClusterDB.instance().read_cluster_list()
        if not rlt.success:
            Log(
                1, "VespaceMgr load_all_client read_cluster_list fail as[%s]" %
                (rlt.message))
            return

        tmp = {}
        for cluster in rlt.content:
            client = self.load_cluster(cluster)
            if client:
                tmp[cluster['name']] = client

        self.__store = tmp
Esempio n. 7
0
    def check_valid(self):
        """
        # 检查数据
        """
        try:
            if self.client is None:
                self.client = VespaceMgr.instance().get_cluster_client(
                    self.cluster_name)

            if not (self.client and self.client.test()):
                return Result('', INIT_VESPACE_CLIENT_FAILERR,
                              'init vespace client fail.')

            if StoregeClusterDB.instance().get_cluster_num(
                    self.cluster_name) <= 1:
                return Result('', LAST_CLUSTER_CANNOT_DELETE_ERR,
                              'The last cluster can not be delete')

        except InternalException, e:
            Log(1, "DeleteStorageWork.check_valid except[%s]" % (e.value))
            return Result("DeleteStorageWork", e.errid, e.value)
Esempio n. 8
0
    def get_cluster_client(self, cluster_name):
        """
        # 获取单个集群的 apiserver client
        """
        self.reload()
        if cluster_name in self.__store:
            return self.__store[cluster_name]

        rlt = StoregeClusterDB.instance().get_cluster_info(cluster_name)
        if not rlt.success:
            Log(
                1,
                "VespaceMgr.get_cluster_client get_cluster_info fail as[%s]" %
                (rlt.message))
            return None

        client = self.load_cluster(rlt.content)
        if client:
            self.__store[cluster_name] = client
            return client

        return None
Esempio n. 9
0
 def is_service_ready(self):
     if StoregeClusterDB.instance().is_cluster_exist(self.cluster_name):
         return True
     else:
         Log(1, 'The cluster[%s]lost' % (self.cluster_name))
         raise InternalException("cluster deleted.", TASK_CANCEL_ERR)
Esempio n. 10
0
class Storage(object):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        pass

    @ring0
    @ring3
    def set_license(self, license_str, **args):
        username = args.get('passport', {}).get('username', 'unkown')

        rlt = SettingMgr.instance().set_vespace_license(license_str)
        if rlt.success:
            LogMod(3, username, u'用户 [%s] 更新存储模块license 成功.' % (username))
        else:
            LogMod(
                3, username,
                u'用户 [%s] 更新存储模块license 失败,as[%s].' % (username, rlt.message))
        return rlt

    @ring0
    @ring3
    def get_license(self, **args):
        return SettingMgr.instance().get_vespace_license()

    @ring0
    @ring3
    def add_cluster(self, post_data, **args):
        try:
            data = json.loads(post_data.replace("'", "\'"))
        except Exception, e:
            Log(1,
                "Configure.add load data to json fail,input[%s]" % (post_data))
            return Result('', INVALID_JSON_DATA_ERR, str(e), http.BAD_REQUEST)

        if 'name' not in data or not data['name']:
            return Result('', INVALID_PARAM_ERR, 'cluster name is invalid',
                          http.BAD_REQUEST)

        if 'ip' not in data or not data['ip']:
            return Result('', INVALID_PARAM_ERR, 'ip is invalid',
                          http.BAD_REQUEST)

        name = data['name']
        ip = data['ip']
        client = VeSpaceClient(ip, data.get('username', DEFAULT_USER_NAME),
                               data.get('password', DEFAULT_PASSWORD))
        rlt = client.create_cluster(name, ip)
        if not rlt.success:
            Log(
                1, 'Storage.add_cluster [%s][%s]fail,as[%s]' %
                (name, ip, rlt.message))
            return rlt

        cluster_id = rlt.content.get('id')

        rlt = SettingMgr.instance().get_vespace_license()
        if not rlt.success:
            Log(
                1, 'Storage.add_cluster get_vespace_license fail,as[%s]' %
                (rlt.message))
            return rlt

        license_str = rlt.content
        rlt = client.add_license(cluster_id, license_str)
        if not rlt.success:
            Log(
                1, 'Storage.add_cluster add_licence[%s][%s]fail,as[%s]' %
                (name, ip, rlt.message))
            return rlt

        cluster_info = rlt.content
        cluster_info['ip'] = ip
        cluster_info['cluster_id'] = cluster_id
        rlt = StoregeClusterDB.instance().create_cluster(name, cluster_info)
        if not rlt.success:
            Log(
                1, 'Storage.add_cluster[%s][%s]to etcd fail,as[%s]' %
                (name, ip, rlt.message))
        return rlt
Esempio n. 11
0
            Log(1,
                "Configure.add load data to json fail,input[%s]" % (post_data))
            return Result('', INVALID_JSON_DATA_ERR, str(e), http.BAD_REQUEST)

        if 'cluster_name' not in data or not data['cluster_name']:
            return Result('', INVALID_PARAM_ERR, 'cluster name is invalid',
                          http.BAD_REQUEST)

        if 'ip' not in data or not data['ip']:
            return Result('', INVALID_PARAM_ERR, 'ip is invalid',
                          http.BAD_REQUEST)

        cluster_name = data['cluster_name']
        ip = data['ip']

        rlt = StoregeClusterDB.instance().get_cluster_info(cluster_name)
        if not rlt.success:
            Log(
                1, 'Storage.add_node get_cluster_info[%s][%s]fail,as[%s]' %
                (cluster_name, ip, rlt.message))
            return Result('', FAIL, 'The cluster not exist')

        cluster_id = rlt.content.get('cluster_id')
        client = VespaceMgr.instance().get_cluster_client(cluster_name)
        rlt = client.add_host(cluster_id, DEFAULT_STORAGE_DOMAIN, ip,
                              HOST_TYPE_STOREGE)
        if not rlt.success:
            Log(
                1, 'Storage.add_node [%s][%s]fail,as[%s]' %
                (cluster_name, ip, rlt.message))
            return rlt