Example #1
0
    def installDependences(self):
        for TmpRawStr in self.AppInfo['dependences']:
            TmpList = TmpRawStr.split('/')
            print (TmpList)
            TmpModuleName, TmpClsName = (TmpList[0], TmpList[1])
            TmpModule = importlib.import_module(TmpModuleName)
            TmpInstance = getattr(TmpModule, TmpClsName)(**self.kwargs)
            TmpResponse = TmpInstance.start()

            if TmpResponse['ret_code'] != 0:
                print ('%s faild to install dependency %s '%(self.AppInfo['AppName'], TmpClsName))
                return TmpResponse

            print ('%s  install dependency %s  successfully' % (self.AppInfo['AppName'], TmpClsName))
            TmpInfo = TmpInstance.getValues()

            if TmpClsName == 'MariaDBTool':
                self.DependencyDict['MariaDBPassword'] = TmpInfo['MariaDBPassword']
            elif TmpClsName == 'RedisHATool':
                self.AppInfo['TRSRedisPassword'] = crypto_tools.DecodeBase64(TmpInfo['RedisPassword'])
            elif TmpClsName == 'RabbitmqHATool':
                self.AppInfo['TRSMQPassword'] = crypto_tools.DecodeBase64(TmpInfo['RabbitmqPassword'])

        return {
            'ret_code': 0,
            'result': 'all dependencies installed'
        }
Example #2
0
    def createVhosts(self):
        TmpRabbitmqPods = self.k8sObj.filterNamespacedPod(
            namespace=self.AppInfo['Namespace'],
            filters={
                'app': 'rabbitmq-ha',
                'release': 'rabbitmq-ha',
            })['result']

        TmpPod = None
        for _ in range(1):
            for pod in TmpRabbitmqPods:
                print('Config target Rabbitmq POD: ' +
                      str(pod.to_dict()['metadata']['name']))
                TmpPod = pod.to_dict()
                break

        TmpAdminPassword = crypto_tools.DecodeBase64(
            self.AppInfo['RabbitmqPassword'])
        self.k8sObj.execNamespacedPod(namespace=self.AppInfo['Namespace'],
                                      name=TmpPod['metadata']['name'],
                                      cmd='rabbitmqctl add_user admin %s' %
                                      (TmpAdminPassword, ))

        self.k8sObj.execNamespacedPod(
            namespace=self.AppInfo['Namespace'],
            name=TmpPod['metadata']['name'],
            cmd='rabbitmqctl set_user_tags admin administrator')

        print('rabbitmqctl add_user admin %s' % (TmpAdminPassword, ))
        print('rabbitmqctl set_user_tags admin administrator')

        for vhost in self.AppInfo['VHosts']:
            print('creating Rabbitmq Vhost: ' + str(vhost))
            self.k8sObj.execNamespacedPod(namespace=self.AppInfo['Namespace'],
                                          name=TmpPod['metadata']['name'],
                                          cmd='rabbitmqctl add_vhost %s' %
                                          (vhost.strip(), ))
            print(
                'rabbitmqctl set_permissions -p "%s" "admin" ".*" ".*" ".*"' %
                (vhost.strip(), ))
            tmp = self.k8sObj.execNamespacedPod(
                namespace=self.AppInfo['Namespace'],
                name=TmpPod['metadata']['name'],
                cmd="rabbitmqctl set_permissions -p %s admin  .*  .*  .*" %
                (vhost.strip(), ))
            print(tmp['result'])

        return {'ret_code': 0, 'result': 'successfully create rabbitmq Vhost'}