2875N/A#!/usr/bin/python
2875N/A#
2875N/A# CDDL HEADER START
2875N/A#
2875N/A# The contents of this file are subject to the terms of the
2875N/A# Common Development and Distribution License (the "License").
2875N/A# You may not use this file except in compliance with the License.
2875N/A#
2875N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2875N/A# or http://www.opensolaris.org/os/licensing.
2875N/A# See the License for the specific language governing permissions
2875N/A# and limitations under the License.
2875N/A#
2875N/A# When distributing Covered Code, include this CDDL HEADER in each
2875N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2875N/A# If applicable, add the following below this CDDL HEADER, with the
2875N/A# fields enclosed by brackets "[]" replaced with your own identifying
2875N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2875N/A#
2875N/A# CDDL HEADER END
2875N/A#
2875N/A
3336N/A# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2875N/A
2875N/Aimport os
2875N/A
2875N/Aimport pkg.client.pkgdefs as pkgdefs
2875N/Aimport pkg.client.linkedimage as li
2875N/Aimport pkg.misc as misc
2875N/A
3025N/Afrom pkg.client.api_errors import InvalidOptionError, LinkedImageException
2875N/Afrom pkg.client import global_settings
2875N/A
2875N/A_orig_cwd = None
2875N/A
2875N/A# List of available options for common option processing.
2875N/AACCEPT = "accept"
2875N/AALLOW_RELINK = "allow_relink"
2875N/AATTACH_CHILD = "attach_child"
2875N/AATTACH_PARENT = "attach_parent"
2875N/ABACKUP_BE = "backup_be"
2875N/ABACKUP_BE_NAME = "backup_be_name"
2875N/ABE_ACTIVATE = "be_activate"
2875N/ABE_NAME = "be_name"
2875N/ACONCURRENCY = "concurrency"
2875N/ADENY_NEW_BE = "deny_new_be"
2875N/AFORCE = "force"
3025N/AIGNORE_MISSING = "ignore_missing"
2875N/ALI_IGNORE = "li_ignore"
2875N/ALI_IGNORE_ALL = "li_ignore_all"
2875N/ALI_IGNORE_LIST = "li_ignore_list"
2875N/ALI_MD_ONLY = "li_md_only"
2875N/ALI_NAME = "li_name"
2875N/ALI_PARENT_SYNC = "li_parent_sync"
2875N/ALI_PKG_UPDATES = "li_pkg_updates"
2875N/ALI_PROPS = "li_props"
2875N/ALI_TARGET_ALL = "li_target_all"
2875N/ALI_TARGET_LIST = "li_target_list"
3025N/A# options for explicit recursion; see description in client.py
3025N/ALI_ERECURSE_ALL = "li_erecurse_all"
3025N/ALI_ERECURSE_INCL = "li_erecurse_list"
3025N/ALI_ERECURSE_EXCL = "li_erecurse_excl"
3025N/ALI_ERECURSE = "li_erecurse"
2875N/ALIST_ALL = "list_all"
2875N/ALIST_INSTALLED_NEWEST = "list_installed_newest"
2875N/ALIST_NEWEST = "list_newest"
2875N/ALIST_UPGRADABLE = "list_upgradable"
2875N/AMED_IMPLEMENTATION = "med_implementation"
2875N/AMED_VERSION = "med_version"
2875N/ANEW_BE = "new_be"
2875N/ANO_BACKUP_BE = "no_backup_be"
2875N/ANOEXECUTE = "noexecute"
2875N/AOMIT_HEADERS = "omit_headers"
2875N/AORIGINS = "origins"
2875N/APARSABLE_VERSION = "parsable_version"
2875N/AQUIET = "quiet"
2875N/AREFRESH_CATALOGS = "refresh_catalogs"
2875N/AREJECT_PATS = "reject_pats"
2875N/AREQUIRE_BACKUP_BE = "require_backup_be"
2875N/AREQUIRE_NEW_BE = "require_new_be"
2875N/ASHOW_LICENSES = "show_licenses"
2875N/ASTAGE = "stage"
2875N/ASUMMARY = "summary"
2875N/ATAGGED = "tagged"
2875N/AUPDATE_INDEX = "update_index"
3336N/AUNPACKAGED = "unpackaged"
3336N/AUNPACKAGED_ONLY = "unpackaged_only"
3407N/AVERIFY_PATHS = "verify_paths"
2875N/AVERBOSE = "verbose"
3014N/ASYNC_ACT = "sync_act"
3014N/AACT_TIMEOUT = "act_timeout"
3110N/APUBLISHERS = "publishers"
3185N/ASSL_KEY = "ssl_key"
3185N/ASSL_CERT = "ssl_cert"
3185N/AAPPROVED_CA_CERTS = "approved_ca_certs"
3185N/AREVOKED_CA_CERTS = "revoked_ca_certs"
3185N/AUNSET_CA_CERTS = "unset_ca_certs"
3185N/AORIGIN_URI = "origin_uri"
3185N/ARESET_UUID = "reset_uuid"
3185N/AADD_MIRRORS = "add_mirrors"
3185N/AREMOVE_MIRRORS = "remove_mirrors"
3185N/AADD_ORIGINS = "add_origins"
3185N/AREMOVE_ORIGINS = "remove_origins"
3371N/AENABLE_ORIGINS = "enable_origins"
3371N/ADISABLE_ORIGINS = "disable_origins"
3185N/AREFRESH_ALLOWED = "refresh_allowed"
3185N/APUB_ENABLE = "enable"
3185N/APUB_DISABLE = "disable"
3185N/APUB_STICKY = "sticky"
3185N/APUB_NON_STICKY = "non_sticky"
3185N/AREPO_URI = "repo_uri"
3185N/APROXY_URI = "proxy_uri"
3185N/ASEARCH_BEFORE = "search_before"
3185N/ASEARCH_AFTER = "search_after"
3185N/ASEARCH_FIRST = "search_first"
3185N/ASET_PROPS = "set_props"
3185N/AADD_PROP_VALUES = "add_prop_values"
3185N/AREMOVE_PROP_VALUES = "remove_prop_values"
3185N/AUNSET_PROPS = "unset_props"
3185N/APREFERRED_ONLY = "preferred_only"
3185N/AINC_DISABLED = "inc_disabled"
3185N/AOUTPUT_FORMAT = "output_format"
3185N/ADISPLAY_LICENSE = "display_license"
3185N/AINFO_LOCAL = "info_local"
3185N/AINFO_REMOTE = "info_remote"
2875N/A
3185N/Adef opts_table_cb_info(api_inst, opts, opts_new):
3185N/A opts_new[ORIGINS] = set()
3185N/A for e in opts[ORIGINS]:
3185N/A opts_new[ORIGINS].add(misc.parse_uri(e,
3185N/A cwd=_orig_cwd))
3185N/A if opts[ORIGINS]:
3185N/A opts_new[INFO_REMOTE] = True
3185N/A if opts[QUIET]:
3185N/A global_settings.client_output_quiet = True
3185N/A if not opts_new[INFO_LOCAL] and not opts_new[INFO_REMOTE]:
3185N/A opts_new[INFO_LOCAL] = True
3185N/A elif opts_new[INFO_LOCAL] and opts_new[INFO_REMOTE]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [INFO_LOCAL, INFO_REMOTE])
3185N/A
3185N/Adef __parse_set_props(args):
3185N/A """"Parse set property options that were specified on the command
3185N/A line into a dictionary. Make sure duplicate properties were not
3185N/A specified."""
3185N/A
3185N/A set_props = dict()
3185N/A for pv in args:
3185N/A try:
3185N/A p, v = pv.split("=", 1)
3185N/A except ValueError:
3185N/A raise InvalidOptionError(msg=_("properties to be set "
3185N/A "must be of the form '<name>=<value>'. This is "
3185N/A "what was given: {0}").format(pv))
3185N/A
3185N/A if p in set_props:
3185N/A raise InvalidOptionError(msg=_("a property may only "
3185N/A "be set once in a command. {0} was set twice"
3185N/A ).format(p))
3185N/A set_props[p] = v
3185N/A
3185N/A return set_props
3185N/A
3185N/Adef __parse_prop_values(args, add=True):
3185N/A """"Parse add or remove property values options that were specified
3185N/A on the command line into a dictionary. Make sure duplicate properties
3185N/A were not specified."""
3185N/A
3185N/A props_values = dict()
3185N/A if add:
3185N/A add_txt = "added"
3185N/A else:
3185N/A add_txt = "removed"
3185N/A
3185N/A for pv in args:
3185N/A try:
3185N/A p, v = pv.split("=", 1)
3185N/A except ValueError:
3185N/A raise InvalidOptionError(msg=_("property values to be "
3185N/A "{add} must be of the form '<name>=<value>'. "
3185N/A "This is what was given: {key}").format(
3185N/A add=add_txt, key=pv))
3185N/A
3185N/A props_values.setdefault(p, [])
3185N/A props_values[p].append(v)
3185N/A
3185N/A return props_values
3185N/A
3185N/Adef opts_table_cb_pub_list(api_inst, opts, opts_new):
3185N/A if opts[OUTPUT_FORMAT] == None:
3185N/A opts_new[OUTPUT_FORMAT] = "default"
3185N/A
3185N/Adef opts_table_cb_pub_props(api_inst, opts, opts_new):
3185N/A opts_new[SET_PROPS] = __parse_set_props(opts[SET_PROPS])
3185N/A opts_new[ADD_PROP_VALUES] = __parse_prop_values(opts[ADD_PROP_VALUES])
3185N/A opts_new[REMOVE_PROP_VALUES] = __parse_prop_values(
3185N/A opts[REMOVE_PROP_VALUES], add=False)
3185N/A opts_new[UNSET_PROPS] = set(opts[UNSET_PROPS])
3185N/A
3185N/Adef opts_table_cb_pub_search(api_inst, opts, opts_new):
3185N/A if opts[SEARCH_BEFORE] and opts[SEARCH_AFTER]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [SEARCH_BEFORE, SEARCH_AFTER])
3185N/A
3185N/A if opts[SEARCH_BEFORE] and opts[SEARCH_FIRST]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [SEARCH_BEFORE, SEARCH_FIRST])
3185N/A
3185N/A if opts[SEARCH_AFTER] and opts[SEARCH_FIRST]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [SEARCH_AFTER, SEARCH_FIRST])
3185N/A
3185N/Adef opts_table_cb_pub_opts(api_inst, opts, opts_new):
3185N/A del opts_new[PUB_DISABLE]
3185N/A del opts_new[PUB_ENABLE]
3185N/A del opts_new[PUB_STICKY]
3185N/A del opts_new[PUB_NON_STICKY]
3185N/A
3185N/A if opts[PUB_DISABLE] and opts[PUB_ENABLE]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [PUB_DISABLE, PUB_ENABLE])
3185N/A
3185N/A if opts[PUB_STICKY] and opts[PUB_NON_STICKY]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [PUB_STICKY, PUB_NON_STICKY])
3185N/A
3185N/A opts_new[PUB_DISABLE] = None
3185N/A if opts[PUB_DISABLE]:
3185N/A opts_new[PUB_DISABLE] = True
3185N/A
3185N/A if opts[PUB_ENABLE]:
3185N/A opts_new[PUB_DISABLE] = False
3185N/A
3185N/A opts_new[PUB_STICKY] = None
3185N/A if opts[PUB_STICKY]:
3185N/A opts_new[PUB_STICKY] = True
3185N/A
3185N/A if opts[PUB_NON_STICKY]:
3185N/A opts_new[PUB_STICKY] = False
3185N/A
3185N/A if opts[ORIGIN_URI] and opts[ADD_ORIGINS]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [ORIGIN_URI, ADD_ORIGINS])
3185N/A
3185N/A if opts[ORIGIN_URI] and opts[REMOVE_ORIGINS]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [ORIGIN_URI, REMOVE_ORIGINS])
3185N/A
3185N/A if opts[REPO_URI] and opts[ADD_ORIGINS]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, ADD_ORIGINS])
3185N/A if opts[REPO_URI] and opts[ADD_MIRRORS]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, ADD_MIRRORS])
3185N/A if opts[REPO_URI] and opts[REMOVE_ORIGINS]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, REMOVE_ORIGINS])
3185N/A if opts[REPO_URI] and opts[REMOVE_MIRRORS]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, REMOVE_MIRRORS])
3185N/A if opts[REPO_URI] and opts[PUB_DISABLE]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, PUB_DISABLE])
3185N/A if opts[REPO_URI] and opts[PUB_ENABLE]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, PUB_ENABLE])
3185N/A if opts[REPO_URI] and not opts[REFRESH_ALLOWED]:
3185N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
3185N/A [REPO_URI, REFRESH_ALLOWED])
3185N/A if opts[REPO_URI] and opts[RESET_UUID]:
3185N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3185N/A [REPO_URI, RESET_UUID])
3185N/A
3185N/A if opts[PROXY_URI] and not (opts[ADD_ORIGINS] or opts[ADD_MIRRORS]
3185N/A or opts[REPO_URI] or opts[REMOVE_ORIGINS] or opts[REMOVE_MIRRORS]):
3185N/A raise InvalidOptionError(InvalidOptionError.REQUIRED_ANY,
3185N/A [PROXY_URI, ADD_ORIGINS, ADD_MIRRORS, REMOVE_ORIGINS,
3185N/A REMOVE_MIRRORS, REPO_URI])
3185N/A
3185N/A opts_new[ADD_ORIGINS] = set()
3185N/A opts_new[REMOVE_ORIGINS] = set()
3185N/A opts_new[ADD_MIRRORS] = set()
3185N/A opts_new[REMOVE_MIRRORS] = set()
3371N/A opts_new[ENABLE_ORIGINS] = set()
3371N/A opts_new[DISABLE_ORIGINS] = set()
3185N/A for e in opts[ADD_ORIGINS]:
3371N/A if e == "*":
3371N/A if not (opts[PUB_DISABLE] or opts[PUB_ENABLE]):
3371N/A raise InvalidOptionError(InvalidOptionError.XOR,
3371N/A [PUB_ENABLE, PUB_DISABLE])
3371N/A # Allow wildcard to support an easy, scriptable
3371N/A # way of enabling all existing entries.
3371N/A if opts[PUB_DISABLE]:
3371N/A opts_new[DISABLE_ORIGINS].add("*")
3371N/A if opts[PUB_ENABLE]:
3371N/A opts_new[ENABLE_ORIGINS].add("*")
3371N/A else:
3371N/A opts_new[ADD_ORIGINS].add(misc.parse_uri(e,
3371N/A cwd=_orig_cwd))
3371N/A
3371N/A # If enable/disable is specified and "*" is not present, then assign
3371N/A # origins collected to be added into disable/enable set as well.
3371N/A if opts[PUB_DISABLE]:
3371N/A if "*" not in opts_new[DISABLE_ORIGINS]:
3371N/A opts_new[DISABLE_ORIGINS] = opts_new[ADD_ORIGINS]
3371N/A
3371N/A if opts[PUB_ENABLE]:
3371N/A if "*" not in opts_new[ENABLE_ORIGINS]:
3371N/A opts_new[ENABLE_ORIGINS] = opts_new[ADD_ORIGINS]
3371N/A
3185N/A for e in opts[REMOVE_ORIGINS]:
3185N/A if e == "*":
3185N/A # Allow wildcard to support an easy, scriptable
3185N/A # way of removing all existing entries.
3185N/A opts_new[REMOVE_ORIGINS].add("*")
3185N/A else:
3185N/A opts_new[REMOVE_ORIGINS].add(misc.parse_uri(e,
3185N/A cwd=_orig_cwd))
3185N/A
3185N/A for e in opts[ADD_MIRRORS]:
3185N/A opts_new[ADD_MIRRORS].add(misc.parse_uri(e, cwd=_orig_cwd))
3185N/A for e in opts[REMOVE_MIRRORS]:
3185N/A if e == "*":
3185N/A # Allow wildcard to support an easy, scriptable
3185N/A # way of removing all existing entries.
3185N/A opts_new[REMOVE_MIRRORS].add("*")
3185N/A else:
3185N/A opts_new[REMOVE_MIRRORS].add(misc.parse_uri(e,
3185N/A cwd=_orig_cwd))
3185N/A
3185N/A if opts[REPO_URI]:
3185N/A opts_new[REPO_URI] = misc.parse_uri(opts[REPO_URI],
3185N/A cwd=_orig_cwd)
2875N/A
2875N/Adef opts_table_cb_beopts(api_inst, opts, opts_new):
2875N/A
2875N/A # synthesize require_new_be and deny_new_be into new_be
2875N/A del opts_new[REQUIRE_NEW_BE]
2875N/A del opts_new[DENY_NEW_BE]
2875N/A opts_new[NEW_BE] = None
2875N/A
2875N/A if (opts[BE_NAME] or opts[REQUIRE_NEW_BE]) and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [REQUIRE_NEW_BE, DENY_NEW_BE])
2875N/A
2875N/A # create a new key called BACKUP_BE in the options array
2875N/A if opts[REQUIRE_NEW_BE] or opts[BE_NAME]:
2875N/A opts_new[NEW_BE] = True
2875N/A if opts[DENY_NEW_BE]:
2875N/A opts_new[NEW_BE] = False
2875N/A
2875N/A # synthesize require_backup_be and no_backup_be into backup_be
2875N/A del opts_new[REQUIRE_BACKUP_BE]
2875N/A del opts_new[NO_BACKUP_BE]
2875N/A opts_new[BACKUP_BE] = None
2875N/A
2875N/A if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
2875N/A opts[NO_BACKUP_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [REQUIRE_BACKUP_BE, NO_BACKUP_BE])
2875N/A
2875N/A if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
2875N/A (opts[REQUIRE_NEW_BE] or opts[BE_NAME]):
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [REQUIRE_BACKUP_BE, REQUIRE_NEW_BE])
2875N/A
2875N/A # create a new key called BACKUP_BE in the options array
2875N/A if opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]:
2875N/A opts_new[BACKUP_BE] = True
2875N/A if opts[NO_BACKUP_BE]:
2875N/A opts_new[BACKUP_BE] = False
2875N/A
2875N/Adef opts_table_cb_li_ignore(api_inst, opts, opts_new):
2875N/A
2875N/A # synthesize li_ignore_all and li_ignore_list into li_ignore
2875N/A del opts_new[LI_IGNORE_ALL]
2875N/A del opts_new[LI_IGNORE_LIST]
2875N/A opts_new[LI_IGNORE] = None
2875N/A
2875N/A # check if there's nothing to ignore
2875N/A if not opts[LI_IGNORE_ALL] and not opts[LI_IGNORE_LIST]:
2875N/A return
2875N/A
2875N/A if opts[LI_IGNORE_ALL]:
2875N/A
2875N/A # can't ignore all and specific images
2875N/A if opts[LI_IGNORE_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_IGNORE_LIST])
2875N/A
2875N/A # can't ignore all and target anything.
2875N/A if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_TARGET_ALL])
2875N/A if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_TARGET_LIST])
2875N/A if LI_NAME in opts and opts[LI_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_NAME])
2875N/A opts_new[LI_IGNORE] = []
2875N/A return
2875N/A
2875N/A assert opts[LI_IGNORE_LIST]
2875N/A
2875N/A # it doesn't make sense to specify images to ignore if the
2875N/A # user is already specifying images to operate on.
2875N/A if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_LIST, LI_TARGET_ALL])
2875N/A if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_LIST, LI_TARGET_LIST])
2875N/A if LI_NAME in opts and opts[LI_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_LIST, LI_NAME])
2875N/A
2875N/A li_ignore = []
2875N/A for li_name in opts[LI_IGNORE_LIST]:
2875N/A # check for repeats
2875N/A if li_name in li_ignore:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.ARG_REPEAT, [li_name,
2875N/A LI_IGNORE_LIST])
2875N/A # add to ignore list
2875N/A li_ignore.append(li_name)
2875N/A
2875N/A opts_new[LI_IGNORE] = api_inst.parse_linked_name_list(li_ignore)
2875N/A
2875N/Adef opts_table_cb_li_no_psync(api_inst, opts, opts_new):
2875N/A # if a target child linked image was specified, the no-parent-sync
2875N/A # option doesn't make sense since we know that both the parent and
2875N/A # child image are accessible
2875N/A
2875N/A if LI_TARGET_ALL not in opts:
2875N/A # we don't accept linked image target options
2875N/A assert LI_TARGET_LIST not in opts
2875N/A return
2875N/A
2875N/A if opts[LI_TARGET_ALL] and not opts[LI_PARENT_SYNC]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [LI_TARGET_ALL, LI_PARENT_SYNC])
2875N/A
2875N/A if opts[LI_TARGET_LIST] and not opts[LI_PARENT_SYNC]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [LI_TARGET_LIST, LI_PARENT_SYNC])
2875N/A
3336N/Adef opts_table_cb_unpackaged(api_inst, opts, opts_new):
3336N/A # Check whether unpackaged and unpackaged_only options are used
3336N/A # together.
3336N/A
3336N/A if opts[UNPACKAGED] and opts[UNPACKAGED_ONLY]:
3336N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3336N/A [UNPACKAGED, UNPACKAGED_ONLY])
2875N/A
3407N/Adef opts_table_cb_path_no_unpackaged(api_inst, opts, opts_new):
3407N/A # Check whether path options is used with either unpackaged
3407N/A # or unpackaged_only options.
3407N/A
3407N/A if opts[VERIFY_PATHS] and opts[UNPACKAGED]:
3407N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3407N/A [VERIFY_PATHS, UNPACKAGED])
3407N/A
3407N/A if opts[VERIFY_PATHS] and opts[UNPACKAGED_ONLY]:
3407N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3407N/A [VERIFY_PATHS, UNPACKAGED_ONLY])
3407N/A
2875N/Adef __parse_linked_props(args):
2875N/A """"Parse linked image property options that were specified on the
2875N/A command line into a dictionary. Make sure duplicate properties were
2875N/A not specified."""
2875N/A
2875N/A linked_props = dict()
2875N/A for pv in args:
2875N/A try:
2875N/A p, v = pv.split("=", 1)
2875N/A except ValueError:
2875N/A raise InvalidOptionError(msg=_("linked image "
2875N/A "property arguments must be of the form "
2875N/A "'<name>=<value>'."))
2875N/A
2875N/A if p not in li.prop_values:
2875N/A raise InvalidOptionError(msg=_("invalid linked "
3158N/A "image property: '{0}'.").format(p))
2875N/A
2875N/A if p in linked_props:
2875N/A raise InvalidOptionError(msg=_("linked image "
3158N/A "property specified multiple times: "
3158N/A "'{0}'.").format(p))
2875N/A
2875N/A linked_props[p] = v
2875N/A
2875N/A return linked_props
2875N/A
2875N/Adef opts_table_cb_li_props(api_inst, opts, opts_new):
2875N/A """convert linked image prop list into a dictionary"""
2875N/A
2875N/A opts_new[LI_PROPS] = __parse_linked_props(opts[LI_PROPS])
2875N/A
2875N/Adef opts_table_cb_li_target(api_inst, opts, opts_new):
2875N/A # figure out which option the user specified
2875N/A if opts[LI_TARGET_ALL] and opts[LI_TARGET_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_TARGET_ALL, LI_TARGET_LIST])
2875N/A elif opts[LI_TARGET_ALL]:
2875N/A arg1 = LI_TARGET_ALL
2875N/A elif opts[LI_TARGET_LIST]:
2875N/A arg1 = LI_TARGET_LIST
2875N/A else:
2875N/A return
2875N/A
2875N/A if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [arg1, BE_ACTIVATE])
2875N/A if BE_NAME in opts and opts[BE_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, BE_NAME])
2875N/A if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, DENY_NEW_BE])
2875N/A if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REQUIRE_NEW_BE])
2875N/A if REJECT_PATS in opts and opts[REJECT_PATS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REJECT_PATS])
2875N/A if ORIGINS in opts and opts[ORIGINS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, ORIGINS])
2875N/A
2875N/A # validate linked image name
2875N/A li_target_list = []
2875N/A for li_name in opts[LI_TARGET_LIST]:
2875N/A # check for repeats
2875N/A if li_name in li_target_list:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.ARG_REPEAT, [li_name,
2875N/A LI_TARGET_LIST])
2875N/A # add to ignore list
2875N/A li_target_list.append(li_name)
2875N/A
2875N/A opts_new[LI_TARGET_LIST] = \
2875N/A api_inst.parse_linked_name_list(li_target_list)
2875N/A
2875N/Adef opts_table_cb_li_target1(api_inst, opts, opts_new):
2875N/A # figure out which option the user specified
2875N/A if opts[LI_NAME]:
2875N/A arg1 = LI_NAME
2875N/A else:
2875N/A return
2875N/A
2875N/A if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [arg1, BE_ACTIVATE])
2875N/A if BE_NAME in opts and opts[BE_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, BE_NAME])
2875N/A if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, DENY_NEW_BE])
2875N/A if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REQUIRE_NEW_BE])
2875N/A if REJECT_PATS in opts and opts[REJECT_PATS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REJECT_PATS])
2875N/A if ORIGINS in opts and opts[ORIGINS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, ORIGINS])
2875N/A
3025N/Adef opts_table_cb_li_recurse(api_inst, opts, opts_new):
3025N/A
3025N/A del opts_new[LI_ERECURSE_INCL]
3025N/A del opts_new[LI_ERECURSE_EXCL]
3025N/A del opts_new[LI_ERECURSE_ALL]
3025N/A
3025N/A if opts[LI_ERECURSE_EXCL] and not opts[LI_ERECURSE_ALL]:
3025N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
3025N/A [LI_ERECURSE_EXCL, LI_ERECURSE_ALL])
3025N/A
3025N/A if opts[LI_ERECURSE_INCL] and not opts[LI_ERECURSE_ALL]:
3025N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
3025N/A [LI_ERECURSE_INCL, LI_ERECURSE_ALL])
3025N/A
3025N/A if opts[LI_ERECURSE_INCL] and opts[LI_ERECURSE_EXCL]:
3025N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3025N/A [LI_ERECURSE_INCL, LI_ERECURSE_EXCL])
3025N/A
3025N/A if not opts[LI_ERECURSE_ALL]:
3025N/A opts_new[LI_ERECURSE] = None
3025N/A return
3025N/A
3025N/A # Go through all children and check if they are in the recurse list.
3025N/A li_child_targets = []
3025N/A li_child_list = set([
3025N/A lin
3025N/A for lin, rel, path in api_inst.list_linked()
3025N/A if rel == "child"
3025N/A ])
3025N/A
3025N/A def parse_lin(ulin):
3025N/A lin = None
3025N/A try:
3025N/A lin = api_inst.parse_linked_name(ulin,
3025N/A allow_unknown=True)
3171N/A except LinkedImageException as e:
3025N/A try:
3158N/A lin = api_inst.parse_linked_name(
3158N/A "zone:{0}".format(ulin), allow_unknown=True)
3171N/A except LinkedImageException as e:
3025N/A pass
3025N/A if lin is None or lin not in li_child_list:
3025N/A raise InvalidOptionError(msg=
3158N/A _("invalid linked image or zone name "
3158N/A "'{0}'.").format(ulin))
3025N/A
3025N/A return lin
3025N/A
3025N/A if opts[LI_ERECURSE_INCL]:
3025N/A # include list specified
3025N/A for ulin in opts[LI_ERECURSE_INCL]:
3025N/A li_child_targets.append(parse_lin(ulin))
3025N/A opts_new[LI_ERECURSE] = li_child_targets
3025N/A else:
3025N/A # exclude list specified
3025N/A for ulin in opts[LI_ERECURSE_EXCL]:
3025N/A li_child_list.remove(parse_lin(ulin))
3025N/A opts_new[LI_ERECURSE] = li_child_list
3025N/A
3025N/A # If we use image recursion we need to make sure uninstall and update
3025N/A # ignore non-existing packages in the parent image.
3025N/A if opts_new[LI_ERECURSE] and IGNORE_MISSING in opts:
3025N/A opts_new[IGNORE_MISSING] = True
3025N/A
2875N/Adef opts_table_cb_no_headers_vs_quiet(api_inst, opts, opts_new):
2875N/A # check if we accept the -q option
2875N/A if QUIET not in opts:
2875N/A return
2875N/A
2875N/A # -q implies -H
2875N/A if opts[QUIET]:
2875N/A opts_new[OMIT_HEADERS] = True
2875N/A
2875N/Adef opts_table_cb_q(api_inst, opts, opts_new):
2875N/A # Be careful not to overwrite global_settings.client_output_quiet
2875N/A # because it might be set "True" from elsewhere, e.g. in
2875N/A # opts_table_cb_parsable.
2875N/A if opts[QUIET] is True:
2875N/A global_settings.client_output_quiet = True
2875N/A
2875N/Adef opts_table_cb_v(api_inst, opts, opts_new):
2875N/A global_settings.client_output_verbose = opts[VERBOSE]
2875N/A
2875N/Adef opts_table_cb_nqv(api_inst, opts, opts_new):
2875N/A if opts[VERBOSE] and opts[QUIET]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [VERBOSE, QUIET])
2875N/A
3110N/Adef opts_table_cb_publishers(api_inst, opts, opts_new):
3110N/A publishers = set()
3110N/A for p in opts[PUBLISHERS]:
3110N/A publishers.add(p)
3110N/A opts_new[PUBLISHERS] = publishers
3110N/A
2875N/Adef opts_table_cb_parsable(api_inst, opts, opts_new):
3336N/A if opts[PARSABLE_VERSION] is not None and opts.get(VERBOSE, False):
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [VERBOSE, PARSABLE_VERSION])
3336N/A if opts[PARSABLE_VERSION] is not None and opts.get(OMIT_HEADERS,
3336N/A False):
3336N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
3336N/A [OMIT_HEADERS, PARSABLE_VERSION])
3336N/A if opts[PARSABLE_VERSION] is not None:
2875N/A try:
2875N/A opts_new[PARSABLE_VERSION] = int(
2875N/A opts[PARSABLE_VERSION])
2875N/A except ValueError:
2875N/A raise InvalidOptionError(
2875N/A options=[PARSABLE_VERSION],
2875N/A msg=_("integer argument expected"))
2875N/A
2875N/A global_settings.client_output_parsable_version = \
2875N/A opts_new[PARSABLE_VERSION]
2875N/A opts_new[QUIET] = True
2875N/A global_settings.client_output_quiet = True
2875N/A
2875N/Adef opts_table_cb_origins(api_inst, opts, opts_new):
2875N/A origins = set()
2875N/A for o in opts[ORIGINS]:
2875N/A origins.add(misc.parse_uri(o, cwd=_orig_cwd))
2875N/A opts_new[ORIGINS] = origins
2875N/A
2875N/Adef opts_table_cb_stage(api_inst, opts, opts_new):
2875N/A if opts[STAGE] == None:
2875N/A opts_new[STAGE] = pkgdefs.API_STAGE_DEFAULT
2875N/A return
2875N/A
2875N/A if opts_new[STAGE] not in pkgdefs.api_stage_values:
2875N/A raise InvalidOptionError(msg=_("invalid operation stage: "
3158N/A "'{0}'").format(opts[STAGE]))
2875N/A
2875N/Adef opts_cb_li_attach(api_inst, opts, opts_new):
2875N/A if opts[ATTACH_PARENT] and opts[ATTACH_CHILD]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [ATTACH_PARENT, ATTACH_CHILD])
2875N/A
2875N/A if not opts[ATTACH_PARENT] and not opts[ATTACH_CHILD]:
2875N/A raise InvalidOptionError(InvalidOptionError.XOR,
2875N/A [ATTACH_PARENT, ATTACH_CHILD])
2875N/A
2875N/A if opts[ATTACH_CHILD]:
2875N/A # if we're attaching a new child then that doesn't affect
2875N/A # any other children, so ignoring them doesn't make sense.
2875N/A if opts[LI_IGNORE_ALL]:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.INCOMPAT,
2875N/A [ATTACH_CHILD, LI_IGNORE_ALL])
2875N/A if opts[LI_IGNORE_LIST]:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.INCOMPAT,
2875N/A [ATTACH_CHILD, LI_IGNORE_LIST])
2875N/A
2875N/Adef opts_table_cb_md_only(api_inst, opts, opts_new):
2875N/A # if the user didn't specify linked-md-only we're done
2875N/A if not opts[LI_MD_ONLY]:
2875N/A return
2875N/A
2875N/A # li_md_only implies no li_pkg_updates
2875N/A if LI_PKG_UPDATES in opts:
2875N/A opts_new[LI_PKG_UPDATES] = False
2875N/A
2875N/A #
2875N/A # if li_md_only is false that means we're not updating any packages
2875N/A # within the current image so there are a ton of options that no
2875N/A # longer apply to the current operation, and hence are incompatible
2875N/A # with li_md_only.
2875N/A #
2875N/A arg1 = LI_MD_ONLY
2875N/A if BE_NAME in opts and opts[BE_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, BE_NAME])
2875N/A if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, DENY_NEW_BE])
2875N/A if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REQUIRE_NEW_BE])
2875N/A if LI_PARENT_SYNC in opts and not opts[LI_PARENT_SYNC]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [arg1, LI_PARENT_SYNC])
2875N/A if REJECT_PATS in opts and opts[REJECT_PATS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REJECT_PATS])
2875N/A
2875N/Adef opts_cb_list(api_inst, opts, opts_new):
2875N/A if opts_new[ORIGINS] and opts_new[LIST_UPGRADABLE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [ORIGINS, LIST_UPGRADABLE])
2875N/A
2875N/A if opts_new[ORIGINS] and not opts_new[LIST_NEWEST]:
2875N/A # Use of -g implies -a unless -n is provided.
2875N/A opts_new[LIST_INSTALLED_NEWEST] = True
2875N/A
2875N/A if opts_new[LIST_ALL] and not opts_new[LIST_INSTALLED_NEWEST]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [LIST_ALL, LIST_INSTALLED_NEWEST])
2875N/A
2875N/A if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_NEWEST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LIST_INSTALLED_NEWEST, LIST_NEWEST])
2875N/A
2875N/A if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_UPGRADABLE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LIST_INSTALLED_NEWEST, LIST_UPGRADABLE])
2875N/A
2875N/A if opts_new[SUMMARY] and opts_new[VERBOSE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [SUMMARY, VERBOSE])
2875N/A
2893N/A if opts_new[QUIET] and opts_new[VERBOSE]:
2893N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2893N/A [QUIET, VERBOSE])
2893N/A
2875N/Adef opts_cb_int(k, api_inst, opts, opts_new, minimum=None):
2875N/A
2875N/A if k not in opts or opts[k] == None:
2875N/A err = _("missing required parameter")
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/A # get the original argument value
2875N/A v = opts[k]
2875N/A
2875N/A # make sure it is an integer
2875N/A try:
2875N/A v = int(v)
2875N/A except (ValueError, TypeError):
2875N/A # not a valid integer
3158N/A err = _("value '{0}' invalid").format(v)
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/A # check the minimum bounds
2875N/A if minimum is not None and v < minimum:
3158N/A err = _("value must be >= {0:d}").format(minimum)
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/A # update the new options array to make the value an integer
2875N/A opts_new[k] = v
2875N/A
2875N/Adef opts_cb_fd(k, api_inst, opts, opts_new):
2875N/A opts_cb_int(k, api_inst, opts, opts_new, minimum=0)
2875N/A
3158N/A err = _("value '{0}' invalid").format(opts_new[k])
2875N/A try:
2875N/A os.fstat(opts_new[k])
2875N/A except OSError:
2875N/A # not a valid file descriptor
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/Adef opts_table_cb_concurrency(api_inst, opts, opts_new):
2875N/A if opts[CONCURRENCY] is None:
2875N/A # remove concurrency from parameters dict
2875N/A del opts_new[CONCURRENCY]
2875N/A return
2875N/A
2875N/A # make sure we have an integer
2875N/A opts_cb_int(CONCURRENCY, api_inst, opts, opts_new)
2875N/A
2875N/A # update global concurrency setting
2875N/A global_settings.client_concurrency = opts_new[CONCURRENCY]
2896N/A global_settings.client_concurrency_set = True
2875N/A
2875N/A # remove concurrency from parameters dict
2875N/A del opts_new[CONCURRENCY]
2875N/A
3014N/Adef opts_table_cb_actuators(api_inst, opts, opts_new):
3014N/A
3014N/A del opts_new[ACT_TIMEOUT]
3014N/A del opts_new[SYNC_ACT]
3014N/A
3014N/A if opts[ACT_TIMEOUT]:
3014N/A # make sure we have an integer
3014N/A opts_cb_int(ACT_TIMEOUT, api_inst, opts, opts_new)
3014N/A elif opts[SYNC_ACT]:
3014N/A # -1 is no timeout
3014N/A opts_new[ACT_TIMEOUT] = -1
3014N/A else:
3014N/A # 0 is no sync actuators are used (timeout=0)
3014N/A opts_new[ACT_TIMEOUT] = 0
3014N/A
2875N/A#
2875N/A# options common to multiple pkg(1) operations. The format for specifying
2875N/A# options is a list which can contain:
2875N/A#
2875N/A# - Tuples formatted as:
3185N/A# (k, v, [val], {})
2875N/A# where the values are:
2875N/A# k: the key value for the options dictionary
2875N/A# v: the default value. valid values are: True/False, None, [], 0
3031N/A# val: the valid argument list. It should be a list,
3031N/A# and it is optional.
3185N/A# {}: json schema.
2875N/A#
2875N/A
3185N/Aopts_table_info = [
3185N/A opts_table_cb_info,
3185N/A (DISPLAY_LICENSE, False, [], {"type": "boolean"}),
3185N/A (INFO_LOCAL, False, [], {"type": "boolean"}),
3185N/A (INFO_REMOTE, False, [], {"type": "boolean"}),
3185N/A (ORIGINS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (QUIET, False, [], {"type": "boolean"})
3185N/A]
3185N/A
3185N/Aopts_table_pub_list = [
3185N/A opts_table_cb_pub_list,
3185N/A (PREFERRED_ONLY, False, [], {"type": "boolean"}),
3185N/A (INC_DISABLED, True, [], {"type": "boolean"}),
3185N/A (OUTPUT_FORMAT, None, ["default", "tsv"], {"type": ["null", "string"]}),
3185N/A (OMIT_HEADERS, False, [], {"type": "boolean"})
3185N/A]
3185N/A
3185N/Aopts_table_pub_props = [
3185N/A opts_table_cb_pub_props,
3185N/A (SET_PROPS, [], [], {"type": "array", "items": {"type": "string"}
3185N/A }),
3185N/A (ADD_PROP_VALUES, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (REMOVE_PROP_VALUES, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (UNSET_PROPS, [], [], {"type": "array", "items": {"type": "string"}
3185N/A })
3185N/A]
3185N/A
3185N/Aopts_table_ssl = [
3185N/A (SSL_KEY, None, [], {"type": ["null", "string"]}),
3185N/A (SSL_CERT, None, [], {"type": ["null", "string"]}),
3185N/A (APPROVED_CA_CERTS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (REVOKED_CA_CERTS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (UNSET_CA_CERTS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A]
3185N/A
3185N/Aopts_table_pub_search = [
3185N/A opts_table_cb_pub_search,
3185N/A (SEARCH_BEFORE, None, [], {"type": ["null", "string"]}),
3185N/A (SEARCH_AFTER, None, [], {"type": ["null", "string"]}),
3185N/A (SEARCH_FIRST, False, [], {"type": "boolean"}),
3185N/A]
3185N/A
3185N/Aopts_table_pub_opts = [
3185N/A opts_table_cb_pub_opts,
3185N/A (ORIGIN_URI, None, [], {"type": ["null", "string"]}),
3185N/A (RESET_UUID, False, [], {"type": "boolean"}),
3185N/A (ADD_MIRRORS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (REMOVE_MIRRORS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (ADD_ORIGINS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (REMOVE_ORIGINS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3371N/A (ENABLE_ORIGINS, [], [], {"type": "array",
3371N/A "items": {"type": "string"}
3371N/A }),
3371N/A (DISABLE_ORIGINS, [], [], {"type": "array",
3371N/A "items": {"type": "string"}
3371N/A }),
3185N/A (REFRESH_ALLOWED, True, [], {"type": "boolean"}),
3185N/A (PUB_ENABLE, False, [], {"type": "boolean"}),
3185N/A (PUB_DISABLE, False, [], {"type": "boolean"}),
3185N/A (PUB_STICKY, False, [], {"type": "boolean"}),
3185N/A (PUB_NON_STICKY, False, [], {"type": "boolean"}),
3185N/A (REPO_URI, None, [], {"type": ["null", "string"]}),
3185N/A (PROXY_URI, None, [], {"type": ["null", "string"]}),
3185N/A]
2875N/A
2875N/Aopts_table_beopts = [
2875N/A opts_table_cb_beopts,
3185N/A (BACKUP_BE_NAME, None, [], {"type": ["null", "string"]}),
3185N/A (BE_NAME, None, [], {"type": ["null", "string"]}),
3185N/A (DENY_NEW_BE, False, [], {"type": "boolean"}),
3185N/A (NO_BACKUP_BE, False, [], {"type": "boolean"}),
3185N/A (BE_ACTIVATE, True, [], {"type": "boolean"}),
3185N/A (REQUIRE_BACKUP_BE, False, [], {"type": "boolean"}),
3185N/A (REQUIRE_NEW_BE, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_concurrency = [
2875N/A opts_table_cb_concurrency,
3185N/A (CONCURRENCY, None, [], {"type": ["null", "integer"],
3185N/A "minimum": 0}),
2875N/A]
2875N/A
2875N/Aopts_table_force = [
3185N/A (FORCE, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_li_ignore = [
2875N/A opts_table_cb_li_ignore,
3185N/A (LI_IGNORE_ALL, False, [], {"type": "boolean"}),
3185N/A (LI_IGNORE_LIST, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
2875N/A]
2875N/A
2875N/Aopts_table_li_md_only = [
2875N/A opts_table_cb_md_only,
3185N/A (LI_MD_ONLY, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_li_no_pkg_updates = [
3185N/A (LI_PKG_UPDATES, True, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_li_no_psync = [
2875N/A opts_table_cb_li_no_psync,
3185N/A (LI_PARENT_SYNC, True, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_li_props = [
2875N/A opts_table_cb_li_props,
3185N/A (LI_PROPS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
2875N/A]
2875N/A
2875N/Aopts_table_li_target = [
2875N/A opts_table_cb_li_target,
3185N/A (LI_TARGET_ALL, False, [], {"type": "boolean"}),
3185N/A (LI_TARGET_LIST, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
2875N/A]
2875N/A
2875N/Aopts_table_li_target1 = [
2875N/A opts_table_cb_li_target1,
3185N/A (LI_NAME, None, [], {"type": ["null", "string"]}),
2875N/A]
2875N/A
3025N/Aopts_table_li_recurse = [
3025N/A opts_table_cb_li_recurse,
3185N/A (LI_ERECURSE_ALL, False, [], {"type": "boolean"}),
3185N/A (LI_ERECURSE_INCL, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3185N/A (LI_ERECURSE_EXCL, [], [], {"type": "array",
3185N/A "items": {"type": "string"}}),
3025N/A]
3025N/A
2875N/Aopts_table_licenses = [
3185N/A (ACCEPT, False, [], {"type": "boolean"}),
3185N/A (SHOW_LICENSES, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_no_headers = [
2875N/A opts_table_cb_no_headers_vs_quiet,
3185N/A (OMIT_HEADERS, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_no_index = [
3185N/A (UPDATE_INDEX, True, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_no_refresh = [
3185N/A (REFRESH_CATALOGS, True, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_reject = [
3185N/A (REJECT_PATS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
2875N/A]
2875N/A
2875N/Aopts_table_verbose = [
2875N/A opts_table_cb_v,
3185N/A (VERBOSE, 0, [], {"type": "integer", "minimum": 0}),
2875N/A]
2875N/A
2875N/Aopts_table_quiet = [
2875N/A opts_table_cb_q,
3185N/A (QUIET, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_parsable = [
2875N/A opts_table_cb_parsable,
3336N/A (PARSABLE_VERSION, None, [None, 0], {"type": ["null", "integer"],
3185N/A "minimum": 0, "maximum": 0
3185N/A }),
2875N/A]
2875N/A
2875N/Aopts_table_nqv = \
2875N/A opts_table_quiet + \
2875N/A opts_table_verbose + \
2875N/A [
2875N/A opts_table_cb_nqv,
3185N/A (NOEXECUTE, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
2875N/Aopts_table_origins = [
2875N/A opts_table_cb_origins,
3185N/A (ORIGINS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
2875N/A]
2875N/A
2875N/Aopts_table_stage = [
2875N/A opts_table_cb_stage,
3185N/A (STAGE, None, [], {"type": ["null", "string"]}),
2875N/A]
2875N/A
3025N/Aopts_table_missing = [
3185N/A (IGNORE_MISSING, False, [], {"type": "boolean"}),
3025N/A]
3025N/A
3014N/Aopts_table_actuators = [
3014N/A opts_table_cb_actuators,
3185N/A (SYNC_ACT, False, [], {"type": "boolean"}),
3185N/A (ACT_TIMEOUT, None, [], {"type": ["null", "integer"],
3185N/A "minimum": 0})
3014N/A]
3014N/A
3110N/Aopts_table_publishers = [
3110N/A opts_table_cb_publishers,
3185N/A (PUBLISHERS, [], [], {"type": "array",
3185N/A "items": {"type": "string"}
3185N/A }),
3110N/A]
3110N/A
3336N/Aopts_table_unpackaged = [
3336N/A (UNPACKAGED, False, [], {"type": "boolean"}),
3336N/A]
2875N/A#
2875N/A# Options for pkg(1) subcommands. Built by combining the option tables above,
2875N/A# with some optional subcommand unique options defined below.
2875N/A#
3025N/A
3014N/Aopts_main = \
2875N/A opts_table_beopts + \
2875N/A opts_table_concurrency + \
2875N/A opts_table_li_ignore + \
2875N/A opts_table_li_no_psync + \
2875N/A opts_table_licenses + \
2875N/A opts_table_reject + \
2875N/A opts_table_no_index + \
2875N/A opts_table_no_refresh + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A opts_table_origins + \
2875N/A []
2875N/A
3014N/Aopts_install = \
3014N/A opts_main + \
3025N/A opts_table_stage + \
3025N/A opts_table_li_recurse + \
3014N/A opts_table_actuators + \
3014N/A []
3014N/A
3185N/Aopts_set_publisher = \
3185N/A opts_table_ssl + \
3185N/A opts_table_pub_opts + \
3185N/A opts_table_pub_props + \
3185N/A opts_table_pub_search + \
3185N/A []
3185N/A
3185N/Aopts_info = \
3185N/A opts_table_info + \
3185N/A []
3185N/A
3014N/A# "update" cmd inherits all main cmd options
2875N/Aopts_update = \
3014N/A opts_main + \
2875N/A opts_table_force + \
3025N/A opts_table_li_recurse + \
2875N/A opts_table_stage + \
3014N/A opts_table_actuators + \
3025N/A opts_table_missing + \
2875N/A []
2875N/A
3014N/A# "attach-linked" cmd inherits all main cmd options
2875N/Aopts_attach_linked = \
3014N/A opts_main + \
2875N/A opts_table_force + \
2875N/A opts_table_li_md_only + \
2875N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_props + \
2875N/A [
2875N/A opts_cb_li_attach,
2875N/A (ALLOW_RELINK, False),
2875N/A (ATTACH_CHILD, False),
2875N/A (ATTACH_PARENT, False),
2875N/A]
2875N/A
2875N/Aopts_revert = \
2875N/A opts_table_beopts + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A [
2875N/A (TAGGED, False),
2875N/A]
2875N/A
2875N/Aopts_set_mediator = \
2875N/A opts_table_beopts + \
2875N/A opts_table_no_index + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A [
2875N/A (MED_IMPLEMENTATION, None),
2875N/A (MED_VERSION, None)
2875N/A]
2875N/A
3014N/A# "set-property-linked" cmd inherits all main cmd options
2875N/Aopts_set_property_linked = \
3014N/A opts_main + \
2875N/A opts_table_li_md_only + \
2875N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_target1 + \
2875N/A []
2875N/A
3014N/A# "sync-linked" cmd inherits all main cmd options
2875N/Aopts_sync_linked = \
3014N/A opts_main + \
2875N/A opts_table_li_md_only + \
2875N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_target + \
2875N/A opts_table_stage + \
2875N/A []
2875N/A
2875N/Aopts_uninstall = \
2875N/A opts_table_beopts + \
2875N/A opts_table_concurrency + \
2875N/A opts_table_li_ignore + \
2925N/A opts_table_li_no_psync + \
2875N/A opts_table_no_index + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
3014N/A opts_table_stage + \
3025N/A opts_table_li_recurse + \
3025N/A opts_table_missing + \
3025N/A opts_table_actuators + \
3025N/A []
2875N/A
2875N/Aopts_audit_linked = \
2875N/A opts_table_li_no_psync + \
2875N/A opts_table_li_target + \
2875N/A opts_table_no_headers + \
2875N/A opts_table_quiet + \
2875N/A []
2875N/A
2875N/Aopts_detach_linked = \
2875N/A opts_table_force + \
2925N/A opts_table_li_md_only + \
2925N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_target + \
2875N/A opts_table_nqv + \
2875N/A []
2875N/A
2875N/Aopts_list_linked = \
2875N/A opts_table_li_ignore + \
2875N/A opts_table_no_headers + \
2875N/A []
2875N/A
2875N/Aopts_list_property_linked = \
2875N/A opts_table_li_target1 + \
2875N/A opts_table_no_headers + \
2875N/A []
2875N/A
2875N/Aopts_list_inventory = \
2875N/A opts_table_li_no_psync + \
2875N/A opts_table_no_refresh + \
2875N/A opts_table_no_headers + \
2875N/A opts_table_origins + \
2893N/A opts_table_quiet + \
2875N/A opts_table_verbose + \
2875N/A [
2875N/A opts_cb_list,
3185N/A (LIST_INSTALLED_NEWEST, False, [], {"type": "boolean"}),
3185N/A (LIST_ALL, False, [], {"type": "boolean"}),
3185N/A (LIST_NEWEST, False, [], {"type": "boolean"}),
3185N/A (SUMMARY, False, [], {"type": "boolean"}),
3185N/A (LIST_UPGRADABLE, False, [], {"type": "boolean"}),
2875N/A]
2875N/A
3110N/Aopts_dehydrate = \
3110N/A opts_table_nqv + \
3110N/A opts_table_publishers + \
3110N/A []
3110N/A
3110N/Aopts_fix = \
3110N/A opts_table_beopts + \
3110N/A opts_table_nqv + \
3110N/A opts_table_licenses + \
3146N/A opts_table_no_headers + \
3159N/A opts_table_parsable + \
3336N/A opts_table_unpackaged + \
3110N/A []
3110N/A
3146N/Aopts_verify = \
3146N/A opts_table_quiet + \
3146N/A opts_table_verbose + \
3146N/A opts_table_no_headers + \
3159N/A opts_table_parsable + \
3336N/A opts_table_unpackaged + \
3146N/A [
3336N/A opts_table_cb_nqv,
3336N/A opts_table_cb_unpackaged,
3407N/A opts_table_cb_path_no_unpackaged,
3336N/A (UNPACKAGED_ONLY, False, [], {"type": "boolean"}),
3407N/A (VERIFY_PATHS, [], [], {"type": "array",
3407N/A "items": {"type": "string"}}),
3146N/A]
3146N/A
3185N/Aopts_publisher = \
3185N/A opts_table_pub_list + \
3185N/A []
3185N/A
2875N/Apkg_op_opts = {
2875N/A
2875N/A pkgdefs.PKG_OP_ATTACH : opts_attach_linked,
2875N/A pkgdefs.PKG_OP_AUDIT_LINKED : opts_audit_linked,
2875N/A pkgdefs.PKG_OP_CHANGE_FACET : opts_install,
2875N/A pkgdefs.PKG_OP_CHANGE_VARIANT : opts_install,
3110N/A pkgdefs.PKG_OP_DEHYDRATE : opts_dehydrate,
2875N/A pkgdefs.PKG_OP_DETACH : opts_detach_linked,
3030N/A pkgdefs.PKG_OP_EXACT_INSTALL : opts_main,
3110N/A pkgdefs.PKG_OP_FIX : opts_fix,
3185N/A pkgdefs.PKG_OP_INFO : opts_info,
2875N/A pkgdefs.PKG_OP_INSTALL : opts_install,
2875N/A pkgdefs.PKG_OP_LIST : opts_list_inventory,
2875N/A pkgdefs.PKG_OP_LIST_LINKED : opts_list_linked,
2875N/A pkgdefs.PKG_OP_PROP_LINKED : opts_list_property_linked,
2875N/A pkgdefs.PKG_OP_PUBCHECK : [],
3185N/A pkgdefs.PKG_OP_PUBLISHER_LIST : opts_publisher,
3110N/A pkgdefs.PKG_OP_REHYDRATE : opts_dehydrate,
2875N/A pkgdefs.PKG_OP_REVERT : opts_revert,
2875N/A pkgdefs.PKG_OP_SET_MEDIATOR : opts_set_mediator,
3185N/A pkgdefs.PKG_OP_SET_PUBLISHER : opts_set_publisher,
2875N/A pkgdefs.PKG_OP_SET_PROP_LINKED: opts_set_property_linked,
2875N/A pkgdefs.PKG_OP_SYNC : opts_sync_linked,
2875N/A pkgdefs.PKG_OP_UNINSTALL : opts_uninstall,
3185N/A pkgdefs.PKG_OP_UNSET_PUBLISHER: [],
3146N/A pkgdefs.PKG_OP_UPDATE : opts_update,
3146N/A pkgdefs.PKG_OP_VERIFY : opts_verify
2875N/A}
2875N/A
2875N/Adef get_pkg_opts(op, add_table=None):
2875N/A """Get the available options for a particular operation specified by
2875N/A 'op'. If the client uses custom pkg_op_opts tables they can be specified
2875N/A by 'add_table'."""
2875N/A
2875N/A popts = pkg_op_opts.copy()
2875N/A if add_table is not None:
2875N/A popts.update(add_table)
2875N/A
2875N/A try:
2875N/A opts = popts[op]
2875N/A except KeyError:
2875N/A opts = None
2875N/A return opts
2875N/A
2875N/Adef get_pkg_opts_defaults(op, opt, add_table=None):
2875N/A """ Get the default value for a certain option 'opt' of a certain
2875N/A operation 'op'. This is useful for clients which toggle boolean options.
2875N/A """
2875N/A popts = get_pkg_opts(op, add_table)
2875N/A
2875N/A for o in popts:
2875N/A if type(o) != tuple:
2875N/A continue
3031N/A if len(o) == 2:
3031N/A opt_name, default = o
3031N/A elif len(o) == 3:
3185N/A opt_name, default, dummy_valid_args = o
3185N/A elif len(o) == 4:
3185N/A opt_name, default, dummy_valid_args, dummy_schema = o
2875N/A if opt_name == opt:
2875N/A return default
2875N/A
2875N/Adef opts_assemble(op, api_inst, opts, add_table=None, cwd=None):
2875N/A """Assembly of the options for a specific operation. Options are read in
2875N/A from a dict (see explanation below) and sanity tested.
2875N/A
2875N/A This is the common interface to supply options to the functions of the
2875N/A API.
2875N/A
2875N/A 'op' is the operation for which the options need to be assembled and
2875N/A verified. The currently supported operations are listed in
2875N/A pkgdefs.pkg_op_values.
2875N/A
2875N/A 'api_inst' is a reference to the API instance, required for some of the
2875N/A verification steps.
2875N/A
2875N/A 'opts' is the raw options table to be processed. It needs to be a dict
2875N/A in the format: { option_name: argument, ... }
2875N/A """
2875N/A
2875N/A global _orig_cwd
2875N/A
2875N/A if cwd is not None:
2875N/A _orig_cwd = cwd
2875N/A else:
2875N/A _orig_cwd = None
2875N/A
2875N/A popts = get_pkg_opts(op, add_table)
2875N/A
2875N/A rv = {}
2875N/A callbacks = []
2875N/A
2875N/A for o in popts:
2875N/A if type(o) != tuple:
2875N/A callbacks.append(o)
2875N/A continue
3031N/A valid_args = []
3031N/A # If no valid argument list specified.
3031N/A if len(o) == 2:
3031N/A avail_opt, default = o
3031N/A elif len(o) == 3:
3031N/A avail_opt, default, valid_args = o
3185N/A elif len(o) == 4:
3185N/A avail_opt, default, valid_args, schema = o
2875N/A # for options not given we substitue the default value
2875N/A if avail_opt not in opts:
2875N/A rv[avail_opt] = default
2875N/A continue
2875N/A
2875N/A if type(default) == int:
2875N/A assert type(opts[avail_opt]) == int, opts[avail_opt]
2875N/A elif type(default) == list:
2875N/A assert type(opts[avail_opt]) == list, opts[avail_opt]
2875N/A elif type(default) == bool:
2875N/A assert type(opts[avail_opt]) == bool, opts[avail_opt]
2875N/A
3031N/A if valid_args:
3031N/A assert type(default) == list or default is None, \
3031N/A default
3031N/A raise_error = False
3031N/A if type(opts[avail_opt]) == list:
3031N/A if not set(opts[avail_opt]).issubset(
3031N/A set(valid_args)):
3031N/A raise_error = True
3031N/A else:
3336N/A # If the any of valid_args is integer, we first
3336N/A # try to convert the argument value into
3336N/A # integer. This is for CLI mode where arguments
3336N/A # are strings.
3336N/A if any(type(va) == int for va in valid_args):
3336N/A try:
3336N/A opts[avail_opt] = int(
3336N/A opts[avail_opt])
3336N/A except Exception:
3336N/A pass
3031N/A if opts[avail_opt] not in valid_args:
3031N/A raise_error = True
3031N/A if raise_error:
3031N/A raise InvalidOptionError(
3031N/A InvalidOptionError.ARG_INVALID,
3185N/A [opts[avail_opt], avail_opt],
3185N/A valid_args=valid_args)
3031N/A
2875N/A rv[avail_opt] = opts[avail_opt]
2875N/A
2875N/A rv_updated = rv.copy()
2875N/A
2875N/A # run the option verification callbacks
2875N/A for cb in callbacks:
2875N/A cb(api_inst, rv, rv_updated)
2875N/A
2875N/A return rv_updated
2875N/A