options.py revision 3158
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# CDDL HEADER START
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# The contents of this file are subject to the terms of the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# Common Development and Distribution License (the "License").
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# You may not use this file except in compliance with the License.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# See the License for the specific language governing permissions
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# and limitations under the License.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# CDDL HEADER END
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainenfrom pkg.client.api_errors import InvalidOptionError, LinkedImageException
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen# List of available options for common option processing.
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen# options for explicit recursion; see description in client.py
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo SirainenLIST_INSTALLED_NEWEST = "list_installed_newest"
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainendef opts_table_cb_beopts(api_inst, opts, opts_new):
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen # synthesize require_new_be and deny_new_be into new_be
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen if (opts[BE_NAME] or opts[REQUIRE_NEW_BE]) and opts[DENY_NEW_BE]:
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen # create a new key called BACKUP_BE in the options array
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # synthesize require_backup_be and no_backup_be into backup_be
178511b57faa7c3f8203dd8b7e4059d00cbfc23aTimo Sirainen if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # create a new key called BACKUP_BE in the options array
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen if opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]:
9e59a1f3f095b3099478562cf3f3970a24736970Timo Sirainendef opts_table_cb_li_ignore(api_inst, opts, opts_new):
96c253a039f102fa78a313ee05200ab3970112dcTimo Sirainen # synthesize li_ignore_all and li_ignore_list into li_ignore
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainen # check if there's nothing to ignore
c3412ddeb9abc13f99d3caf50faf76cd99f7e9d2Timo Sirainen if not opts[LI_IGNORE_ALL] and not opts[LI_IGNORE_LIST]:
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen # can't ignore all and specific images
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
b9ac6179d3aee0d1641a4ee1d78da28628929c61Timo Sirainen # can't ignore all and target anything.
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
88553367d677170a4b703b9d52aac9eabf91c656Timo Sirainen if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen # it doesn't make sense to specify images to ignore if the
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen # user is already specifying images to operate on.
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
b3febb0933fdce10394d25093e23ce0a5aadddd3Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # check for repeats
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # add to ignore list
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen opts_new[LI_IGNORE] = api_inst.parse_linked_name_list(li_ignore)
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainendef opts_table_cb_li_no_psync(api_inst, opts, opts_new):
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # if a target child linked image was specified, the no-parent-sync
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # option doesn't make sense since we know that both the parent and
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen # child image are accessible
755fe6da51ab7f54aa1d86913cb344bffef60e79Timo Sirainen # we don't accept linked image target options
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if opts[LI_TARGET_ALL] and not opts[LI_PARENT_SYNC]:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if opts[LI_TARGET_LIST] and not opts[LI_PARENT_SYNC]:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """"Parse linked image property options that were specified on the
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen command line into a dictionary. Make sure duplicate properties were
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen not specified."""
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen raise InvalidOptionError(msg=_("linked image "
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen "property arguments must be of the form "
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen "'<name>=<value>'."))
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(msg=_("invalid linked "
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(msg=_("linked image "
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen "property specified multiple times: "
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainendef opts_table_cb_li_props(api_inst, opts, opts_new):
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen """convert linked image prop list into a dictionary"""
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen opts_new[LI_PROPS] = __parse_linked_props(opts[LI_PROPS])
db7c9201c88e3d9bee10485194ee5b0c67249916Timo Sirainendef opts_table_cb_li_target(api_inst, opts, opts_new):
db7c9201c88e3d9bee10485194ee5b0c67249916Timo Sirainen # figure out which option the user specified
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen if opts[LI_TARGET_ALL] and opts[LI_TARGET_LIST]:
db7c9201c88e3d9bee10485194ee5b0c67249916Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
a393d9d6dabdc46cf724f8cb004a652b4036d53dTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # validate linked image name
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen # check for repeats
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen # add to ignore list
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen api_inst.parse_linked_name_list(li_target_list)
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainendef opts_table_cb_li_target1(api_inst, opts, opts_new):
9a06cabdfdf4d5e2f19a07e506c3c7d08a7e7038Timo Sirainen # figure out which option the user specified
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainendef opts_table_cb_li_recurse(api_inst, opts, opts_new):
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen if opts[LI_ERECURSE_EXCL] and not opts[LI_ERECURSE_ALL]:
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen if opts[LI_ERECURSE_INCL] and not opts[LI_ERECURSE_ALL]:
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen if opts[LI_ERECURSE_INCL] and opts[LI_ERECURSE_EXCL]:
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen # Go through all children and check if they are in the recurse list.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen _("invalid linked image or zone name "
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # include list specified
8af07808ba203f8709e2ff9eaf2291e1c4a4d53dTimo Sirainen # exclude list specified
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # If we use image recursion we need to make sure uninstall and update
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # ignore non-existing packages in the parent image.
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen if opts_new[LI_ERECURSE] and IGNORE_MISSING in opts:
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainendef opts_table_cb_no_headers_vs_quiet(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # check if we accept the -q option
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # -q implies -H
b9ac6179d3aee0d1641a4ee1d78da28628929c61Timo Sirainen # Be careful not to overwrite global_settings.client_output_quiet
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # because it might be set "True" from elsewhere, e.g. in
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # opts_table_cb_parsable.
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen global_settings.client_output_verbose = opts[VERBOSE]
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainendef opts_table_cb_nqv(api_inst, opts, opts_new):
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainendef opts_table_cb_publishers(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_table_cb_parsable(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if opts[PARSABLE_VERSION] and opts.get(VERBOSE, False):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen global_settings.client_output_parsable_version = \
88553367d677170a4b703b9d52aac9eabf91c656Timo Sirainendef opts_table_cb_origins(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_table_cb_stage(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen if opts_new[STAGE] not in pkgdefs.api_stage_values:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(msg=_("invalid operation stage: "
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_cb_li_attach(api_inst, opts, opts_new):
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen if opts[ATTACH_PARENT] and opts[ATTACH_CHILD]:
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen if not opts[ATTACH_PARENT] and not opts[ATTACH_CHILD]:
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen raise InvalidOptionError(InvalidOptionError.XOR,
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # if we're attaching a new child then that doesn't affect
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # any other children, so ignoring them doesn't make sense.
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainendef opts_table_cb_md_only(api_inst, opts, opts_new):
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # if the user didn't specify linked-md-only we're done
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # li_md_only implies no li_pkg_updates
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # if li_md_only is false that means we're not updating any packages
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # within the current image so there are a ton of options that no
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # longer apply to the current operation, and hence are incompatible
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen # with li_md_only.
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainen if LI_PARENT_SYNC in opts and not opts[LI_PARENT_SYNC]:
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
99be58a447b69d62cbd9e764000a06226b9c9c89Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
bbc92cfb17eb71d2ee9463c9cfd70dfea9a36bb6Timo Sirainen if opts_new[ORIGINS] and opts_new[LIST_UPGRADABLE]:
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainen if opts_new[ORIGINS] and not opts_new[LIST_NEWEST]:
ff640b54224881abbc21141f217c881d6ba5cd28Timo Sirainen # Use of -g implies -a unless -n is provided.
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainen if opts_new[LIST_ALL] and not opts_new[LIST_INSTALLED_NEWEST]:
ff640b54224881abbc21141f217c881d6ba5cd28Timo Sirainen raise InvalidOptionError(InvalidOptionError.REQUIRED,
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainen if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_NEWEST]:
ff640b54224881abbc21141f217c881d6ba5cd28Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainen if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_UPGRADABLE]:
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(InvalidOptionError.INCOMPAT,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_cb_int(k, api_inst, opts, opts_new, minimum=None):
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen raise InvalidOptionError(msg=err, options=[k])
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # get the original argument value
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # make sure it is an integer
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # not a valid integer
3f190f4cbb9233a3a6830956cb5c7ae56a577b79Timo Sirainen raise InvalidOptionError(msg=err, options=[k])
b2ecd50bb98c44816cb07c17aa17fae2b425f941Timo Sirainen # check the minimum bounds
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen err = _("value must be >= {0:d}").format(minimum)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(msg=err, options=[k])
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # update the new options array to make the value an integer
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen opts_cb_int(k, api_inst, opts, opts_new, minimum=0)
60d3fa9883237e896a8704275b6116fa46f7ffdaTimo Sirainen err = _("value '{0}' invalid").format(opts_new[k])
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # not a valid file descriptor
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen raise InvalidOptionError(msg=err, options=[k])
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_table_cb_concurrency(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # remove concurrency from parameters dict
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen # make sure we have an integer
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen opts_cb_int(CONCURRENCY, api_inst, opts, opts_new)
60d3fa9883237e896a8704275b6116fa46f7ffdaTimo Sirainen # update global concurrency setting
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen global_settings.client_concurrency = opts_new[CONCURRENCY]
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # remove concurrency from parameters dict
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_table_cb_actuators(api_inst, opts, opts_new):
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # make sure we have an integer
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen opts_cb_int(ACT_TIMEOUT, api_inst, opts, opts_new)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen # -1 is no timeout
907723f35f4d3dfc774ca42d00a8a7b8ef90dd5dTimo Sirainen # 0 is no sync actuators are used (timeout=0)
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# options common to multiple pkg(1) operations. The format for specifying
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# options is a list which can contain:
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen# - Tuples formatted as:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# (k, v, [val])
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# where the values are:
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# k: the key value for the options dictionary
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# v: the default value. valid values are: True/False, None, [], 0
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# val: the valid argument list. It should be a list,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen# and it is optional.
d7abb52419f9aaf5de040778de3ea238b2431234Timo Sirainen# Options for pkg(1) subcommands. Built by combining the option tables above,
907723f35f4d3dfc774ca42d00a8a7b8ef90dd5dTimo Sirainen# with some optional subcommand unique options defined below.
7f3be7d885c75cdd77f536929a45bc9764595960Timo Sirainen# "update" cmd inherits all main cmd options
6843896c40bee4f9b6680ca7ced598c446e9f999Timo Sirainen# "attach-linked" cmd inherits all main cmd options
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen# "set-property-linked" cmd inherits all main cmd options
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen# "sync-linked" cmd inherits all main cmd options
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen pkgdefs.PKG_OP_AUDIT_LINKED : opts_audit_linked,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen pkgdefs.PKG_OP_LIST_LINKED : opts_list_linked,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen pkgdefs.PKG_OP_PROP_LINKED : opts_list_property_linked,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen pkgdefs.PKG_OP_SET_MEDIATOR : opts_set_mediator,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen pkgdefs.PKG_OP_SET_PROP_LINKED: opts_set_property_linked,
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen """Get the available options for a particular operation specified by
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen 'op'. If the client uses custom pkg_op_opts tables they can be specified
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen by 'add_table'."""
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen if add_table is not None:
292a66475ffe1037c2535063614f8beb71d266bfTimo Sirainendef get_pkg_opts_defaults(op, opt, add_table=None):
292a66475ffe1037c2535063614f8beb71d266bfTimo Sirainen """ Get the default value for a certain option 'opt' of a certain
292a66475ffe1037c2535063614f8beb71d266bfTimo Sirainen operation 'op'. This is useful for clients which toggle boolean options.
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainendef opts_assemble(op, api_inst, opts, add_table=None, cwd=None):
fcfd317f7eb1f0216764c75c5fab3555020552d4Timo Sirainen """Assembly of the options for a specific operation. Options are read in
fcfd317f7eb1f0216764c75c5fab3555020552d4Timo Sirainen from a dict (see explanation below) and sanity tested.
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen This is the common interface to supply options to the functions of the
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen 'op' is the operation for which the options need to be assembled and
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen verified. The currently supported operations are listed in
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen pkgdefs.pkg_op_values.
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen 'api_inst' is a reference to the API instance, required for some of the
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen verification steps.
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen 'opts' is the raw options table to be processed. It needs to be a dict
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen in the format: { option_name: argument, ... }
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen if cwd is not None:
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen # If no valid argument list specified.
63a61b7a739ae0f3f520215137d9c50f94d0f34fTimo Sirainen # for options not given we substitue the default value
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen assert type(opts[avail_opt]) == int, opts[avail_opt]
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen assert type(opts[avail_opt]) == list, opts[avail_opt]
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen assert type(opts[avail_opt]) == bool, opts[avail_opt]
345212e8f61ebf14ff4f80df26df9e655eb5121eTimo Sirainen assert type(default) == list or default is None, \
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen # run the option verification callbacks