Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glance task-list cmd programming (개발 완료) #18

Closed
RyanKor opened this issue Oct 4, 2021 · 4 comments
Closed

glance task-list cmd programming (개발 완료) #18

RyanKor opened this issue Oct 4, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@RyanKor
Copy link
Owner

RyanKor commented Oct 4, 2021

Openstack-client에서 glance task-list가 명령어로 구현이 안되어 있음에 따라 커맨드라인을 개발하기 시작

작업 필요 사항

  1. cmd 명칭 규정 (openstack task list라고 규정)
  2. setup.cfg에 명령어 등록
  3. 테스트 코드 구현

위의 3가지 사항으로 개발 작업 착수 중

cmd 개발 규칙은 아래의 glance task-list 옵션에 따라 개발을 진행 중

image

현재 작업중인 사항 -> cmd 필터링 옵션

# python-openstackclient/openstackclient/image/v2/image.py

class TaskImage(command.Lister):
    _description = _("List available task images")

    def get_parser(self, prog_name):
        parser = super(TaskImage, self).get_parser(prog_name)

        parser.add_argument(
            '--sort',
            metavar="<key>[:<direction>]",
            default='name:asc',
            help=_("Sort output by selected keys and directions(asc or desc) "
                   "(default: name:asc), multiple keys and directions can be "
                   "specified separated by comma"),
        )

        parser.add_argument(
            "--page-size",
            metavar="<size>",
            help=argparse.SUPPRESS,
        )

        parser.add_argument(
            '--type',
            metavar='<type>',
            choices=[
                'evacuation', 'live-migration', 'cold-migration', 'resize', # image 값에 맞게 변경 필요
            ],
            help=_('Filter tasks by type'),
        )

        parser.add_argument(
            '--status',
            metavar='<status>',
            default=None,
            help=_("Filter tasks based on status.")
        )

참고 문서

@RyanKor RyanKor added the enhancement New feature or request label Oct 4, 2021
@RyanKor RyanKor self-assigned this Oct 4, 2021
@RyanKor RyanKor changed the title glance task-listcmd programming glance task-list cmd programming Oct 4, 2021
@RyanKor
Copy link
Owner Author

RyanKor commented Oct 5, 2021

추가 작업 사항

  1. setup.cfg 파일에 작업하고 있는 openstack image task list 커맨드를 등록
    image

  2. python-openstackclient 폴더에 터미널로 이동후 python setup.py develop을 사용해서 커맨드 등록

  3. task list 옵션 커맨드 중 --type에 해당하는 3개 요소 추가

  parser.add_argument(
      '--type',
      metavar='<type>',
      choices=[
          'import', 'export', 'clone', # task type 값에 맞게 변경 완료
      ],
      help=_('Filter tasks by type'),
  )

결과

  • 커맨드 정상적으로 등록 및 사용 가능 체크

  • 커맨드 작업 과정에서 에러 발생 : 'NoneType' object has no attribute 'parse_args'

    • 오픈스택 모듈 중 cliff에서 parse_args 가 결과 값을 받아오지 못하고 있음
    • 조정 필요

@RyanKor
Copy link
Owner Author

RyanKor commented Oct 10, 2021

크으으,,,, 기어이 커맨드를 구현했다...!

내가 해냈다고!!!

이제 테스트 코드만 구현해서 tox에 인증 작업만 진행하자.. 할 수 있다!

class TaskImage(command.Lister):
    _description = _("Retrieve a listing of Task objects.")

    def get_parser(self, prog_name):
        parser = super(TaskImage, self).get_parser(prog_name)

        parser.add_argument(
            '--sort-key',
            metavar="<key>[:<field>]",
            help=_("Sorts the response by one of the following attributes: "
                   "created_at, expires_at, id, status, type, updated_at. "
                   "Default is created_at. "
                   "multiple keys and directions can be "
                   "specified separated by comma"),
        )

        parser.add_argument(
            '--sort-dir',
            metavar="<key>[:<direction>]",
            help=_("Sort output by selected keys and directions(asc or desc) "
                   "(default: name:desc), multiple keys and directions can be "
                   "specified separated by comma"),
        )

        parser.add_argument(
            "--page-size",
            metavar="<size>",
            help=argparse.SUPPRESS,
        )

        parser.add_argument(
            '--type',
            metavar='<type>',
            choices=[
                'import'
            ],
            help=_("Filters the response by a task type. "
                   "A valid value is import. "
                   ),
        )

        parser.add_argument(
            '--status',
            metavar='<status>',
            choices=[
                "pending", "processing", "success", "failure"
            ],
            default=None,
            help=_("Filter tasks based on status.")
        )

        return parser

    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image

        columns = (
            "id",
            "type",
            "status",
            "owner_id"
        )
        column_headers = (
            "ID",
            "Type",
            "Status",
            "Owner"
        )

        kwargs = {}
        copy_attrs = ("sort_key", "sort_dir", "page_size", "type", "status")
        for attr in copy_attrs:
            if attr in parsed_args:
                val = getattr(parsed_args, attr, None)
                if val is not None:
                    # Only include a value in kwargs for attributes that are
                    # actually present on the command line
                    kwargs[attr] = val

        data = image_client.tasks(**kwargs)

        return (
            column_headers,
            (utils.get_item_properties(
                s,
                columns,
                formatters=_formatters,
            ) for s in data)
        )

@RyanKor
Copy link
Owner Author

RyanKor commented Oct 15, 2021

image

https://review.opendev.org/c/openstack/python-openstackclient/+/813554

테스트 케이스 및 인증 내역이 포함된 openstack image task list 커맨드 완성!

@RyanKor RyanKor closed this as completed Oct 15, 2021
@RyanKor
Copy link
Owner Author

RyanKor commented Oct 17, 2021

멘토님 요청에 따라 SDK 레포에 변경사항을 커밋하지 않은 것을 추가로 커밋 작업을 진행했고, 앞전에 커밋한 기능 구현 PR에 Depends-On으로 링크를 걸어두었다.

image

해당 커밋을 통해 openstack image task list --page-size 옵션을 진행하기 위해 sdk에 쿼리를 매핑해놓았으며, 해당 커밋이 없으면 커맨드 옵션으로 --page-size를 적용할 수 없다.

https://review.opendev.org/c/openstack/openstacksdk/+/814270

@RyanKor RyanKor changed the title glance task-list cmd programming glance task-list cmd programming (개발 완료) Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant