Beispiel #1
0
    def remove_lvm(self, lvm_name, mount=False):
        ""

        # 1 ²éѯÐÅÏ¢
        infos = self.info_lvm(lvm_name)
        if infos is None:
            raise CustomException("lvm  is not exist.")

        vg_name = infos['vg_name']
        lvm_dir = infos['lvm_dir']
        mount_dir = infos['mount_dir']

        # 2 жÔعÒÔØ
        if mount:
            self.umount_dir(lvm_name)

        # 3 ɾ³ýlvm
        lvm = LvmDriver(vg_name)
        lvm.remove_volume(lvm_dir)

        # 4 ɾ³ýÊý¾Ý¿â
        delete_sql = 'DELETE FROM lvm WHERE lvmName = ? '
        data = [(lvm_name, )]
        storage_conf = self.conf.get_storage_conf()
        storage_db = storage_conf['db_path']
        sql_tools = SqliteTools(storage_db)
        sql_tools.delete(delete_sql, data)
Beispiel #2
0
    def proxy_del(self, **kwargs):
        ""

        # 必选
        vm_name = kwargs.pop('vm_name', None)
        port = kwargs.pop('port', None)
        # 可选
        ip = kwargs.pop('ip', None)
        proxy_ip = kwargs.pop('proxy_ip', None)
        proxy_port = kwargs.pop('proxy_port', None)

        proxy_type = kwargs.pop('proxy_type', None)

        # 1 检测
        self.check(vm_name)

        # 2 查询ip
        if ip == None:
            info = self.info_vm(vm_name)
            ip = info['ip']

        # 3 删除代理
        self.net.portProxyRemove(ip, port, proxyType=proxy_type)

        # 4 删除数据库
        delete_sql = 'DELETE FROM %s WHERE ip = ? and port = ? ' % VMPROXY
        data = [(ip, port)]

        virtual_conf = self.conf.get_virtual_conf()
        virtual_db = virtual_conf['db_path']
        sql_tools = SqliteTools(virtual_db)
        sql_tools.delete(delete_sql, data)
Beispiel #3
0
    def portProxyRemove(self,
                        ip,
                        port,
                        proxyIp=None,
                        proxyPort=None,
                        proxyType=None):
        agent_ip = self.network_conf['agent_ip']
        if proxyIp in [None, '']:
            proxyIp = agent_ip

        sql = "select dip,dPort,tIp,tPort,id from %s where " % TABLE_PROXYPORT
        cond_conf = ''
        cond_conf += "tIp=? and tPort=? and dip=?"
        data = (ip, port, proxyIp)

        if proxyPort not in [None]:
            cond_conf += " and dPort=?"
            data += (proxyPort, )
        sql += cond_conf

        #执行查询
        sql_tools = SqliteTools(self.db_name)
        item = sql_tools.fetchall(sql, data)
        if len(item) != 1:
            raise CustomNotFoundException(
                "Not found the proxy port (ip=%s,port=%s,proxyIp=%s,proxyPort=%s) find result num=%d"
                % (ip, port, proxyIp, proxyPort, len(item)))
        dip, dPort, tIp, tPort, id = item[0]

        #将端口代理从iptables中删除
        iptablesTool = IptablesTools()
        iptablesTool.del_nat(tIp, tPort, dip, dPort, proxyType)

        sql = "delete from %s where id=?" % TABLE_PROXYPORT
        data = [(id, )]
        sql_tools.delete(sql, data)
        return True
Beispiel #4
0
    def app_deploy(self, env):
        ""

        # 参数获取
        serviceId = env.get_service_env('serviceId')

        instanceId = env.get_service_env('instanceId')

        appName = env.get_app_env('appName')
        if appName is None:
            appName = ""

        param = env.get_app_env('param')

        listenPort = env.get_router_env('listenPort')
        if listenPort is None:
            listenPort = 0

        domain = env.get_router_env('domain')
        if domain is None:
            domain = ""

        name = serviceId
        # 1 判断服务实例是否已经安装
        app_info = self.app_info(instanceId)
        if len(app_info) == 1:
            raise CustomException("the service [%s]  already exists" %
                                  instanceId)
            return

        # 2 判断服务是否存在
        if not self.script.hasService(name):
            raise CustomException("Could not find the service %s" % str(name))
            return

        # 3 得到改服务对象
        service = self.script.getService(name)

        # 4 得到部署的列表
        actions = service.target.actions['deploy']

        # 5 保存数据库
        appType = service.serviceType
        vmName = env.get_vm_env('name')
        status = 'creating'

        app_conf = self.conf.get_app_conf()
        app_db = app_conf['db_path']
        sql_tools = SqliteTools(app_db)

        save_sql = '''INSERT INTO %s values (?, ?, ?,?, ?,?,?,?,?,?,?)''' % APPTABLE
        data = [(instanceId, appName, appType, serviceId, vmName,
                 domain, listenPort, param, status,
                 time.strftime("%Y-%m-%d %H:%M:%S"), "")]
        sql_tools.save(save_sql, data)

        # 6 循环部署响应列表,逐个操作

        # 变量赋值
        self.executer.env = env
        self.executer.properties = service.propertys.parameter

        # 处理
        for action in actions:
            try:
                getattr(self.executer, action['action'])(action['param'])
            except Exception, e:
                # 删除数据库
                delete_sql = 'DELETE FROM %s WHERE instanceId = ? ' % APPTABLE
                data = [(instanceId, )]
                sql_tools.delete(delete_sql, data)
                # 删除VM
                self.vm.delete_vm(vmName)
                # 异常
                raise CustomException("Error executing method %s !,%s" %
                                      (action['action'], str(e)))
                return
Beispiel #5
0
        for action in actions:
            try:
                getattr(self.executer, action['action'])(action['param'])
            except Exception, e:
                raise CustomException("Error executing method %s !,%s" %
                                      (action['action'], str(e)))
                return

        # 7 删除数据库
        app_conf = self.conf.get_app_conf()
        app_db = app_conf['db_path']
        sql_tools = SqliteTools(app_db)

        delete_sql = 'DELETE FROM %s WHERE instanceId = ? ' % APPTABLE
        data = [(instanceId, )]
        sql_tools.delete(delete_sql, data)

    # 服务负载
    def app_balance(self):
        ""

        pass

    # 服务配置
    def app_conf(self):
        ""

        pass

    # 创建服务表
    def create_app_table(self):