コード例 #1
0
class UpdateManager(object):
    def __init__(self):
        self.kuber = KubernetesDriver()
        self.service_db = ServiceDB()
        self.token_driver = TokenDriver()
        self.volume = VolumeDriver()
        self.billing = BillingResource()

    def identify_change_uuid(self, context):
        try:
            uuids = self.service_db.get_uuid_from_admin(context)
            if len(uuids[0]) != 0:
                team_uuid = uuids[0][0]
                project_uuid = uuids[0][1]
            else:
                return False
        except Exception, e:
            log.error(
                'get the team_uuid and project_uuid for admin error, reason is: %s'
                % e)
            return False

        new_dict = {'team_uuid': team_uuid, 'project_uuid': project_uuid}
        context.update(new_dict)

        return context
コード例 #2
0
class CreateManager(object):
    def __init__(self):
        self.service_db = ServiceDB()
        self.krpc_client = KubernetesRpcClient()
        self.token_driver = TokenDriver()
        self.kuber_driver = KubernetesDriver()
        self.volume = VolumeDriver()

    def check_name(self, context):
        try:
            using_name_info = self.service_db.name_if_used_check(context)
            if len(using_name_info) != 0:
                for i in using_name_info:
                    service_name = i[0]
                    if service_name.replace(
                            '_', '-') == context.get('service_name').replace(
                                '_', '-'):
                        return False
                # return False
        except Exception, e:
            log.error(
                'Database select error when check the name..., reason=%s' % e)
            return 'error'

        return True
コード例 #3
0
class BillingResource(object):
    def __init__(self):
        self.billing_url = conf.BILLING_URL
        self.service_db = ServiceDB()
        self.billing_api = conf.billing_api

    def base_element(self, context):
        try:
            header = {'token': context.get('token')}
            ret = self.service_db.rc_for_billing(context)
            log.info('get the rc message for billing is:%s' % ret)

            resource_uuid = ret[0][0]
            service_status = ret[0][1]
            cm_format = ret[0][2]
            pods_num = ret[0][3]
            service_name = context.get('service_name')
            project_uuid = context.get('project_uuid')
            if service_status.lower() == 'stopping':
                pods_num = 0

            return pods_num, header, project_uuid, resource_uuid, cm_format, service_name
        except Exception, e:
            log.error('get the detail parameters error, reason is: %s' % e)
            raise Exception('get the detail parameters error')
コード例 #4
0
class DeleteManager(object):
    def __init__(self):
        self.service_db = ServiceDB()
        self.kuber = KubernetesDriver()
        self.billing = BillingResource()
        self.token_driver = TokenDriver()

    @operation_record(resource_type='app', action='logical_delete')
    def service_delete(self, context, token, source_ip, resource_uuid):
        log.info('the data(in) when delete service....is: %s' % context)

        try:
            context = self.service_db.get_service_name(context)
        except Exception, e:
            log.error('get the service name error, reason=%s' % e)
            return request_result(404)

        try:
            ret_volume = self.kuber.update_volume_status(context)
            if ret_volume is False:
                log.error('update the volume status error')
                return request_result(503)
        except Exception, e:
            log.error('update volume status error, reason is: %s' % e)
            return request_result(503)
コード例 #5
0
 def __init__(self):
     self.recover_url = conf.recover_url
     self.billing_url = conf.BILLING_URL
     self.recover_login = conf.recover_login
     self.user = conf.user
     self.password = base64.decodestring(conf.password)
     self.service_db = ServiceDB()
     self.rpc_client = KubernetesRpc()
     self.operate = DbOperate()
     self.k8s_url = conf.k8s_api
