示例#1
0
    def cleanupResource(self, resource_name):
        self.resource_name = resource_name
        
        pcs('resource', 'cleanup', self.resource_name)
        
        ret = createReturn(code=200, val='cleanup')
        print(json.dumps(json.loads(ret), indent=4))

        return ret
示例#2
0
 def destroyCluster(self):
     try:
         pcs('cluster', 'destroy', '--all')
         
         ret = createReturn(code=200, val='destroy')
         print(json.dumps(json.loads(ret), indent=4))
     except:
         ret = createReturn(code=400, val='cluster not found.')
         print(json.dumps(json.loads(ret), indent=4))
         
     return ret
示例#3
0
    def statusResource(self, resource_name):
        self.resource_name = resource_name
        
        resource = []
        res={}
        nodes = []
        node_list = []
        current_host = None
        
        try:
            xml = pcs('status', 'xml').stdout.decode()
            soup = BeautifulSoup(xml, 'lxml')
            soup_nodes = soup.find('nodes').select('node')
            soup_resource = soup.select_one(f'#{self.resource_name}')
        except:
            ret = createReturn(code=400, val='cluster is not configured.')
            print(json.dumps(json.loads(ret), indent=4))
            sys.exit(0)
            
        try:
            if soup_resource['nodes_running_on'] == '1':
                current_host = soup.select_one(f'#{self.resource_name}').select_one("node")['name']
        except:
            ret = createReturn(code=400, val='resource not found.')
            print(json.dumps(json.loads(ret), indent=4))
            sys.exit(0)
 
        for soup_node in soup_nodes:
            node = {}
            node['host'] = soup_node['name']
            node['online'] = soup_node['online']
            node['resources_running'] = soup_node['resources_running']
            node['standby'] = soup_node['standby']
            node['standby_onfail'] = soup_node['standby_onfail']
            node['maintenance'] = soup_node['maintenance']
            node['pending'] = soup_node['pending']
            node['unclean'] = soup_node['unclean']
            node['shutdown'] = soup_node['shutdown']
            node['expected_up'] = soup_node['expected_up']
            node['is_dc'] = soup_node['is_dc']
            node['type'] = soup_node['type']
            nodes.append(node)

        for i in range(0, len(nodes)):
            clustered_hosts = nodes[i].get('host')
            node_list.append(clustered_hosts)

        res_active = res['active'] = soup_resource['active']
        res_blocked = res['blocked'] = soup_resource['blocked']
        res_failed = res['failed'] = soup_resource['failed']
        res_role = res['role'] = soup_resource['role']
        res['resource'] = soup_resource['id']
        resource.append(res)

        ret_val = {'clustered_host':node_list, 'nodes':nodes, 'started':current_host, 'role':res_role, 'active': res_active, 'blocked': res_blocked, 'failed': res_failed}
        ret = createReturn(code=200, val=ret_val)
        print(json.dumps(json.loads(ret), indent=4))

        return ret
示例#4
0
    def createResource(self, resource_name, xml_path):
        self.resource_name = resource_name
        self.xml_path = xml_path

        #pcs resource 생성 command
        pcs('resource', 'create', self.resource_name, 'VirtualDomain', 'hypervisor=qemu:///system', 
        f'config={self.xml_path}', 'migration_transport=ssh',
        'meta', 'allow-migrate=true', 'priority=100',
        'op', 'start', 'timeout=120s',
        'op', 'stop', 'timeout=120s',
        'op', 'monitor', 'timeout=30', 'interval=10')
        
        ret_val = {'resource name :':self.resource_name, 'hypervisor':'qemu:///system', 'config':self.xml_path, 'migration_transport':'ssh'}
        ret = createReturn(code=200, val=ret_val)
        print(json.dumps(json.loads(ret), indent=4))

        return ret
示例#5
0
    def moveResource(self, resource_name, target_host):
        self.resource_name = resource_name
        self.target_host = target_host
        current_host = None

        xml = pcs('status', 'xml').stdout.decode()
        soup = BeautifulSoup(xml, 'lxml')
        soup_nodes = soup.find('nodes').select('node')
        soup_resource = soup.select_one(f'#{self.resource_name}')

        # pcs resource가 실행 중인 경우
        if soup_resource['nodes_running_on'] == '1':
            current_host = soup.select_one(
                f'#{self.resource_name}').select_one("node")['name']

        if current_host == self.target_host:
            # print('현재 호스트로 마이그레이션 할 수 없습니다.')
            ret = createReturn(code=500,
                               val='cannot be migrated to the same host.')
            print(json.dumps(json.loads(ret), indent=4))

            sys.exit(0)

        elif current_host == None:
            # print('정지 상태에서는 다른 호스트로 마이그레이션 할 수 없습니다.')
            ret = createReturn(code=501,
                               val='Migration is not possible while stopped.')
            print(json.dumps(json.loads(ret), indent=4))

            sys.exit(0)

        else:
            pcs('resource', 'move', self.resource_name, self.target_host)

            ret_val = {
                'current host': current_host,
                'target host': self.target_host
            }
            ret = createReturn(code=200, val=ret_val)
            print(json.dumps(json.loads(ret), indent=4))

        return ret
示例#6
0
    def configCluster(self, cluster_name, *hostnames):
        self.cluster_name = cluster_name
        self.hostnames = hostnames

        #pcs cluster 구성 command
        pcs('host', 'auth', '-u', 'hacluster', '-p', 'password', *self.hostnames)
        pcs('cluster', 'setup', self.cluster_name, *self.hostnames)
        pcs('cluster', 'start', '--all')
        systemctl('enable', '--now', 'corosync.service')
        systemctl('enable', '--now', 'pacemaker.service')
        pcs('property', 'set', 'stonith-enabled=false')

        ret_val = {'cluster name :':self.cluster_name, 'hosts': self.hostnames}
        ret = createReturn(code=200, val=ret_val)
        print(json.dumps(json.loads(ret), indent=4))

        return ret       
示例#7
0
    def removeResource(self, resource_name):
        self.resource_name = resource_name
        
        try:
            pcs('resource', 'cleanup', self.resource_name)
            pcs('resource', 'disable', self.resource_name)
            pcs('resource', 'remove', self.resource_name)
            pcs('resource', 'refresh')
            
            ret = createReturn(code=200, val='remove')
            print(json.dumps(json.loads(ret), indent=4))
            
        except:
            ret = createReturn(code=400, val='resource not found.')
            print(json.dumps(json.loads(ret), indent=4))

        return ret