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

Support for unmanaged CPCs #374

Merged
merged 1 commit into from
Mar 29, 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
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Released: not yet

* Added support for Python 3.11.

* Added 'zhmc unmanaged_cpc' command group for dealing with unmanaged CPCs.

**Cleanup:**

* Increased minimum versions of pip, setuptools, wheel to more recent versions.
Expand Down
1 change: 1 addition & 0 deletions zhmccli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ._cmd_session import * # noqa: F401
from ._cmd_console import * # noqa: F401
from ._cmd_cpc import * # noqa: F401
from ._cmd_unmanaged_cpc import * # noqa: F401
from ._cmd_lpar import * # noqa: F401
from ._cmd_partition import * # noqa: F401
from ._cmd_adapter import * # noqa: F401
Expand Down
88 changes: 88 additions & 0 deletions zhmccli/_cmd_unmanaged_cpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2023 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Commands for unmanaged CPCs.
"""

from __future__ import absolute_import

import click

import zhmcclient
from .zhmccli import cli
from ._helper import print_resources, click_exception, COMMAND_OPTIONS_METAVAR


def find_unmanaged_cpc(cmd_ctx, console, cpc_name):
"""
Find an unmanaged CPC by name and return its resource object.
"""
try:
ucpc = console.unmanaged_cpcs.find(name=cpc_name)
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)
return ucpc


@cli.group('unmanaged_cpc', options_metavar=COMMAND_OPTIONS_METAVAR)
def ucpc_group():
"""
Command group for unmanaged CPCs.

In addition to the command-specific options shown in this help text, the
general options (see 'zhmc --help') can also be specified right after the
'zhmc' command name.
"""


@ucpc_group.command('list', options_metavar=COMMAND_OPTIONS_METAVAR)
@click.option('--uri', is_flag=True, required=False,
help='Add the resource URI to the properties shown')
@click.pass_obj
def ucpc_list(cmd_ctx, **options):
"""
List the unmanaged CPCs of the HMC.

In addition to the command-specific options shown in this help text, the
general options (see 'zhmc --help') can also be specified right after the
'zhmc' command name.
"""
cmd_ctx.execute_cmd(lambda: cmd_ucpc_list(cmd_ctx, options))


def cmd_ucpc_list(cmd_ctx, options):
# pylint: disable=missing-function-docstring

client = zhmcclient.Client(cmd_ctx.session)
console = client.consoles.console

try:
ucpcs = console.unmanaged_cpcs.list()
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)

show_list = [
'name',
]
if options['uri']:
show_list.extend([
'object-uri',
])

try:
print_resources(cmd_ctx, ucpcs, cmd_ctx.output_format, show_list,
all=False)
except zhmcclient.Error as exc:
raise click_exception(exc, cmd_ctx.error_format)