コード例 #6
0
class BillingDriver(object):
    def __init__(self):
        self.billing = conf.billing_api
        self.service_db = ServiceDB()

    def get_cost(self, token, service_uuid):
        cost = 0
        billing_url = self.billing + '/api/v1.0/billing/costs'
        header = {'token': token}

        try:
            db_ret = self.service_db.get_cost_use(service_uuid)
            for i in db_ret:
                pods_num = int(i[0])
                cm = int(i[1][:-1])
                cost_in = pods_num * cm
                cost += cost_in
            cost = str(cost) + 'X'
        except Exception, e:
            log.error('get the service uses for cost error, reason is: %s' % e)
            raise Exception('get the service uses for cost error')

        to_billing = {
            'resource_type': 'app',
            'resource_conf': cost,
            'resource_status': 'on',
            'hours': 1
        }

        try:
            bill_ret = requests.post(billing_url,
                                     headers=header,
                                     data=json.dumps(to_billing),
                                     timeout=5)
            log.info('get the cost message\'s result is: %s, type is: %s' %
                     (bill_ret.text, type(bill_ret)))
            bill_ret = json.loads(bill_ret.text)
            if bill_ret.get('status') != 0:
                raise Exception(
                    'from billing get cost, the result code is not 0')

            cost = bill_ret.get('result').get('resource_cost')
        except Exception, e:
            log.error('get the cost message error, reason is: %s' % e)
            raise Exception('get the cost message error')
コード例 #7
0
 def __init__(self):
     self.service_db = ServiceDB()
     self.krpc_client = KubernetesRpcClient()
     self.token_driver = TokenDriver()
     self.kuber_driver = KubernetesDriver()
     self.volume = VolumeDriver()
コード例 #8
0
 def __init__(self):
     self.billing_url = conf.BILLING_URL
     self.service_db = ServiceDB()
     self.billing_api = conf.billing_api
コード例 #9
0
 def __init__(self):
     self.service_db = ServiceDB()
     self.kuber = KubernetesDriver()
     self.billing = BillingResource()
     self.token_driver = TokenDriver()
コード例 #10
0
 def __init__(self):
     self.billing = conf.billing_api
     self.service_db = ServiceDB()
コード例 #11
0
 def __init__(self):
     self.recover_driver = RecoverDriver()
     self.service_db = ServiceDB()
     self.billing_driver = BillingDriver()
コード例 #12
0
 def __init__(self):
     self.service_db = ServiceDB()
     self.billing_resource = BillingResource()
コード例 #13
0
class CheckManager(object):
    def __init__(self):
        self.service_db = ServiceDB()
        self.billing_resource = BillingResource()

    @staticmethod
    def explain(in_tuple):
        add_list = []

        for c in in_tuple:
            resource_uuid = c[0]
            resource_name = c[1]
            team_uuid = c[3]
            project_uuid = c[4]
            user_uuid = c[5]
            resource_type = 'app'
            if c[2].lower() != 'stopping':
                resource_status = 'on'
                pods_num = c[6]
                cm_format = c[7][:-1]
                resource_conf = str(int(pods_num) * int(cm_format)) + 'x'
            else:
                resource_status = 'off'
                resource_conf = '0x'

            dict_add = {
                'resource_uuid': resource_uuid,
                'resource_name': resource_name,
                'team_uuid': team_uuid,
                'project_uuid': project_uuid,
                'user_uuid': user_uuid,
                'resource_type': resource_type,
                'resource_status': resource_status,
                'resource_conf': resource_conf
            }
            add_list.append(dict_add)

            return add_list

    def check_manager(self):
        # 24小时删除的服务
        try:
            svc_del = self.service_db.delete_in24()
        except Exception, e:
            log.error('get the delete service error, reason is: %s' % e)
            return request_result(404)

        delete_list = []
        for i in svc_del:
            service_uuid = i[0]
            v_svc_info = {"resource_uuid": service_uuid}

            delete_list.append(v_svc_info)

        # 24小时新增与更新的服务
        try:
            svc_create = self.service_db.create_in24()
            svc_update = self.service_db.update_in24()
        except Exception, e:
            log.error(
                'get the update service in 24 hours error, reason is: %s' % e)
            return request_result(404)
コード例 #14
0
 def __init__(self):
     self.metal_work = MetalWork()
     self.k_driver = KubernetesDriver()
     self.service_db = ServiceDB()