コード例 #1
0
ファイル: project.py プロジェクト: onetop21/MLAppDeploy
def list():
    data = docker.running_projects()

    columns = [('USERNAME', 'PROJECT', 'IMAGE', 'SERVICES', 'TASKS')]
    for project in data:
        running_tasks = f"{data[project]['tasks']}/{data[project]['replicas']}"
        columns.append((data[project]['username'], data[project]['project'], data[project]['image'], data[project]['services'], f"{running_tasks:>5}"))
    utils.print_table(columns, 'Cannot find running project.', 48)
コード例 #2
0
ファイル: project.py プロジェクト: onetop21/MLAppDeploy
def status(all, no_trunc):
    config = utils.read_config()
    project = utils.get_project(default_project)
    
    task_info = docker.show_status(project['project'], project['services'] or {}, all)
    columns = [('ID', 'SERVICE', 'SLOT', 'NODE', 'DESIRED STATE', 'CURRENT STATE', 'UPTIME', 'PORTS', 'ERROR')]
    columns_data = []
    for id, service, slot, node, desired_state, current_state, uptime, ports, error in task_info:
        columns_data.append((id, service, slot, node, desired_state, current_state, uptime, ports, error))
    columns_data = sorted(columns_data, key=lambda x: f"{x[1]}-{x[2]:08}")
    columns += columns_data

    print(f"USERNAME: [{config['account']['username']}] / PROJECT: [{project['project']['name']}]")
    if no_trunc:
        utils.print_table(columns, 'Project is not running.', -1)
    else:
        utils.print_table(columns, 'Project is not running.')
コード例 #3
0
ファイル: node.py プロジェクト: onetop21/MLAppDeploy
def list():
    nodes = docker.node_list()
    columns = [('ID', 'HOSTNAME', 'ADDRESS', 'ROLE', 'STATE', 'AVAILABILITY',
                'ENGINE', 'LABELS')]
    for node in nodes:
        ID = node.attrs['ID'][:10]
        role = node.attrs['Spec']['Role']
        activate = node.attrs['Spec']['Availability'] == 'active'
        hostname = node.attrs['Description']['Hostname']
        engine = node.attrs['Description']['Engine']['EngineVersion']
        state = node.attrs['Status']['State']
        address = node.attrs['Status']['Addr']
        labels = ', '.join([
            f'{key}={value}'
            for key, value in node.attrs['Spec']['Labels'].items()
        ])
        columns.append((ID, hostname, address, role.title(), state.title(),
                        'Active' if activate else '-', engine, labels))
    utils.print_table(columns, 'No attached node.')
コード例 #4
0
ファイル: image.py プロジェクト: onetop21/MLAppDeploy
def list(all, tail):
    if all:
        project = None
    else:
        project = utils.get_project(default_project)

    images, dummies = docker.image_list(
        project['project'] if project else None)

    data = [('ID', 'REGISTRY', 'BUILD USER', 'PROJECT NAME', 'PROJECT AUTHOR',
             'VERSION', 'CREATED')]
    for id, repository, tag, head, project_name, author, created in images[:
                                                                           tail]:
        registry, builder, _ = repository.split('/')
        data.append((id, registry, builder, project_name, author,
                     f'[{tag}]' if head else f'{tag}', created))
    utils.print_table(data, 'No have built image.')
    if dummies:
        print(
            f'This project has {dummies} cached-images. To secure disk spaces by cleaning cache.'
        )
コード例 #5
0
ファイル: image.py プロジェクト: onetop21/MLAppDeploy
def search(keyword):
    import urllib3, json
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    config = utils.read_config()
    try:
        images = []
        catalog = json.loads(
            requests.get(f"http://{config['docker']['registry']}/v2/_catalog",
                         verify=False).text)
        if 'repositories' in catalog:
            repositories = catalog['repositories']
            for repository in repositories:
                tags = json.loads(
                    requests.get(
                        f'http://{config["docker"]["registry"]}/v2/{repository}/tags/list',
                        verify=False).text)
                images += [
                    f"{config['docker']['registry']}/{tags['name']}:{tag}"
                    for tag in tags['tags']
                ]
            found = [
                item for item in filter(
                    None,
                    [image if keyword in image else None for image in images])
            ]

            columns = [('REPOSITORY', 'TAG')]
            for item in found:
                repo, tag = item.rsplit(':', 1)
                columns.append((repo, tag))
            utils.print_table(columns, 'Cannot find image.', 48)
        else:
            print('No images.', file=sys.stderr)
    except requests.exceptions.ConnectionError as e:
        print(
            f"Cannot connect to docker registry [{config['docker']['registry']}]",
            file=sys.stderr)