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

Fix vm listing traceback and manpage strings #17

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ build_manpages = "build_manpages.build_manpages"
[tool.build_manpages]
manpages = [
"man/resalloc-ibm-cloud-vm.1:function=vm_arg_parser:pyfile=resalloc_ibm_cloud/argparsers.py",
"man/resalloc-ibm-cloud-list-vms.1:function=vm_list_arg_parser:pyfile=resalloc_ibm_cloud/argparsers.py",
"man/resalloc-ibm-cloud-list-deleting-vms.1:function=default_arg_parser:pyfile=resalloc_ibm_cloud/argparsers.py",
"man/resalloc-ibm-cloud-list-vms.1:function=list_vms_parser:pyfile=resalloc_ibm_cloud/argparsers.py",
"man/resalloc-ibm-cloud-list-deleting-vms.1:function=list_deleting_vms_parser:pyfile=resalloc_ibm_cloud/argparsers.py",
]
24 changes: 18 additions & 6 deletions resalloc_ibm_cloud/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import argparse


def default_arg_parser():
def _pfx(name):
return "resalloc-ibm-cloud-" + name


def _default_arg_parser(prog=None):
"""
The part that every resalloc-ibm-cloud utility needs
"""

parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog=prog)
parser.add_argument(
"--token-file", help="Path to IBM cloud token file", required=True
)
Expand All @@ -26,7 +30,7 @@ def vm_arg_parser():
"""
Parser for the resalloc-ibm-cloud-vm utility.
"""
parser = default_arg_parser()
parser = _default_arg_parser(prog=_pfx("vm"))
parser.add_argument("--log-level", default="info")

subparsers = parser.add_subparsers(dest="subparser")
Expand Down Expand Up @@ -66,10 +70,18 @@ def vm_arg_parser():
return parser


def vm_list_arg_parser():
def _list_arg_parser(prog=None):
"""
Parser for the resalloc-ibm-cloud-list-vms utility.
Parser for listing utilities
"""
parser = default_arg_parser()
parser = _default_arg_parser(prog=prog)
parser.add_argument("--pool")
return parser

def list_deleting_vms_parser():
""" parser for listing vms """
return _list_arg_parser(prog=_pfx("list-deleting-vms"))

def list_vms_parser():
""" parser for listing deleting vms """
return _list_arg_parser(prog=_pfx("list-vms"))
4 changes: 2 additions & 2 deletions resalloc_ibm_cloud/ibm_cloud_list_deleting_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"""

from resalloc_ibm_cloud.helpers import get_service
from resalloc_ibm_cloud.argparsers import default_arg_parser
from resalloc_ibm_cloud.argparsers import list_deleting_vms_parser
from resalloc_ibm_cloud.constants import LIMIT


def main():
"""Entrypoint to the script."""

opts = default_arg_parser().parse_args()
opts = list_deleting_vms_parser().parse_args()
Fixed Show fixed Hide fixed
cmd = f"source {opts.token_file} ; echo $IBMCLOUD_API_KEY"
service = get_service(cmd, opts)

Expand Down
4 changes: 2 additions & 2 deletions resalloc_ibm_cloud/ibm_cloud_list_vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import sys

from resalloc_ibm_cloud.helpers import get_service
from resalloc_ibm_cloud.argparsers import default_arg_parser
from resalloc_ibm_cloud.argparsers import list_vms_parser
from resalloc_ibm_cloud.constants import LIMIT


def main():
"""An entrypoint to the script."""

opts = default_arg_parser().parse_args()
opts = list_vms_parser().parse_args()

pool_id = opts.pool or os.getenv("RESALLOC_POOL_ID")
if not pool_id:
Expand Down