How to use the zhmcclient.Client function in zhmcclient

To help you get started, we’ve selected a few zhmcclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_unmanaged_cpc.py View on Github external
def setup_method(self):
        """
        Set up a faked session, and add a faked Console without any
        child resources.
        """

        self.session = FakedSession('fake-host', 'fake-hmc', '2.13.1', '1.8')
        self.client = Client(self.session)

        self.faked_console = self.session.hmc.consoles.add({
            'object-id': None,
            # object-uri will be automatically set
            'parent': None,
            'class': 'console',
            'name': 'fake-console1',
            'description': 'Console #1',
        })
        self.console = self.client.consoles.find(name=self.faked_console.name)
github zhmcclient / python-zhmcclient / zhmccli / _cmd_partition.py View on Github external
def cmd_partition_mount_iso(cmd_ctx, cpc_name, partition_name, options):

    client = zhmcclient.Client(cmd_ctx.session)
    partition = find_partition(cmd_ctx, client, cpc_name, partition_name)

    image_file = options['imagefile']
    image_fp = open(image_file, 'rb')
    path, image_name = os.path.split(image_file)
    partition.mount_iso_image(image_fp, image_name, options['imageinsfile'])
    if options['boot']:
        partition.update_properties({'boot-device': 'iso-image'})
    cmd_ctx.spinner.stop()
    click.echo('ISO image %s has been mounted to Partition %s.' %
               (image_name, partition.name))
github zhmcclient / python-zhmcclient / examples / partition_lifecycle.py View on Github external
partname = partition_lifecycle["partname"]

cred = hmccreds.get(hmc, None)
if cred is None:
    print("Credentials for HMC %s not found in credentials file %s" % \
          (hmc, hmccreds_file))
    sys.exit(1)

userid = cred["userid"]
password = cred["password"]

print(__doc__)

print("Using HMC %s with userid %s ..." % (hmc, userid))
session = zhmcclient.Session(hmc, userid, password)
cl = zhmcclient.Client(session)

timestats = partition_lifecycle.get("timestats", False)
if timestats:
    session.time_stats_keeper.enable()

print("Listing CPCs ...")
cpcs = cl.cpcs.list()
for cpc in cpcs:
    print(cpc)

print("Finding CPC by name=%s ..." % cpcname)
try:
    cpc = cl.cpcs.find(name=cpcname)
except zhmcclient.NotFound:
    print("Could not find CPC %s on HMC %s" % (cpcname, hmc))
    sys.exit(1)
github zhmcclient / python-zhmcclient / examples / activation_profiles.py View on Github external
lparname = activation_profiles["lparname"]

cred = hmccreds.get(hmc, None)
if cred is None:
    print("Credentials for HMC %s not found in credentials file %s" % \
          (hmc, hmccreds_file))
    sys.exit(1)

userid = cred["userid"]
password = cred["password"]

print(__doc__)

print("Using HMC %s with userid %s ..." % (hmc, userid))
session = zhmcclient.Session(hmc, userid, password)
cl = zhmcclient.Client(session)

timestats = activation_profiles.get("timestats", False)
if timestats:
    session.time_stats_keeper.enable()

print("Listing CPCs ...")
cpcs = cl.cpcs.list()
for cpc in cpcs:
    print(cpc.name, cpc.get_property('status'), cpc.uri)

print("Finding CPC by name=%s ..." % cpcname)
try:
    cpc = cl.cpcs.find(name=cpcname)
except zhmcclient.NotFound:
    print("Could not find CPC %s on HMC %s" % (cpcname, hmc))
    sys.exit(1)
github zhmcclient / python-zhmcclient / zhmccli / _cmd_metrics.py View on Github external
def cmd_metrics_crypto(cmd_ctx, cpc_name, options):

    try:
        client = zhmcclient.Client(cmd_ctx.session)

        metric_group = 'crypto-usage'
        resource_filter = [
            ('cpc', cpc_name),
        ]
        print_metric_groups(cmd_ctx, client, metric_group, resource_filter)

    except zhmcclient.Error as exc:
        raise_click_exception(exc, cmd_ctx.error_format)
github zhmcclient / python-zhmcclient / zhmccli / _cmd_metrics.py View on Github external
def cmd_metrics_roce(cmd_ctx, cpc_name, options):

    try:
        client = zhmcclient.Client(cmd_ctx.session)

        metric_group = 'roce-usage'
        resource_filter = [
            ('cpc', cpc_name),
        ]
        print_metric_groups(cmd_ctx, client, metric_group, resource_filter)

    except zhmcclient.Error as exc:
        raise_click_exception(exc, cmd_ctx.error_format)
github zhmcclient / python-zhmcclient / zhmccli / _cmd_metrics.py View on Github external
def cmd_metrics_flash(cmd_ctx, cpc_name, options):

    try:
        client = zhmcclient.Client(cmd_ctx.session)

        metric_group = 'flash-memory-usage'
        resource_filter = [
            ('cpc', cpc_name),
        ]
        print_metric_groups(cmd_ctx, client, metric_group, resource_filter)

    except zhmcclient.Error as exc:
        raise_click_exception(exc, cmd_ctx.error_format)
github zhmcclient / python-zhmcclient / zhmccli / _cmd_partition.py View on Github external
def cmd_partition_create(cmd_ctx, cpc_name, options):

    client = zhmcclient.Client(cmd_ctx.session)
    cpc = find_cpc(cmd_ctx, client, cpc_name)

    name_map = {
        # The following options are handled in this function:
        'boot-ftp-host': None,
        'boot-ftp-username': None,
        'boot-ftp-password': None,
        'boot-ftp-insfile': None,
        'boot-media-file': None,
    }
    options = original_options(options)
    properties = options_to_properties(options, name_map)

    required_ftp_option_names = (
        'boot-ftp-host',
        'boot-ftp-username',
github zhmcclient / python-zhmcclient / zhmccli / _cmd_vfunction.py View on Github external
def cmd_vfunction_show(cmd_ctx, cpc_name, partition_name, vfunction_name):

    client = zhmcclient.Client(cmd_ctx.session)
    vfunction = find_vfunction(cmd_ctx, client, cpc_name, partition_name,
                               vfunction_name)

    try:
        vfunction.pull_full_properties()
    except zhmcclient.Error as exc:
        raise_click_exception(exc, cmd_ctx.error_format)

    cmd_ctx.spinner.stop()
    print_properties(vfunction.properties, cmd_ctx.output_format)
github zhmcclient / python-zhmcclient / zhmccli / _cmd_vswitch.py View on Github external
def cmd_vswitch_show(cmd_ctx, cpc_name, vswitch_name):

    client = zhmcclient.Client(cmd_ctx.session)
    vswitch = find_vswitch(cmd_ctx, client, cpc_name, vswitch_name)

    try:
        vswitch.pull_full_properties()
    except zhmcclient.Error as exc:
        raise_click_exception(exc, cmd_ctx.error_format)

    cmd_ctx.spinner.stop()
    print_properties(vswitch.properties, cmd_ctx.output_format)