src/modules/client/api.py
author Yiteng Zhang <yiteng.zhang@oracle.com>
Tue, 04 Feb 2014 11:53:32 -0800
changeset 3010 2741200f3d9e
parent 3003 0612a636198c
child 3014 a88a867e3a9d
permissions -rw-r--r--
17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1516
8c950a3b4171 10485 move pkg(5) to Python 2.6
Rich Burridge <rich.burridge@sun.com>
parents: 1505
diff changeset
     1
#!/usr/bin/python
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     2
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     4
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     8
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    13
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    19
#
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    21
#
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    22
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    23
#
3010
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
    24
# Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    25
#
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    26
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    27
"""This module provides the supported, documented interface for clients to
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    28
interface with the pkg(5) system.
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    29
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    30
Refer to pkg.api_common and pkg.plandesc for additional core class
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    31
documentation.
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    32
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    33
Consumers should catch ApiException when calling any API function, and
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    34
may optionally catch any subclass of ApiException for further, specific
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    35
error handling.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
    36
"""
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    37
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    38
#
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    39
# this file is not completely pylint clean
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    40
#
2828
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
    41
# pylint: disable=C0111,C0301,C0321,E0702,R0201,W0102
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
    42
# pylint: disable=W0212,W0511,W0612,W0613,W0702
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    43
#
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    44
# C0111 Missing docstring
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    45
# C0301 Line too long
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    46
# C0321 More than one statement on a single line
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    47
# E0702 Raising NoneType while only classes, instances or string are allowed
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    48
# R0201 Method could be a function
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    49
# W0102 Dangerous default value %s as argument
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    50
# W0212 Access to a protected member %s of a client class
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    51
# W0511 XXX
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    52
# W0612 Unused variable '%s'
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    53
# W0613 Unused argument '%s'
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    54
# W0702 No exception type(s) specified
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    55
#
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    56
1853
8f8a90301844 15234 "pkg list -a" doesn't account for pattern versions
Shawn Walker <shawn.walker@oracle.com>
parents: 1843
diff changeset
    57
import collections
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
    58
import copy
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
    59
import datetime
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    60
import errno
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    61
import fnmatch
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
    62
import glob
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
    63
import os
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    64
import shutil
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    65
import simplejson as json
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
    66
import sys
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
    67
import tempfile
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    68
import threading
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
    69
import time
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    70
import urllib
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    71
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
    72
import pkg.client.api_errors as apx
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    73
import pkg.client.bootenv as bootenv
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    74
import pkg.client.history as history
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    75
import pkg.client.image as image
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
    76
import pkg.client.imageconfig as imgcfg
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    77
import pkg.client.imageplan as imageplan
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
    78
import pkg.client.imagetypes as imgtypes
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    79
import pkg.client.indexer as indexer
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
    80
import pkg.client.pkgdefs as pkgdefs
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
    81
import pkg.client.plandesc as plandesc
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    82
import pkg.client.publisher as publisher
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    83
import pkg.client.query_parser as query_p
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    84
import pkg.fmri as fmri
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
    85
import pkg.mediator as med
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    86
import pkg.misc as misc
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    87
import pkg.nrlock
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
    88
import pkg.p5i as p5i
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
    89
import pkg.p5s as p5s
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
    90
import pkg.portable as portable
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    91
import pkg.search_errors as search_errors
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
    92
import pkg.version
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
    93
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    94
from pkg.api_common import (PackageInfo, LicenseInfo, PackageCategory,
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
    95
    _get_pkg_cat_data)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
    96
from pkg.client import global_settings
2207
029ca014fced 17797 plan debugging should also display solver trim database
Shawn Walker <shawn.walker@oracle.com>
parents: 2205
diff changeset
    97
from pkg.client.debugvalues import DebugValues
2828
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
    98
from pkg.client.pkgdefs import * # pylint: disable=W0401
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
    99
from pkg.smf import NonzeroExitException
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
   100
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   101
# we import PlanDescription here even though it isn't used so that consumers
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   102
# of the api still have access to the class definition and are able to do
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   103
# things like help(pkg.client.api.PlanDescription)
2828
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
   104
from pkg.client.plandesc import PlanDescription # pylint: disable=W0611
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   105
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   106
CURRENT_API_VERSION = 76
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   107
COMPATIBLE_API_VERSIONS = frozenset([72, 73, 74, 75, CURRENT_API_VERSION])
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   108
CURRENT_P5I_VERSION = 1
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   109
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   110
# Image type constants.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   111
IMG_TYPE_NONE = imgtypes.IMG_NONE # No image.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   112
IMG_TYPE_ENTIRE = imgtypes.IMG_ENTIRE # Full image ('/').
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   113
IMG_TYPE_PARTIAL = imgtypes.IMG_PARTIAL  # Not yet implemented.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   114
IMG_TYPE_USER = imgtypes.IMG_USER # Not '/'; some other location.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   115
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   116
# History result constants.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   117
RESULT_CANCELED = history.RESULT_CANCELED
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   118
RESULT_NOTHING_TO_DO = history.RESULT_NOTHING_TO_DO
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   119
RESULT_SUCCEEDED = history.RESULT_SUCCEEDED
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   120
RESULT_FAILED_BAD_REQUEST = history.RESULT_FAILED_BAD_REQUEST
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   121
RESULT_FAILED_CONFIGURATION = history.RESULT_FAILED_CONFIGURATION
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   122
RESULT_FAILED_CONSTRAINED = history.RESULT_FAILED_CONSTRAINED
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   123
RESULT_FAILED_LOCKED = history.RESULT_FAILED_LOCKED
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   124
RESULT_FAILED_SEARCH = history.RESULT_FAILED_SEARCH
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   125
RESULT_FAILED_STORAGE = history.RESULT_FAILED_STORAGE
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   126
RESULT_FAILED_TRANSPORT = history.RESULT_FAILED_TRANSPORT
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   127
RESULT_FAILED_ACTUATOR = history.RESULT_FAILED_ACTUATOR
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   128
RESULT_FAILED_OUTOFMEMORY = history.RESULT_FAILED_OUTOFMEMORY
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   129
RESULT_CONFLICTING_ACTIONS = history.RESULT_CONFLICTING_ACTIONS
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   130
RESULT_FAILED_UNKNOWN = history.RESULT_FAILED_UNKNOWN
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   131
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   132
# Globals.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
   133
logger = global_settings.logger
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
   134
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   135
class _LockedGenerator(object):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   136
        """This is a private class and should not be used by API consumers.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   137
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   138
        This decorator class wraps API generator functions, managing the
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   139
        activity and cancelation locks.  Due to implementation differences
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   140
        in the decorator protocol, the decorator must be used with
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   141
        parenthesis in order for this to function correctly.  Always
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   142
        decorate functions @_LockedGenerator()."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   143
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   144
        def __init__(self, *d_args, **d_kwargs):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   145
                object.__init__(self)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   146
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   147
        def __call__(self, f):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   148
                def wrapper(*fargs, **f_kwargs):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   149
                        instance, fargs = fargs[0], fargs[1:]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   150
                        instance._acquire_activity_lock()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   151
                        instance._enable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   152
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   153
                        clean_exit = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   154
                        canceled = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   155
                        try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   156
                                for v in f(instance, *fargs, **f_kwargs):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   157
                                        yield v
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   158
                        except GeneratorExit:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   159
                                return
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   160
                        except apx.CanceledException:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   161
                                canceled = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   162
                                raise
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   163
                        except Exception:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   164
                                clean_exit = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   165
                                raise
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   166
                        finally:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   167
                                if canceled:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   168
                                        instance._cancel_done()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   169
                                elif clean_exit:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   170
                                        try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   171
                                                instance._disable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   172
                                        except apx.CanceledException:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   173
                                                instance._cancel_done()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   174
                                                instance._activity_lock.release()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   175
                                                raise
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   176
                                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   177
                                        instance._cancel_cleanup_exception()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   178
                                instance._activity_lock.release()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   179
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   180
                return wrapper
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   181
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   182
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   183
class _LockedCancelable(object):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   184
        """This is a private class and should not be used by API consumers.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   185
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   186
        This decorator class wraps non-generator cancelable API functions,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   187
        managing the activity and cancelation locks.  Due to implementation
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   188
        differences in the decorator protocol, the decorator must be used with
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   189
        parenthesis in order for this to function correctly.  Always
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   190
        decorate functions @_LockedCancelable()."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   191
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   192
        def __init__(self, *d_args, **d_kwargs):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   193
                object.__init__(self)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   194
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   195
        def __call__(self, f):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   196
                def wrapper(*fargs, **f_kwargs):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   197
                        instance, fargs = fargs[0], fargs[1:]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   198
                        instance._acquire_activity_lock()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   199
                        instance._enable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   200
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   201
                        clean_exit = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   202
                        canceled = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   203
                        try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   204
                                return f(instance, *fargs, **f_kwargs)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   205
                        except apx.CanceledException:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   206
                                canceled = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   207
                                raise
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   208
                        except Exception:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   209
                                clean_exit = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   210
                                raise
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   211
                        finally:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   212
                                instance._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   213
                                try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   214
                                        if int(os.environ.get("PKG_DUMP_STATS",
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   215
                                            0)) > 0:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   216
                                                instance._img.transport.stats.dump()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   217
                                except ValueError:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   218
                                        # Don't generate stats if an invalid
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   219
                                        # value is supplied.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   220
                                        pass
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   221
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   222
                                if canceled:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   223
                                        instance._cancel_done()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   224
                                elif clean_exit:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   225
                                        try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   226
                                                instance._disable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   227
                                        except apx.CanceledException:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   228
                                                instance._cancel_done()
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   229
                                                # if f() acquired the image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   230
                                                # lock, drop it
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   231
                                                if instance._img.locked:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   232
                                                        instance._img.unlock()
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   233
                                                instance._activity_lock.release()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   234
                                                raise
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   235
                                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   236
                                        instance._cancel_cleanup_exception()
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   237
                                # if f() acquired the image lock, drop it
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   238
                                if instance._img.locked:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   239
                                        instance._img.unlock()
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   240
                                instance._activity_lock.release()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   241
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   242
                return wrapper
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   243
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   244
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   245
class ImageInterface(object):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   246
        """This class presents an interface to images that clients may use.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   247
        There is a specific order of methods which must be used to install
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   248
        or uninstall packages, or update an image.  First, a gen_plan_* method
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   249
        must be called.  After that method completes successfully, describe may
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   250
        be called, and prepare must be called.  Finally, execute_plan may be
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   251
        called to implement the previous created plan.  The other methods
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   252
        do not have an ordering imposed upon them, and may be used as
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   253
        needed.  Cancel may only be invoked while a cancelable method is
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   254
        running."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   255
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   256
        FACET_ALL = 0
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   257
        FACET_IMAGE = 1
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   258
        FACET_INSTALLED = 2
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   259
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   260
        FACET_SRC_SYSTEM = pkg.facet.Facets.FACET_SRC_SYSTEM
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   261
        FACET_SRC_LOCAL = pkg.facet.Facets.FACET_SRC_LOCAL
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   262
        FACET_SRC_PARENT = pkg.facet.Facets.FACET_SRC_PARENT
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   263
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   264
        # Constants used to reference specific values that info can return.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   265
        INFO_FOUND = 0
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   266
        INFO_MISSING = 1
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   267
        INFO_ILLEGALS = 3
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   268
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   269
        LIST_ALL = 0
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   270
        LIST_INSTALLED = 1
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   271
        LIST_INSTALLED_NEWEST = 2
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   272
        LIST_NEWEST = 3
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   273
        LIST_UPGRADABLE = 4
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   274
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   275
        MATCH_EXACT = 0
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   276
        MATCH_FMRI = 1
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   277
        MATCH_GLOB = 2
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
   278
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   279
        VARIANT_ALL = 0
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   280
        VARIANT_ALL_POSSIBLE = 1
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   281
        VARIANT_IMAGE = 2
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   282
        VARIANT_IMAGE_POSSIBLE = 3
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   283
        VARIANT_INSTALLED = 4
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   284
        VARIANT_INSTALLED_POSSIBLE = 5
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   285
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   286
        def __init__(self, img_path, version_id, progresstracker,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   287
            cancel_state_callable, pkg_client_name, exact_match=True,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   288
            cmdpath=None):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   289
                """Constructs an ImageInterface object.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   290
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   291
                'img_path' is the absolute path to an existing image or to a
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   292
                path from which to start looking for an image.  To control this
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   293
                behaviour use the 'exact_match' parameter.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   294
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   295
                'version_id' indicates the version of the api the client is
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   296
                expecting to use.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   297
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   298
                'progresstracker' is the ProgressTracker object the client wants
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   299
                the api to use for UI progress callbacks.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   300
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   301
                'cancel_state_callable' is an optional function reference that
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   302
                will be called if the cancellable status of an operation
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   303
                changes.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   304
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   305
                'pkg_client_name' is a string containing the name of the client,
2991
75e616731cc3 16635525 EOL of packagemanager and related components
Shawn Walker <shawn.walker@oracle.com>
parents: 2961
diff changeset
   306
                such as "pkg".
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   307
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   308
                'exact_match' is a boolean indicating whether the API should
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   309
                attempt to find a usable image starting from the specified
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   310
                directory, going up to the filesystem root until it finds one.
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   311
                If set to True, an image must exist at the location indicated
2488
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
   312
                by 'img_path'.
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   313
                """
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   314
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   315
                if version_id not in COMPATIBLE_API_VERSIONS:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   316
                        raise apx.VersionException(CURRENT_API_VERSION,
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   317
                            version_id)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   318
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   319
                if sys.path[0].startswith("/dev/fd/"):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   320
                        #
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   321
                        # Normally when the kernel forks off an interpreted
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   322
                        # program, it executes the interpreter with the first
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   323
                        # argument being the path to the interpreted program
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   324
                        # we're executing.  But in the case of suid scripts
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   325
                        # this presents a security problem because that path
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   326
                        # could be updated after exec but before the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   327
                        # interpreter opens reads the program.  To avoid this
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   328
                        # race, for suid script the kernel replaces the name
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   329
                        # of the interpreted program with /dev/fd/###, and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   330
                        # opens the interpreted program such that it can be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   331
                        # read from the specified file descriptor device node.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   332
                        # So if we detect that path[0] (which should be then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   333
                        # interpreted program name) is a /dev/fd/ path, that
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   334
                        # means we're being run as an suid script, which we
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   335
                        # don't really want to support.  (Since this breaks
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   336
                        # our subsequent code that attempt to determine the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   337
                        # name of the executable we are running as.)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   338
                        #
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   339
                        raise apx.SuidUnsupportedError()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   340
696
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   341
                # The image's History object will use client_name from
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   342
                # global_settings, but if the program forgot to set it,
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   343
                # we'll go ahead and do so here.
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   344
                if global_settings.client_name is None:
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   345
                        global_settings.client_name = pkg_client_name
6bbfd2dece6f 4371 user-agent string needs to be different for different client front-ends
Danek Duvall <danek.duvall@sun.com>
parents: 688
diff changeset
   346
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   347
                if cmdpath == None:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   348
                        cmdpath = misc.api_cmdpath()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   349
                self.cmdpath = cmdpath
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   350
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   351
                # prevent brokeness in the test suite
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   352
                if self.cmdpath and \
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   353
                    "PKG_NO_RUNPY_CMDPATH" in os.environ and \
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   354
                    self.cmdpath.endswith(os.sep + "run.py"):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   355
                        raise RuntimeError, """
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   356
An ImageInterface object was allocated from within ipkg test suite and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   357
cmdpath was not explicitly overridden.  Please make sure to set
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   358
explicitly set cmdpath when allocating an ImageInterface object, or
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   359
override cmdpath when allocating an Image object by setting PKG_CMDPATH
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   360
in the environment or by setting simulate_cmdpath in DebugValues."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   361
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   362
                if isinstance(img_path, basestring):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   363
                        # Store this for reset().
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   364
                        self._img_path = img_path
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   365
                        self._img = image.Image(img_path,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   366
                            progtrack=progresstracker,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   367
                            user_provided_dir=exact_match,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   368
                            cmdpath=self.cmdpath)
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   369
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   370
                        # Store final image path.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   371
                        self._img_path = self._img.get_root()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   372
                elif isinstance(img_path, image.Image):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   373
                        # This is a temporary, special case for client.py
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   374
                        # until the image api is complete.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   375
                        self._img = img_path
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   376
                        self._img_path = img_path.get_root()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   377
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   378
                        # API consumer passed an unknown type for img_path.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   379
                        raise TypeError(_("Unknown img_path type."))
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
   380
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   381
                self.__progresstracker = progresstracker
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   382
                lin = None
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   383
                if self._img.linked.ischild():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   384
                        lin = self._img.linked.child_name
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   385
                self.__progresstracker.set_linked_name(lin)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   386
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   387
                self.__cancel_state_callable = cancel_state_callable
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   388
                self.__plan_type = None
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   389
                self.__api_op = None
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   390
                self.__plan_desc = None
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   391
                self.__planned_children = False
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   392
                self.__prepared = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   393
                self.__executed = False
2319
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
   394
                self.__be_activate = True
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   395
                self.__backup_be_name = None
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   396
                self.__be_name = None
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   397
                self.__can_be_canceled = False
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   398
                self.__canceling = False
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   399
                self._activity_lock = pkg.nrlock.NRLock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   400
                self.__blocking_locks = False
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   401
                self._img.blocking_locks = self.__blocking_locks
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
   402
                self.__cancel_lock = pkg.nrlock.NRLock()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
   403
                self.__cancel_cv = threading.Condition(self.__cancel_lock)
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   404
                self.__backup_be = None # create if needed
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   405
                self.__new_be = None # create if needed
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   406
                self.__alt_sources = {}
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   407
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   408
        def __set_blocking_locks(self, value):
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   409
                self._activity_lock.acquire()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   410
                self.__blocking_locks = value
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   411
                self._img.blocking_locks = value
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   412
                self._activity_lock.release()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   413
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   414
        def __set_img_alt_sources(self, repos):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   415
                """Private helper function to change image to use alternate
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   416
                package sources if applicable."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   417
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   418
                # When using alternate package sources with the image, the
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   419
                # result is a composite of the package data already known
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   420
                # by the image and the alternate sources.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   421
                if repos:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   422
                        self._img.set_alt_pkg_sources(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   423
                            self.__get_alt_pkg_data(repos))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   424
                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   425
                        self._img.set_alt_pkg_sources(None)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   426
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   427
        @_LockedCancelable()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   428
        def set_alt_repos(self, repos):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   429
                """Public function to specify alternate package sources."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   430
                self.__set_img_alt_sources(repos)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   431
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   432
        blocking_locks = property(lambda self: self.__blocking_locks,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   433
            __set_blocking_locks, doc="A boolean value indicating whether "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   434
            "the API should wait until the image interface can be locked if "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   435
            "it is in use by another thread or process.  Clients should be "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   436
            "aware that there is no timeout mechanism in place if blocking is "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   437
            "enabled, and so should take steps to remain responsive to user "
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   438
            "input or provide a way for users to cancel operations.")
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   439
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   440
        @property
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   441
        def excludes(self):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   442
                """The list of excludes for the image."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   443
                return self._img.list_excludes()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   444
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   445
        @property
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   446
        def img(self):
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   447
                """Private; public access to this property will be removed at
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
   448
                a later date.  Do not use."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   449
                return self._img
884
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   450
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   451
        @property
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   452
        def img_type(self):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   453
                """Returns the IMG_TYPE constant for the image's type."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   454
                if not self._img:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   455
                        return None
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   456
                return self._img.image_type(self._img.root)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   457
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   458
        @property
2550
71fe32689f17 18914 pkg warns about image modification even if image is not liveroot
Shawn Walker <shawn.walker@oracle.com>
parents: 2547
diff changeset
   459
        def is_liveroot(self):
71fe32689f17 18914 pkg warns about image modification even if image is not liveroot
Shawn Walker <shawn.walker@oracle.com>
parents: 2547
diff changeset
   460
                """A boolean indicating whether the image to be modified is
71fe32689f17 18914 pkg warns about image modification even if image is not liveroot
Shawn Walker <shawn.walker@oracle.com>
parents: 2547
diff changeset
   461
                for the live system root."""
71fe32689f17 18914 pkg warns about image modification even if image is not liveroot
Shawn Walker <shawn.walker@oracle.com>
parents: 2547
diff changeset
   462
                return self._img.is_liveroot()
71fe32689f17 18914 pkg warns about image modification even if image is not liveroot
Shawn Walker <shawn.walker@oracle.com>
parents: 2547
diff changeset
   463
71fe32689f17 18914 pkg warns about image modification even if image is not liveroot
Shawn Walker <shawn.walker@oracle.com>
parents: 2547
diff changeset
   464
        @property
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   465
        def is_zone(self):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   466
                """A boolean value indicating whether the image is a zone."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   467
                return self._img.is_zone()
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   468
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
   469
        @property
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   470
        def is_active_liveroot_be(self):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   471
                """A boolean indicating whether the image to be modified is
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   472
                the active BE for the system's root image."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   473
2773
9e1e8c67549e 7187946 pkg running in a zone always thinks it's modifying a non-active BE
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2750
diff changeset
   474
                if not self._img.is_liveroot():
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   475
                        return False
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   476
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   477
                try:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   478
                        be_name, be_uuid = bootenv.BootEnv.get_be_name(
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   479
                            self._img.root)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   480
                        return be_name == \
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   481
                            bootenv.BootEnv.get_activated_be_name()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   482
                except apx.BEException:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   483
                        # If boot environment logic isn't supported, return
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   484
                        # False.  This is necessary for user images and for
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   485
                        # the test suite.
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   486
                        return False
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   487
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   488
        @property
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   489
        def img_plandir(self):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   490
                """A path to the image planning directory."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   491
                plandir = self._img.plandir
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   492
                misc.makedirs(plandir)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   493
                return plandir
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   494
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
   495
        @property
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   496
        def last_modified(self):
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   497
                """A datetime object representing when the image's metadata was
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   498
                last updated."""
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   499
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   500
                return self._img.get_last_modified()
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   501
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   502
        def __set_progresstracker(self, value):
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   503
                self._activity_lock.acquire()
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   504
                self.__progresstracker = value
2619
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   505
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   506
                # tell the progress tracker about this image's name
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   507
                lin = None
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   508
                if self._img.linked.ischild():
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   509
                        lin = self._img.linked.child_name
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   510
                self.__progresstracker.set_linked_name(lin)
a439e7e6a4d3 19155 ImageInterface should call set_linked_name() for ProgressTracker updates
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2616
diff changeset
   511
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   512
                self._activity_lock.release()
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   513
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   514
        progresstracker = property(lambda self: self.__progresstracker,
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   515
            __set_progresstracker, doc="The current ProgressTracker object.  "
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   516
            "This value should only be set when no other API calls are in "
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   517
            "progress.")
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
   518
2073
9fcacc9e5eaa 16998 transport should support publisher-specific write and read caches
Shawn Walker <shawn.walker@oracle.com>
parents: 2055
diff changeset
   519
        @property
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   520
        def mediators(self):
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   521
                """A dictionary of the mediators and their configured version
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   522
                and implementation of the form:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   523
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   524
                   {
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   525
                       mediator-name: {
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   526
                           "version": mediator-version-string,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   527
                           "version-source": (site|vendor|system|local),
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   528
                           "implementation": mediator-implementation-string,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   529
                           "implementation-source": (site|vendor|system|local),
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   530
                       }
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   531
                   }
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   532
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   533
                  'version' is an optional string that specifies the version
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   534
                   (expressed as a dot-separated sequence of non-negative
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   535
                   integers) of the mediator for use.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   536
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   537
                   'version-source' is a string describing the source of the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   538
                   selected version configuration.  It indicates how the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   539
                   version component of the mediation was selected.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   540
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   541
                   'implementation' is an optional string that specifies the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   542
                   implementation of the mediator for use in addition to or
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   543
                   instead of 'version'.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   544
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   545
                   'implementation-source' is a string describing the source of
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   546
                   the selected implementation configuration.  It indicates how
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   547
                   the implementation component of the mediation was selected.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   548
                 """
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   549
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   550
                ret = {}
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   551
                for m, mvalues in self._img.cfg.mediators.iteritems():
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   552
                        ret[m] = copy.copy(mvalues)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   553
                        if "version" in ret[m]:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   554
                                # Don't expose internal Version object to
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   555
                                # external consumers.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   556
                                ret[m]["version"] = \
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   557
                                    ret[m]["version"].get_short_version()
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   558
                        if "implementation-version" in ret[m]:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   559
                                # Don't expose internal Version object to
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   560
                                # external consumers.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   561
                                ret[m]["implementation-version"] = \
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   562
                                    ret[m]["implementation-version"].get_short_version()
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   563
                return ret
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   564
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   565
        @property
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   566
        def root(self):
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   567
                """The absolute pathname of the filesystem root of the image.
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   568
                This property is read-only."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   569
                if not self._img:
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   570
                        return None
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   571
                return self._img.root
1255
13914487fd06 8854 access to ImageInterface img root desired
Shawn Walker <srw@sun.com>
parents: 1254
diff changeset
   572
884
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   573
        @staticmethod
d780afc023ff 3718 plan_update_all needs to have an optional argument for the new BE name
Brock Pytlik <bpytlik@sun.com>
parents: 838
diff changeset
   574
        def check_be_name(be_name):
1076
db86977aa656 8048 image update doesn't check to see if specified be-name already exists
Rich Burridge <rich.burridge@sun.com>
parents: 1072
diff changeset
   575
                bootenv.BootEnv.check_be_name(be_name)
1080
147a665c552c 8394 image-update without a --be-name fails.
Rich Burridge <rich.burridge@sun.com>
parents: 1076
diff changeset
   576
                return True
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
   577
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   578
        def __cert_verify(self, log_op_end=None):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   579
                """Verify validity of certificates.  Any apx.ExpiringCertificate
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   580
                exceptions are caught here, a message is displayed, and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   581
                execution continues.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   582
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   583
                All other exceptions will be passed to the calling context.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   584
                The caller can also set log_op_end to a list of exceptions
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   585
                that should result in a call to self.log_operation_end()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   586
                before the exception is passed on.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   587
                """
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   588
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   589
                if log_op_end == None:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   590
                        log_op_end = []
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   591
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   592
                # we always explicitly handle apx.ExpiringCertificate
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   593
                assert apx.ExpiringCertificate not in log_op_end
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   594
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   595
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   596
                        self._img.check_cert_validity()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   597
                except apx.ExpiringCertificate, e:
3010
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
   598
                        logger.warning(e)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   599
                except:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   600
                        exc_type, exc_value, exc_traceback = sys.exc_info()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   601
                        if exc_type in log_op_end:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   602
                                self.log_operation_end(error=exc_value)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   603
                        raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   604
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
   605
        def __refresh_publishers(self):
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   606
                """Refresh publisher metadata; this should only be used by
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   607
                functions in this module for implicit refresh cases."""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   608
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   609
                #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   610
                # Verify validity of certificates before possibly
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   611
                # attempting network operations.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   612
                #
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   613
                self.__cert_verify()
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   614
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   615
                        self._img.refresh_publishers(immediate=True,
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   616
                            progtrack=self.__progresstracker)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   617
                except apx.ImageFormatUpdateNeeded:
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   618
                        # If image format update is needed to perform refresh,
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   619
                        # continue on and allow failure to happen later since
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   620
                        # an implicit refresh failing for this reason isn't
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   621
                        # important.  (This allows planning installs and updates
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   622
                        # before the format of an image is updated.  Yes, this
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   623
                        # means that if the refresh was needed to do that, then
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   624
                        # this isn't useful, but this is as good as it gets.)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   625
                        logger.warning(_("Skipping publisher metadata refresh;"
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
   626
                            "image rooted at %s must have its format updated "
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   627
                            "before a refresh can occur.") % self._img.root)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   628
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   629
        def _acquire_activity_lock(self):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   630
                """Private helper method to aqcuire activity lock."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   631
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   632
                rc = self._activity_lock.acquire(
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   633
                    blocking=self.__blocking_locks)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   634
                if not rc:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   635
                        raise apx.ImageLockedError()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
   636
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   637
        def __plan_common_start(self, operation, noexecute, backup_be,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   638
            backup_be_name, new_be, be_name, be_activate):
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
   639
                """Start planning an operation:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   640
                    Acquire locks.
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   641
                    Log the start of the operation.
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   642
                    Check be_name."""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   643
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   644
                self._acquire_activity_lock()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   645
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   646
                        self._enable_cancel()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   647
                        if self.__plan_type is not None:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
   648
                                raise apx.PlanExistsException(
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   649
                                    self.__plan_type)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   650
                        self._img.lock(allow_unprivileged=noexecute)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   651
                except:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   652
                        self._cancel_cleanup_exception()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   653
                        self._activity_lock.release()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   654
                        raise
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   655
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   656
                assert self._activity_lock._is_owned()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   657
                self.log_operation_start(operation)
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   658
                self.__backup_be = backup_be
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   659
                self.__backup_be_name = backup_be_name
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   660
                self.__new_be = new_be
2319
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
   661
                self.__be_activate = be_activate
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   662
                self.__be_name = be_name
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   663
                for val in (self.__be_name, self.__backup_be_name):
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   664
                        if val is not None:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   665
                                self.check_be_name(val)
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   666
                                if not self._img.is_liveroot():
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   667
                                        raise apx.BENameGivenOnDeadBE(val)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   668
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   669
        def __plan_common_finish(self):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   670
                """Finish planning an operation."""
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   671
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   672
                assert self._activity_lock._is_owned()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   673
                self._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   674
                self._img.unlock()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   675
                try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   676
                        if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   677
                                self._img.transport.stats.dump()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   678
                except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   679
                        # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   680
                        # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
   681
                        pass
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   682
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
   683
                self._activity_lock.release()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
   684
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   685
        def __set_be_creation(self):
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   686
                """Figure out whether or not we'd create a new or backup boot
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   687
                environment given inputs and plan.  Toss cookies if we need a
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   688
                new be and can't have one."""
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   689
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   690
                if not self._img.is_liveroot():
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   691
                        self.__backup_be = False
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   692
                        self.__new_be = False
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   693
                        return
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   694
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   695
                if self.__new_be is None:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   696
                        # If image policy requires a new BE or the plan requires
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   697
                        # it, then create a new BE.
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   698
                        self.__new_be = (self._img.cfg.get_policy_str(
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   699
                            imgcfg.BE_POLICY) == "always-new" or
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   700
                            self._img.imageplan.reboot_needed())
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   701
                elif self.__new_be is False and \
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   702
                    self._img.imageplan.reboot_needed():
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   703
                        raise apx.ImageUpdateOnLiveImageException()
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   704
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   705
                if not self.__new_be and self.__backup_be is None:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   706
                        # Create a backup be if allowed by policy (note that the
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   707
                        # 'default' policy is currently an alias for
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   708
                        # 'create-backup') ...
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   709
                        allow_backup = self._img.cfg.get_policy_str(
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   710
                            imgcfg.BE_POLICY) in ("default",
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   711
                                "create-backup")
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   712
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   713
                        self.__backup_be = False
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   714
                        if allow_backup:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   715
                                # ...when packages are being
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   716
                                # updated...
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   717
                                for src, dest in self._img.imageplan.plan_desc:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   718
                                        if src and dest:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   719
                                                self.__backup_be = True
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   720
                                                break
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   721
                        if allow_backup and not self.__backup_be:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   722
                                # ...or if new packages that have
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   723
                                # reboot-needed=true are being
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   724
                                # installed.
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   725
                                self.__backup_be = \
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
   726
                                    self._img.imageplan.reboot_advised()
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
   727
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   728
        def abort(self, result=RESULT_FAILED_UNKNOWN):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   729
                """Indicate that execution was unexpectedly aborted and log
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   730
                operation failure if possible."""
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   731
                try:
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   732
                        # This can raise if, for example, we're aborting
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   733
                        # because we have a PipeError and we can no longer
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   734
                        # write.  So supress problems here.
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   735
                        if self.__progresstracker:
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   736
                                self.__progresstracker.flush()
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   737
                except:
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   738
                        pass
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
   739
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   740
                self._img.history.abort(result)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
   741
2228
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   742
        def avoid_pkgs(self, fmri_strings, unavoid=False):
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   743
                """Avoid/Unavoid one or more packages.  It is an error to
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   744
                avoid an installed package, or unavoid one that would
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   745
                be installed."""
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   746
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   747
                self._acquire_activity_lock()
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   748
                try:
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   749
                        if not unavoid:
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   750
                                self._img.avoid_pkgs(fmri_strings,
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   751
                                    progtrack=self.__progresstracker,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   752
                                    check_cancel=self.__check_cancel)
2228
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   753
                        else:
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   754
                                self._img.unavoid_pkgs(fmri_strings,
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   755
                                    progtrack=self.__progresstracker,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
   756
                                    check_cancel=self.__check_cancel)
2228
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   757
                finally:
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   758
                        self._activity_lock.release()
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   759
                return True
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   760
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   761
        def gen_available_mediators(self):
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   762
                """A generator function that yields tuples of the form (mediator,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   763
                mediations), where mediator is the name of the provided mediation
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   764
                and mediations is a list of dictionaries of possible mediations
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   765
                to set, provided by installed packages, of the form:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   766
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   767
                   {
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   768
                       mediator-name: {
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   769
                           "version": mediator-version-string,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   770
                           "version-source": (site|vendor|system|local),
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   771
                           "implementation": mediator-implementation-string,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   772
                           "implementation-source": (site|vendor|system|local),
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   773
                       }
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   774
                   }
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   775
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   776
                  'version' is an optional string that specifies the version
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   777
                   (expressed as a dot-separated sequence of non-negative
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   778
                   integers) of the mediator for use.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   779
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   780
                   'version-source' is a string describing how the version
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   781
                   component of the mediation will be evaluated during
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   782
                   mediation. (The priority.)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   783
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   784
                   'implementation' is an optional string that specifies the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   785
                   implementation of the mediator for use in addition to or
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   786
                   instead of 'version'.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   787
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   788
                   'implementation-source' is a string describing how the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   789
                   implementation component of the mediation will be evaluated
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   790
                   during mediation.  (The priority.)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   791
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   792
                The list of possible mediations returned for each mediator is
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   793
                ordered by source in the sequence 'site', 'vendor', 'system',
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   794
                and then by version and implementation.  It does not include
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   795
                mediations that exist only in the image configuration.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   796
                """
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   797
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   798
                ret = collections.defaultdict(set)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   799
                excludes = self._img.list_excludes()
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   800
                for f in self._img.gen_installed_pkgs():
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   801
                        mfst = self._img.get_manifest(f)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   802
                        for m, mediations in mfst.gen_mediators(
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   803
                            excludes=excludes):
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   804
                                ret[m].update(mediations)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   805
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   806
                for mediator in sorted(ret):
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   807
                        for med_priority, med_ver, med_impl in sorted(
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   808
                            ret[mediator], cmp=med.cmp_mediations):
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   809
                                val = {}
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   810
                                if med_ver:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   811
                                        # Don't expose internal Version object
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   812
                                        # to callers.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   813
                                        val["version"] = \
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   814
                                            med_ver.get_short_version()
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   815
                                if med_impl:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   816
                                        val["implementation"] = med_impl
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   817
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   818
                                ret_priority = med_priority
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   819
                                if not ret_priority:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   820
                                        # For consistency with the configured
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   821
                                        # case, list source as this.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   822
                                        ret_priority = "system"
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   823
                                # Always set both to be consistent
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   824
                                # with @mediators.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   825
                                val["version-source"] = ret_priority
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   826
                                val["implementation-source"] = \
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   827
                                    ret_priority
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   828
                                yield mediator, val
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
   829
2228
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   830
        def get_avoid_list(self):
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   831
                """Return list of tuples of (pkg stem, pkgs w/ group
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   832
                dependencies on this) """
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   833
                return [a for a in self._img.get_avoid_dict().iteritems()]
5319ee47781d 2774 new depend action behavior: follow if possible
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2224
diff changeset
   834
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   835
        def gen_facets(self, facet_list, patterns=misc.EmptyI):
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   836
                """A generator function that produces tuples of the form:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   837
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   838
                    (
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   839
                        name,    - (string) facet name (e.g. facet.doc)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   840
                        value    - (boolean) current facet value
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   841
                        src      - (string) source for the value
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   842
                        masked   - (boolean) is the facet maksed by another
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   843
                    )
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   844
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   845
                Results are always sorted by facet name.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   846
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   847
                'facet_list' is one of the following constant values indicating
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   848
                which facets should be returned based on how they were set:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   849
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   850
                        FACET_ALL
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   851
                                Return all facets set in the image and all
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   852
                                facets listed in installed packages.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   853
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   854
                        FACET_IMAGE
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   855
                                Return only the facets set in the image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   856
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   857
                        FACET_INSTALLED
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   858
                                Return only the facets listed in installed
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   859
                                packages.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   860
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   861
                'patterns' is an optional list of facet wildcard strings to
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   862
                filter results by."""
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   863
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   864
                facets = self._img.cfg.facets
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   865
                if facet_list != self.FACET_INSTALLED:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   866
                        # Include all facets set in image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   867
                        fimg = set(facets.keys())
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   868
                else:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   869
                        # Don't include any set only in image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   870
                        fimg = set()
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   871
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   872
                # Get all facets found in packages and determine state.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   873
                fpkg = set()
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   874
                excludes = self._img.list_excludes()
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   875
                if facet_list != self.FACET_IMAGE:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   876
                        for f in self._img.gen_installed_pkgs():
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   877
                                # The manifest must be loaded without
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   878
                                # pre-applying excludes so that gen_facets() can
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   879
                                # choose how to filter the actions.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   880
                                mfst = self._img.get_manifest(f,
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   881
                                    ignore_excludes=True)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   882
                                for facet in mfst.gen_facets(excludes=excludes):
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   883
                                        # Use Facets object to determine
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   884
                                        # effective facet state.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   885
                                        fpkg.add(facet)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   886
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   887
                # Generate the results.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   888
                for name in misc.yield_matching("facet.", sorted(fimg | fpkg),
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   889
                    patterns):
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   890
                        # check if the facet is explicitly set.
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   891
                        if name not in facets:
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   892
                                # The image's Facets dictionary will return
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   893
                                # the effective value for any facets not
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   894
                                # explicitly set in the image (wildcards or
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   895
                                # implicit). _match_src() will tell us how
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   896
                                # that effective value was determined (via a
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   897
                                # local or inherited wildcard facet, or via a
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   898
                                # system default).
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   899
                                src = facets._match_src(name)
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   900
                                yield (name, facets[name], src, False)
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   901
                                continue
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   902
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   903
                        # This is an explicitly set facet.
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   904
                        for value, src, masked in facets._src_values(name):
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
   905
                                yield (name, value, src, masked)
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   906
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   907
        def gen_variants(self, variant_list, patterns=misc.EmptyI):
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   908
                """A generator function that produces tuples of the form:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   909
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   910
                    (
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   911
                        name,    - (string) variant name (e.g. variant.arch)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   912
                        value    - (string) current variant value,
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   913
                        possible - (list) list of possible variant values based
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   914
                                   on installed packages; empty unless using
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   915
                                   *_POSSIBLE variant_list.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   916
                    )
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   917
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   918
                Results are always sorted by variant name.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   919
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   920
                'variant_list' is one of the following constant values indicating
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   921
                which variants should be returned based on how they were set:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   922
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   923
                        VARIANT_ALL
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   924
                                Return all variants set in the image and all
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   925
                                variants listed in installed packages.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   926
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   927
                        VARIANT_ALL_POSSIBLE
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   928
                                Return possible variant values (those found in
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   929
                                any installed package) for all variants set in
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   930
                                the image and all variants listed in installed
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   931
                                packages.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   932
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   933
                        VARIANT_IMAGE
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   934
                                Return only the variants set in the image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   935
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   936
                        VARIANT_IMAGE_POSSIBLE
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   937
                                Return possible variant values (those found in
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   938
                                any installed package) for only the variants set
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   939
                                in the image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   940
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   941
                        VARIANT_INSTALLED
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   942
                                Return only the variants listed in installed
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   943
                                packages.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   944
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   945
                        VARIANT_INSTALLED_POSSIBLE
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   946
                                Return possible variant values (those found in
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   947
                                any installed package) for only the variants
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   948
                                listed in installed packages.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   949
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   950
                'patterns' is an optional list of variant wildcard strings to
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   951
                filter results by."""
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   952
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   953
                variants = self._img.cfg.variants
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   954
                if variant_list != self.VARIANT_INSTALLED and \
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   955
                    variant_list != self.VARIANT_INSTALLED_POSSIBLE:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   956
                        # Include all variants set in image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   957
                        vimg = set(variants.keys())
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   958
                else:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   959
                        # Don't include any set only in image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   960
                        vimg = set()
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   961
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   962
                # Get all variants found in packages and determine state.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   963
                vpkg = {}
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   964
                excludes = self._img.list_excludes()
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   965
                vposs = collections.defaultdict(set)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   966
                if variant_list != self.VARIANT_IMAGE:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   967
                        # Only incur the overhead of reading through all
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   968
                        # installed packages if not just listing variants set in
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   969
                        # image or listing possible values for them.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   970
                        for f in self._img.gen_installed_pkgs():
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   971
                                # The manifest must be loaded without
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   972
                                # pre-applying excludes so that gen_variants()
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   973
                                # can choose how to filter the actions.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   974
                                mfst = self._img.get_manifest(f,
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   975
                                    ignore_excludes=True)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   976
                                for variant, vals in mfst.gen_variants(
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   977
                                    excludes=excludes):
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   978
                                        # Unlike facets, Variants class doesn't
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   979
                                        # handle implicitly set values.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   980
                                        if variant[:14] == "variant.debug.":
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   981
                                                # Debug variants are implicitly
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   982
                                                # false and are not required
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   983
                                                # to be set explicitly in the
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   984
                                                # image.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   985
                                                vpkg[variant] = variants.get(
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   986
                                                    variant, "false")
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   987
                                        elif variant not in vimg:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   988
                                                # Although rare, packages with
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   989
                                                # unknown variants (those not
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   990
                                                # set in the image) can be
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   991
                                                # installed as long as content
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   992
                                                # does not conflict.  For those
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   993
                                                # variants, return None.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   994
                                                vpkg[variant] = \
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   995
                                                    variants.get(variant)
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   996
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   997
                                        if (variant_list == \
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   998
                                            self.VARIANT_ALL_POSSIBLE or
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
   999
                                            variant_list == \
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1000
                                                self.VARIANT_IMAGE_POSSIBLE or
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1001
                                            variant_list == \
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1002
                                                self.VARIANT_INSTALLED_POSSIBLE):
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1003
                                                # Build possible list of variant
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1004
                                                # values.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1005
                                                vposs[variant].update(set(vals))
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1006
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1007
                # Generate the results.
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1008
                for name in misc.yield_matching("variant.",
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1009
                    sorted(vimg | set(vpkg.keys())), patterns):
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1010
                        try:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1011
                                yield (name, vpkg[name], sorted(vposs[name]))
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1012
                        except KeyError:
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1013
                                yield (name, variants[name],
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1014
                                    sorted(vposs[name]))
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  1015
2452
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1016
        def freeze_pkgs(self, fmri_strings, dry_run=False, comment=None,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1017
            unfreeze=False):
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1018
                """Freeze/Unfreeze one or more packages."""
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1019
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1020
                # Comment is only a valid parameter if a freeze is happening.
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1021
                assert not comment or not unfreeze
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1022
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1023
                self._acquire_activity_lock()
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1024
                try:
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1025
                        if unfreeze:
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1026
                                return self._img.unfreeze_pkgs(fmri_strings,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1027
                                    progtrack=self.__progresstracker,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1028
                                    check_cancel=self.__check_cancel,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1029
                                    dry_run=dry_run)
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1030
                        else:
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1031
                                return self._img.freeze_pkgs(fmri_strings,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1032
                                    progtrack=self.__progresstracker,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1033
                                    check_cancel=self.__check_cancel,
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1034
                                    dry_run=dry_run, comment=comment)
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1035
                finally:
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1036
                        self._activity_lock.release()
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1037
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1038
        def get_frozen_list(self):
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1039
                """Return list of tuples of (pkg fmri, reason package was
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1040
                frozen, timestamp when package was frozen)."""
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1041
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1042
                return self._img.get_frozen_list()
3be84ba08176 18441 pkg needs a freeze mechanism
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2446
diff changeset
  1043
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1044
        def __plan_common_exception(self, log_op_end_all=False):
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1045
                """Deal with exceptions that can occur while planning an
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1046
                operation.  Any exceptions generated here are passed
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1047
                onto the calling context.  By default all exceptions
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1048
                will result in a call to self.log_operation_end() before
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1049
                they are passed onto the calling context."""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1050
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1051
                exc_type, exc_value, exc_traceback = sys.exc_info()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1052
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1053
                if exc_type == apx.PlanCreationException:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1054
                        self.__set_history_PlanCreationException(exc_value)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1055
                elif exc_type == apx.CanceledException:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1056
                        self._cancel_done()
2205
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1057
                elif exc_type == apx.ConflictingActionErrors:
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1058
                        self.log_operation_end(error=str(exc_value),
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  1059
                            result=RESULT_CONFLICTING_ACTIONS)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1060
                elif exc_type in [
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1061
                    apx.IpkgOutOfDateException,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1062
                    fmri.IllegalFmri]:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1063
                        self.log_operation_end(error=exc_value)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1064
                elif log_op_end_all:
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1065
                        self.log_operation_end(error=exc_value)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1066
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1067
                if exc_type != apx.ImageLockedError:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1068
                        # Must be called before reset_unlock, and only if
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1069
                        # the exception was not a locked error.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1070
                        self._img.unlock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  1071
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1072
                try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1073
                        if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1074
                                self._img.transport.stats.dump()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1075
                except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1076
                        # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1077
                        # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1078
                        pass
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  1079
2205
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1080
                # In the case of duplicate actions, we want to save off the plan
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1081
                # description for display to the client (if they requested it),
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1082
                # as once the solver's done its job, there's interesting
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1083
                # information in the plan.  We have to save it here and restore
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1084
                # it later because __reset_unlock() torches it.
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1085
                if exc_type == apx.ConflictingActionErrors:
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1086
                        self._img.imageplan.set_be_options(self.__backup_be,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1087
                            self.__backup_be_name, self.__new_be,
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1088
                            self.__be_activate, self.__be_name)
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1089
                        plan_desc = self._img.imageplan.describe()
2205
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1090
1346
c4d21b460a66 10539 Package Manager hangs after canceling Update All
Padraig O'Briain <padraig.obriain@sun.com>
parents: 1337
diff changeset
  1091
                self.__reset_unlock()
2205
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1092
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1093
                if exc_type == apx.ConflictingActionErrors:
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1094
                        self.__plan_desc = plan_desc
53d0be594162 3822 image plans should prevent conflicting actions from being installed
Danek Duvall <danek.duvall@oracle.com>
parents: 2200
diff changeset
  1095
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1096
                self._activity_lock.release()
2819
cd5e9c001812 7140470 __plan_common_exception() calls raise with no exception in scope
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2808
diff changeset
  1097
cd5e9c001812 7140470 __plan_common_exception() calls raise with no exception in scope
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2808
diff changeset
  1098
                # re-raise the original exception. (we have to explicitly
cd5e9c001812 7140470 __plan_common_exception() calls raise with no exception in scope
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2808
diff changeset
  1099
                # restate the original exception since we may have cleared the
cd5e9c001812 7140470 __plan_common_exception() calls raise with no exception in scope
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2808
diff changeset
  1100
                # current exception scope above.)
cd5e9c001812 7140470 __plan_common_exception() calls raise with no exception in scope
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2808
diff changeset
  1101
                raise exc_type, exc_value, exc_traceback
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1102
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1103
        def solaris_image(self):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1104
                """Returns True if the current image is a solaris image, or an
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1105
                image which contains the pkg(5) packaging system."""
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1106
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1107
                # First check to see if the special package "release/name"
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1108
                # exists and contains metadata saying this is Solaris.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1109
                results = self.__get_pkg_list(self.LIST_INSTALLED,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1110
                    patterns=["release/name"], return_fmris=True)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1111
                results = [e for e in results]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1112
                if results:
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  1113
                        pfmri, summary, categories, states, attrs = results[0]
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1114
                        mfst = self._img.get_manifest(pfmri)
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1115
                        osname = mfst.get("pkg.release.osname", None)
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1116
                        if osname == "sunos":
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1117
                                return True
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1118
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1119
                # Otherwise, see if we can find package/pkg (or SUNWipkg) and
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  1120
                # system/core-os (or SUNWcs).
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  1121
                results = self.__get_pkg_list(self.LIST_INSTALLED,
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  1122
                    patterns=["/package/pkg", "SUNWipkg", "/system/core-os",
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  1123
                        "SUNWcs"])
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  1124
                installed = set(e[0][1] for e in results)
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  1125
                if ("SUNWcs" in installed or "system/core-os" in installed) and \
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  1126
                    ("SUNWipkg" in installed or "package/pkg" in installed):
1829
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1127
                        return True
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1128
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1129
                return False
e581a205ec02 14907 references to old-style package names must be purged
Danek Duvall <danek.duvall@sun.com>
parents: 1795
diff changeset
  1130
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1131
        def __ipkg_require_latest(self, noexecute):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1132
                """Raises an IpkgOutOfDateException if the current image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1133
                contains the pkg(5) packaging system and a newer version
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1134
                of the pkg(5) packaging system is installable."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1135
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1136
                if not self.solaris_image():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1137
                        return
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1138
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1139
                # Get old purpose in order to be able to restore it on return.
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1140
                p = self.__progresstracker.get_purpose()
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1141
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1142
                try:
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1143
                        #
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1144
                        # Let progress tracker know that subsequent callbacks
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1145
                        # into it will all be in service of update checking.
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1146
                        # Note that even though this might return, the
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1147
                        # finally: will still reset the purpose.
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1148
                        #
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1149
                        self.__progresstracker.set_purpose(
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1150
                            self.__progresstracker.PURPOSE_PKG_UPDATE_CHK)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1151
                        if self._img.ipkg_is_up_to_date(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1152
                            self.__check_cancel, noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1153
                            refresh_allowed=False,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1154
                            progtrack=self.__progresstracker):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1155
                                return
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1156
                except apx.ImageNotFoundException:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1157
                        # Can't do anything in this
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1158
                        # case; so proceed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1159
                        return
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1160
                finally:
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1161
                        self.__progresstracker.set_purpose(p)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1162
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1163
                raise apx.IpkgOutOfDateException()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1164
2839
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1165
        def __verify_args(self, args):
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1166
                """Verifies arguments passed into the API.
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1167
                It tests for correct data types of the input args, verifies that
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1168
                passed in FMRIs are valid, checks if repository URIs are valid
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1169
                and does some logical tests for the combination of arguments."""
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1170
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1171
                arg_types = {
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1172
                    # arg name              type                   nullable
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1173
                    "_noexecute":           (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1174
                    "_be_activate":         (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1175
                    "_new_be":              (bool,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1176
                    "_be_name":             (basestring,           True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1177
                    "_backup_be":           (bool,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1178
                    "_backup_be_name":      (basestring,           True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1179
                    "_pubcheck":            (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1180
                    "_refresh_catalogs":    (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1181
                    "_repos":               (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1182
                    "_update_index":        (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1183
                    "_li_ignore":           (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1184
                    "_li_parent_sync":      (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1185
                    "_li_md_only":          (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1186
                    "_ipkg_require_latest": (bool,                 False),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1187
                    "pkgs_inst":            (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1188
                    "pkgs_update":          (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1189
                    "pkgs_to_uninstall":    (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1190
                    "reject_list":          (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1191
                    "mediators":            (iter,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1192
                    "variants":             (dict,                 True),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1193
                    "facets":               (pkg.facet.Facets,     True)
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1194
                }
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1195
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1196
                # merge kwargs into the main arg dict
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1197
                if "kwargs" in args:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1198
                        for name, value in args["kwargs"].items():
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1199
                                args[name] = value
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1200
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1201
                # check arguments for proper type and nullability
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1202
                for a in args:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1203
                        try:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1204
                                a_type, nullable = arg_types[a]
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1205
                        except KeyError:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1206
                                # unknown argument passed, ignore
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1207
                                continue
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1208
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1209
                        assert nullable or args[a] is not None
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1210
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1211
                        if args[a] is not None and a_type == iter:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1212
                                try:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1213
                                        iter(args[a])
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1214
                                except TypeError:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1215
                                        raise AssertionError("%s is not an "
2840
2f6f88362fd1 15981296 pkg API should have basic input checking for clients other than the CLI (2)
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2839
diff changeset
  1216
                                            "iterable" % a)
2839
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1217
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1218
                        else:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1219
                                assert (args[a] is None or
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1220
                                    isinstance(args[a], a_type)), "%s is " \
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1221
                                    "type %s; expected %s" % (a, type(a),
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1222
                                    a_type)
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1223
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1224
                # check if passed FMRIs are valid
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1225
                illegals = []
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1226
                for i in ("pkgs_inst", "pkgs_update", "pkgs_to_uninstall",
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1227
                    "reject_list"):
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1228
                        try:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1229
                                fmris = args[i]
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1230
                        except KeyError:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1231
                                continue
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1232
                        if fmris is None:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1233
                                continue
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1234
                        for pat, err, pfmri, matcher in \
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1235
                            self.parse_fmri_patterns(fmris):
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1236
                                if not err:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1237
                                        continue
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1238
                                else:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1239
                                        illegals.append(fmris)
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1240
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1241
                if illegals:
2840
2f6f88362fd1 15981296 pkg API should have basic input checking for clients other than the CLI (2)
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2839
diff changeset
  1242
                        raise apx.PlanCreationException(illegal=illegals)
2839
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1243
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1244
                # some logical checks
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1245
                errors = []
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1246
                if not args["_new_be"] and args["_be_name"]:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1247
                        errors.append(apx.InvalidOptionError(
2840
2f6f88362fd1 15981296 pkg API should have basic input checking for clients other than the CLI (2)
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2839
diff changeset
  1248
                            apx.InvalidOptionError.REQUIRED, ["_be_name",
2839
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1249
                            "_new_be"]))
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1250
                if not args["_backup_be"] and args["_backup_be_name"]:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1251
                        errors.append(apx.InvalidOptionError(
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1252
                            apx.InvalidOptionError.REQUIRED, ["_backup_be_name",
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1253
                            "_backup_be"]))
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1254
                if args["_backup_be"] and args["_new_be"]:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1255
                        errors.append(apx.InvalidOptionError(
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1256
                            apx.InvalidOptionError.INCOMPAT, ["_backup_be",
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1257
                            "_new_be"]))
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1258
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1259
                if errors:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1260
                        raise apx.InvalidOptionErrors(errors)
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1261
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1262
                # check if repo URIs are valid
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1263
                try:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1264
                        repos = args["_repos"]
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1265
                except KeyError:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1266
                        return
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1267
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1268
                if not repos:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1269
                        return
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1270
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1271
                illegals = []
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1272
                for r in repos:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1273
                        valid = False
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1274
                        if type(r) == publisher.RepositoryURI:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1275
                                # RepoURI objects pass right away
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1276
                                continue
2840
2f6f88362fd1 15981296 pkg API should have basic input checking for clients other than the CLI (2)
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2839
diff changeset
  1277
2839
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1278
                        if not misc.valid_pub_url(r):
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1279
                                illegals.append(r)
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1280
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1281
                if illegals:
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1282
                        raise apx.UnsupportedRepositoryURI(illegals)
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1283
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1284
        def __plan_op(self, _op, _ad_kwargs=None,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1285
            _backup_be=None, _backup_be_name=None, _be_activate=True,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1286
            _be_name=None, _ipkg_require_latest=False, _li_ignore=None,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1287
            _li_md_only=False, _li_parent_sync=True, _new_be=False,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1288
            _noexecute=False, _pubcheck=True, _refresh_catalogs=True,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1289
            _repos=None, _update_index=True, **kwargs):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1290
                """Contructs a plan to change the package or linked image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1291
                state of an image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1292
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1293
                We can raise PermissionsException, PlanCreationException,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1294
                InventoryException, or LinkedImageException.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1295
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1296
                Arguments prefixed with '_' are primarily used within this
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1297
                function.  All other arguments must be specified via keyword
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1298
                assignment and will be passed directly on to the image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1299
                interfaces being invoked."
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1300
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1301
                '_op' is the API operation we will perform.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1302
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1303
                '_ad_kwargs' is only used dyring attach or detach and it
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1304
                is a dictionary of arguments that will be passed to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1305
                linked image attach/detach interfaces.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1306
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1307
                '_ipkg_require_latest' enables a check to verify that the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1308
                latest installable version of the pkg(5) packaging system is
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1309
                installed before we proceed with the requested operation.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1310
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1311
                For all other '_' prefixed parameters, please refer to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1312
                'gen_plan_*' functions which invoke this function for an
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1313
                explanation of their usage and effects.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1314
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1315
                This function first yields the plan description for the global
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1316
                zone, then either a series of dictionaries representing the
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1317
                parsable output from operating on the child images or a series
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1318
                of None values."""
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1319
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1320
                # sanity checks
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1321
                assert _op in api_op_values
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1322
                assert _ad_kwargs == None or \
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1323
                    _op in [API_OP_ATTACH, API_OP_DETACH]
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1324
                assert _ad_kwargs != None or \
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1325
                    _op not in [API_OP_ATTACH, API_OP_DETACH]
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1326
                assert not _li_md_only or \
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1327
                    _op in [API_OP_ATTACH, API_OP_DETACH, API_OP_SYNC]
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1328
                assert not _li_md_only or _li_parent_sync
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1329
2839
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1330
                self.__verify_args(locals())
7b0fc73bf146 15981296 pkg API should have basic input checking for clients other than the CLI
Erik Trauschke <Erik.Trauschke@oracle.com>
parents: 2832
diff changeset
  1331
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1332
                # make some perf optimizations
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1333
                if _li_md_only:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1334
                        _refresh_catalogs = _update_index = False
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1335
                if _op in [API_OP_DETACH, API_OP_SET_MEDIATOR]:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1336
                        # these operations don't change fmris and don't need
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1337
                        # to recurse, so disable a bunch of linked image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1338
                        # operations.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1339
                        _li_parent_sync = False
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1340
                        _pubcheck = False
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1341
                        _li_ignore = [] # ignore all children
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1342
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1343
                # All the image interface functions that we invoke have some
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1344
                # common arguments.  Set those up now.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1345
                args_common = {}
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1346
                args_common["op"] = _op
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1347
                args_common["progtrack"] = self.__progresstracker
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1348
                args_common["check_cancel"] = self.__check_cancel
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1349
                args_common["noexecute"] = _noexecute
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1350
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1351
                # make sure there is no overlap between the common arguments
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1352
                # supplied to all api interfaces and the arguments that the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1353
                # api arguments that caller passed to this function.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1354
                assert (set(args_common) & set(kwargs)) == set(), \
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1355
                    "%s & %s != set()" % (str(set(args_common)),
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1356
                    str(set(kwargs)))
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1357
                kwargs.update(args_common)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1358
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1359
                # Lock the current image.
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1360
                self.__plan_common_start(_op, _noexecute, _backup_be,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1361
                    _backup_be_name, _new_be, _be_name, _be_activate)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1362
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1363
                try:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1364
                        if _op == API_OP_ATTACH:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1365
                                self._img.linked.attach_parent(**_ad_kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1366
                        elif _op == API_OP_DETACH:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1367
                                self._img.linked.detach_parent(**_ad_kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1368
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1369
                        if _li_parent_sync:
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1370
                                # refresh linked image data from parent image.
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1371
                                self._img.linked.syncmd_from_parent()
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1372
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1373
                        # initialize recursion state
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1374
                        self._img.linked.api_recurse_init(
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1375
                                li_ignore=_li_ignore, repos=_repos)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1376
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1377
                        if _pubcheck:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1378
                                # check that linked image pubs are in sync
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1379
                                self.__linked_pubcheck(_op)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1380
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1381
                        if _refresh_catalogs:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1382
                                self.__refresh_publishers()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1383
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1384
                        if _ipkg_require_latest:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1385
                                # If this is an image update then make
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1386
                                # sure the latest version of the ipkg
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1387
                                # software is installed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1388
                                self.__ipkg_require_latest(_noexecute)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1389
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1390
                        self.__set_img_alt_sources(_repos)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1391
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1392
                        if _li_md_only:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1393
                                self._img.make_noop_plan(**args_common)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1394
                        elif _op in [API_OP_ATTACH, API_OP_DETACH, API_OP_SYNC]:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1395
                                self._img.make_sync_plan(**kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1396
                        elif _op in [API_OP_CHANGE_FACET,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1397
                            API_OP_CHANGE_VARIANT]:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1398
                                self._img.make_change_varcets_plan(**kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1399
                        elif _op == API_OP_INSTALL:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1400
                                self._img.make_install_plan(**kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1401
                        elif _op == API_OP_REVERT:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1402
                                self._img.make_revert_plan(**kwargs)
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1403
                        elif _op == API_OP_SET_MEDIATOR:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1404
                                self._img.make_set_mediators_plan(**kwargs)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1405
                        elif _op == API_OP_UNINSTALL:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1406
                                self._img.make_uninstall_plan(**kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1407
                        elif _op == API_OP_UPDATE:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1408
                                self._img.make_update_plan(**kwargs)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1409
                        else:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1410
                                raise RuntimeError("Unknown api op: %s" % _op)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1411
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1412
                        self.__api_op = _op
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1413
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1414
                        if self._img.imageplan.nothingtodo():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1415
                                # no package changes mean no index changes
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1416
                                _update_index = False
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1417
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1418
                        self._disable_cancel()
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1419
                        self.__set_be_creation()
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1420
                        self._img.imageplan.set_be_options(
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1421
                            self.__backup_be, self.__backup_be_name,
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1422
                            self.__new_be, self.__be_activate, self.__be_name)
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1423
                        self.__plan_desc = self._img.imageplan.describe()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1424
                        if not _noexecute:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1425
                                self.__plan_type = self.__plan_desc.plan_type
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1426
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1427
                        # Yield to our caller so they can display our plan
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1428
                        # before we recurse into child images.  Drop the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1429
                        # activity lock before yielding because otherwise the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1430
                        # caller can't do things like set the displayed
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1431
                        # license state for pkg plans).
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1432
                        self._activity_lock.release()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1433
                        yield self.__plan_desc
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1434
                        self._activity_lock.acquire()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1435
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1436
                        # plan operation in child images.  This currently yields
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1437
                        # either a dictionary representing the parsable output
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1438
                        # from the child image operation, or None.  Eventually
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1439
                        # these will yield plan descriptions objects instead.
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1440
                        for p_dict in self._img.linked.api_recurse_plan(
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1441
                            api_kwargs=kwargs,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1442
                            refresh_catalogs=_refresh_catalogs,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1443
                            update_index=_update_index,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1444
                            progtrack=self.__progresstracker):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1445
                                yield p_dict
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1446
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1447
                        self.__planned_children = True
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1448
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1449
                except:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1450
                        if _op in [
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1451
                            API_OP_UPDATE,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1452
                            API_OP_INSTALL,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1453
                            API_OP_REVERT,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1454
                            API_OP_SYNC]:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1455
                                self.__plan_common_exception(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1456
                                    log_op_end_all=True)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1457
                        else:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1458
                                self.__plan_common_exception()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1459
                        # NOTREACHED
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1460
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1461
                stuff_to_do = not self.planned_nothingtodo()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1462
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1463
                if not stuff_to_do or _noexecute:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1464
                        self.log_operation_end(
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  1465
                            result=RESULT_NOTHING_TO_DO)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1466
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1467
                self._img.imageplan.update_index = _update_index
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1468
                self.__plan_common_finish()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1469
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1470
                if DebugValues["plandesc_validate"]:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1471
                        # save, load, and get a new json copy of the plan,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1472
                        # then compare that new copy against our current one.
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1473
                        # this regressions tests the plan save/load code.
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1474
                        pd_json1 = self.__plan_desc.getstate(self.__plan_desc,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1475
                            reset_volatiles=True)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1476
                        fobj = tempfile.TemporaryFile()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1477
                        json.dump(pd_json1, fobj, encoding="utf-8")
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1478
                        pd_new = plandesc.PlanDescription(_op)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1479
                        pd_new._load(fobj)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1480
                        pd_json2 = pd_new.getstate(pd_new, reset_volatiles=True)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1481
                        del fobj, pd_new
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1482
                        pkg.misc.json_diff("PlanDescription", \
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1483
                            pd_json1, pd_json2, pd_json1, pd_json2)
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1484
                        del pd_json1, pd_json2
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1485
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1486
        @_LockedCancelable()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1487
        def load_plan(self, plan, prepared=False):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1488
                """Load a previously generated PlanDescription."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1489
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1490
                # Prevent loading a plan if one has been already.
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1491
                if self.__plan_type is not None:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1492
                        raise apx.PlanExistsException(self.__plan_type)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1493
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1494
                # grab image lock.  we don't worry about dropping the image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1495
                # lock since __activity_lock will drop it for us us after we
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1496
                # return (or if we generate an exception).
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1497
                self._img.lock()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1498
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1499
                # load the plan
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1500
                self.__plan_desc = plan
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1501
                self.__plan_type = plan.plan_type
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1502
                self.__planned_children = True
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1503
                self.__prepared = prepared
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1504
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1505
                # load BE related plan settings
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1506
                self.__new_be = plan.new_be
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1507
                self.__be_activate = plan.activate_be
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1508
                self.__be_name = plan.be_name
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1509
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1510
                # sanity check: verify the BE name
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1511
                if self.__be_name is not None:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1512
                        self.check_be_name(self.__be_name)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1513
                        if not self._img.is_liveroot():
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1514
                                raise apx.BENameGivenOnDeadBE(self.__be_name)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1515
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1516
                # sanity check: verify that all the fmris in the plan are in
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1517
                # the known catalog
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1518
                pkg_cat = self._img.get_catalog(self._img.IMG_CATALOG_KNOWN)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1519
                for pp in plan.pkg_plans:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1520
                        if pp.destination_fmri:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1521
                                assert pkg_cat.get_entry(pp.destination_fmri), \
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1522
                                     "fmri part of plan, but currently " \
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1523
                                     "unknown: %s" % pp.destination_fmri
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1524
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1525
                # allocate an image plan based on the supplied plan
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1526
                self._img.imageplan = imageplan.ImagePlan(self._img, plan._op,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1527
                    self.__progresstracker, check_cancel=self.__check_cancel,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1528
                    pd=plan)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1529
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1530
                if prepared:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1531
                        self._img.imageplan.skip_preexecute()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1532
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1533
                # create a history entry
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1534
                self.log_operation_start(plan.plan_type)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1535
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1536
        def __linked_pubcheck(self, api_op=None):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1537
                """Private interface to perform publisher check on this image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1538
                and its children."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1539
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1540
                if api_op in [API_OP_DETACH, API_OP_SET_MEDIATOR]:
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1541
                        # we don't need to do a pubcheck for detach or
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1542
                        # changing mediators
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1543
                        return
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1544
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1545
                # check the current image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1546
                self._img.linked.pubcheck()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1547
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1548
                # check child images
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  1549
                self._img.linked.api_recurse_pubcheck(self.__progresstracker)
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1550
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1551
        @_LockedCancelable()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1552
        def linked_publisher_check(self):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1553
                """If we're a child image, verify that the parent image's
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1554
                publisher configuration is a subset of the child image's
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1555
                publisher configuration.  If we have any children, recurse
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1556
                into them and perform a publisher check."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1557
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1558
                # grab image lock.  we don't worry about dropping the image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1559
                # lock since __activity_lock will drop it for us us after we
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1560
                # return (or if we generate an exception).
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1561
                self._img.lock(allow_unprivileged=True)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1562
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1563
                # get ready to recurse
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1564
                self._img.linked.api_recurse_init()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1565
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1566
                # check that linked image pubs are in sync
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1567
                self.__linked_pubcheck()
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1568
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1569
        def planned_nothingtodo(self, li_ignore_all=False):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1570
                """Once an operation has been planned check if there is
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1571
                something todo.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1572
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1573
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1574
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1575
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1576
                'li_ignore_all' indicates if we should only report on work
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1577
                todo in the parent image.  (i.e., if an operation was planned
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1578
                and that operation only involves changes to children, and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1579
                li_ignore_all is true, then we'll report that there's nothing
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1580
                todo."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1581
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1582
                if not self._img.imageplan:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1583
                        # if theres no plan there nothing to do
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1584
                        return True
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1585
                if not self._img.imageplan.nothingtodo():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1586
                        return False
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1587
                if not self._img.linked.nothingtodo():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1588
                        return False
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1589
                if not li_ignore_all:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1590
                        assert self.__planned_children
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1591
                        if not self._img.linked.recurse_nothingtodo():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1592
                                return False
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1593
                return True
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1594
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1595
        def plan_update(self, pkg_list, refresh_catalogs=True,
2410
60b600d406df 18489 skip generating parent deps if we're running a build with parent deps
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2407
diff changeset
  1596
            reject_list=misc.EmptyI, noexecute=False, update_index=True,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1597
            be_name=None, new_be=False, repos=None, be_activate=True):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1598
                """DEPRECATED.  use gen_plan_update()."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1599
                for pd in self.gen_plan_update(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1600
                    pkgs_update=pkg_list, refresh_catalogs=refresh_catalogs,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1601
                    reject_list=reject_list, noexecute=noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1602
                    update_index=update_index, be_name=be_name, new_be=new_be,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1603
                    repos=repos, be_activate=be_activate):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1604
                        continue
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1605
                return not self.planned_nothingtodo()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1606
2092
0ef66bf272d3 16852 pkg should look at its image for certs if active image lacks certs
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2089
diff changeset
  1607
        def plan_update_all(self, refresh_catalogs=True,
2410
60b600d406df 18489 skip generating parent deps if we're running a build with parent deps
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2407
diff changeset
  1608
            reject_list=misc.EmptyI, noexecute=False, force=False,
2319
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
  1609
            update_index=True, be_name=None, new_be=True, repos=None,
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
  1610
            be_activate=True):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1611
                """DEPRECATED.  use gen_plan_update()."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1612
                for pd in self.gen_plan_update(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1613
                    refresh_catalogs=refresh_catalogs, reject_list=reject_list,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1614
                    noexecute=noexecute, force=force,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1615
                    update_index=update_index, be_name=be_name, new_be=new_be,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1616
                    repos=repos, be_activate=be_activate):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1617
                        continue
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1618
                return (not self.planned_nothingtodo(), self.solaris_image())
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1619
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1620
        def gen_plan_update(self, pkgs_update=None, backup_be=None,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1621
            backup_be_name=None, be_activate=True, be_name=None,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1622
            force=False, li_ignore=None, li_parent_sync=True, new_be=True,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1623
            noexecute=False, pubcheck=True, refresh_catalogs=True,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1624
            reject_list=misc.EmptyI, repos=None, update_index=True):
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1625
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1626
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1627
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1628
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1629
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1630
                If pkgs_update is not set, constructs a plan to update all
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1631
                packages on the system to the latest known versions.  Once an
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1632
                operation has been planned, it may be executed by first
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1633
                calling prepare(), and then execute_plan().  After execution
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1634
                of a plan, or to abandon a plan, reset() should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1635
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1636
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1637
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1638
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1639
                If 'pkgs_update' is set, constructs a plan to update the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1640
                packages provided in pkgs_update.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1641
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1642
                Once an operation has been planned, it may be executed by
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1643
                first calling prepare(), and then execute_plan().
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  1644
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  1645
                'force' indicates whether update should skip the package
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  1646
                system up to date check.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  1647
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1648
                'pubcheck' indicates that we should skip the child image
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1649
                publisher check before creating a plan for this image.  only
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1650
                pkg.1 should use this parameter, other callers should never
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1651
                specify it.
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1652
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1653
                For all other parameters, refer to the 'gen_plan_install'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1654
                function for an explanation of their usage and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1655
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1656
                if pkgs_update or force:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1657
                        ipkg_require_latest = False
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1658
                else:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1659
                        ipkg_require_latest = True
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1660
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1661
                op = API_OP_UPDATE
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1662
                return self.__plan_op(op,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1663
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1664
                    _be_activate=be_activate, _be_name=be_name,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1665
                    _ipkg_require_latest=ipkg_require_latest,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1666
                    _li_ignore=li_ignore, _li_parent_sync=li_parent_sync,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1667
                    _new_be=new_be, _noexecute=noexecute, _pubcheck=pubcheck,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1668
                    _refresh_catalogs=refresh_catalogs, _repos=repos,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1669
                    _update_index=update_index, pkgs_update=pkgs_update,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1670
                    reject_list=reject_list)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1671
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1672
        def plan_install(self, pkg_list, refresh_catalogs=True,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1673
            noexecute=False, update_index=True, be_name=None,
2410
60b600d406df 18489 skip generating parent deps if we're running a build with parent deps
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2407
diff changeset
  1674
            reject_list=misc.EmptyI, new_be=False, repos=None,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1675
            be_activate=True):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1676
                """DEPRECATED.  use gen_plan_install()."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1677
                for pd in self.gen_plan_install(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1678
                     pkgs_inst=pkg_list, refresh_catalogs=refresh_catalogs,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1679
                     noexecute=noexecute, update_index=update_index,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1680
                     be_name=be_name, reject_list=reject_list, new_be=new_be,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1681
                     repos=repos, be_activate=be_activate):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1682
                        continue
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1683
                return not self.planned_nothingtodo()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1684
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1685
        def gen_plan_install(self, pkgs_inst, backup_be=None,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1686
            backup_be_name=None, be_activate=True, be_name=None, li_ignore=None,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1687
            li_parent_sync=True, new_be=False, noexecute=False,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1688
            refresh_catalogs=True, reject_list=misc.EmptyI, repos=None,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1689
            update_index=True):
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1690
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1691
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1692
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1693
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1694
                Constructs a plan to install the packages provided in
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1695
                pkgs_inst.  Once an operation has been planned, it may be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1696
                executed by first calling prepare(), and then execute_plan().
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1697
                After execution of a plan, or to abandon a plan, reset()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1698
                should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1699
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1700
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1701
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1702
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1703
                'pkgs_inst' is a list of packages to install.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1704
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1705
                'backup_be' indicates whether a backup boot environment should
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1706
                be created before the operation is executed.  If True, a backup
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1707
                boot environment will be created.  If False, a backup boot
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1708
                environment will not be created. If None and a new boot
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1709
                environment is not created, and packages are being updated or
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1710
                are being installed and tagged with reboot-needed, a backup
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1711
                boot environment will be created.
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1712
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1713
                'backup_be_name' is a string to use as the name of any backup
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1714
                boot environment created during the operation.
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1715
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1716
                'be_name' is a string to use as the name of any new boot
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1717
                environment created during the operation.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1718
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1719
                'li_ignore' is either None or a list.  If it's None (the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1720
                default), the planning operation will attempt to keep all
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1721
                linked children in sync.  If it's an empty list the planning
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1722
                operation will ignore all children.  If this is a list of
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1723
                linked image children names, those children will be ignored
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1724
                during the planning operation.  If a child is ignored during
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1725
                the planning phase it will also be skipped during the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1726
                preparation and execution phases.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1727
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1728
                'li_parent_sync' if the current image is a child image, this
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1729
                flag controls whether the linked image parent metadata will be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1730
                automatically refreshed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1731
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1732
                'new_be' indicates whether a new boot environment should be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1733
                created during the operation.  If True, a new boot environment
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1734
                will be created.  If False, and a new boot environment is
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1735
                needed, an ImageUpdateOnLiveImageException will be raised.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1736
                If None, a new boot environment will be created only if needed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1737
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1738
                'noexecute' determines whether the resulting plan can be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1739
                executed and whether history will be recorded after
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1740
                planning is finished.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1741
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1742
                'refresh_catalogs' controls whether the catalogs will
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1743
                automatically be refreshed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1744
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1745
                'reject_list' is a list of patterns not to be permitted
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1746
                in solution; installed packages matching these patterns
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1747
                are removed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1748
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1749
                'repos' is a list of URI strings or RepositoryURI objects that
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1750
                represent the locations of additional sources of package data to
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1751
                use during the planned operation.  All API functions called
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1752
                while a plan is still active will use this package data.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1753
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1754
                'be_activate' is an optional boolean indicating whether any
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1755
                new boot environment created for the operation should be set
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1756
                as the active one on next boot if the operation is successful.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1757
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1758
                'update_index' determines whether client search indexes
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1759
                will be updated after operation completion during plan
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1760
                execution."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1761
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1762
                # certain parameters must be specified
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1763
                assert pkgs_inst and type(pkgs_inst) == list
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1764
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1765
                op = API_OP_INSTALL
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1766
                return self.__plan_op(op,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1767
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1768
                    _be_activate=be_activate, _be_name=be_name,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1769
                    _li_ignore=li_ignore, _li_parent_sync=li_parent_sync,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1770
                    _new_be=new_be, _noexecute=noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1771
                    _refresh_catalogs=refresh_catalogs, _repos=repos,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1772
                    _update_index=update_index, pkgs_inst=pkgs_inst,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1773
                    reject_list=reject_list)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1774
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1775
        def gen_plan_sync(self, backup_be=None, backup_be_name=None,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1776
            be_activate=True, be_name=None, li_ignore=None, li_md_only=False,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1777
            li_parent_sync=True, li_pkg_updates=True, new_be=False,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1778
            noexecute=False, pubcheck=True, refresh_catalogs=True,
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1779
            reject_list=misc.EmptyI, repos=None, update_index=True):
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1780
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1781
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1782
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1783
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1784
                Constructs a plan to sync the current image with its
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1785
                linked image constraints.  Once an operation has been planned,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1786
                it may be executed by first calling prepare(), and then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1787
                execute_plan().  After execution of a plan, or to abandon a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1788
                plan, reset() should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1789
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1790
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1791
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1792
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1793
                'li_md_only' don't actually modify any packages in the current
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1794
                images, only sync the linked image metadata from the parent
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1795
                image.  If this options is True, 'li_parent_sync' must also be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1796
                True.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1797
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1798
                'li_pkg_updates' when planning a sync operation, allow updates
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1799
                to packages other than the constraints package.  If this
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1800
                option is False, planning a sync will fail if any packages
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1801
                (other than the constraints package) need updating to bring
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1802
                the image in sync with its parent.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1803
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1804
                For all other parameters, refer to 'gen_plan_install' and
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1805
                'gen_plan_update' for an explanation of their usage and
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1806
                effects."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1807
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1808
                # we should only be invoked on a child image.
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1809
                if not self.ischild():
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1810
                        raise apx.LinkedImageException(
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1811
                            self_not_child=self._img_path)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1812
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1813
                op = API_OP_SYNC
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1814
                return self.__plan_op(op,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1815
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1816
                    _be_activate=be_activate, _be_name=be_name,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1817
                    _li_ignore=li_ignore, _li_md_only=li_md_only,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1818
                    _li_parent_sync=li_parent_sync, _new_be=new_be,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1819
                    _noexecute=noexecute, _pubcheck=pubcheck,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1820
                    _refresh_catalogs=refresh_catalogs,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1821
                    _repos=repos,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1822
                    _update_index=update_index,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1823
                    li_pkg_updates=li_pkg_updates, reject_list=reject_list)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1824
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1825
        def gen_plan_attach(self, lin, li_path, allow_relink=False,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1826
            backup_be=None, backup_be_name=None, be_activate=True, be_name=None,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1827
            force=False, li_ignore=None, li_md_only=False, li_pkg_updates=True,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1828
            li_props=None, new_be=False, noexecute=False, refresh_catalogs=True,
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1829
            reject_list=misc.EmptyI, repos=None, update_index=True):
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1830
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1831
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1832
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1833
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1834
                Attach a parent image and sync the packages in the current
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1835
                image with the new parent.  Once an operation has been
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1836
                planned, it may be executed by first calling prepare(), and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1837
                then execute_plan().  After execution of a plan, or to abandon
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1838
                a plan, reset() should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1839
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1840
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1841
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1842
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1843
                'lin' a LinkedImageName object that is a name for the current
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1844
                image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1845
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1846
                'li_path' a path to the parent image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1847
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1848
                'allow_relink' allows re-linking of an image that is already a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1849
                linked image child.  If this option is True we'll overwrite
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1850
                all existing linked image metadata.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1851
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1852
                'li_props' optional linked image properties to apply to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1853
                child image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1854
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1855
                For all other parameters, refer to the 'gen_plan_install' and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1856
                'gen_plan_sync' functions for an explanation of their usage
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1857
                and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1858
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1859
                if li_props == None:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1860
                        li_props = dict()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1861
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1862
                op = API_OP_ATTACH
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1863
                ad_kwargs = {
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1864
                    "allow_relink": allow_relink,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1865
                    "force": force,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1866
                    "lin": lin,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1867
                    "path": li_path,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1868
                    "props": li_props,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1869
                }
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1870
                return self.__plan_op(op,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1871
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1872
                    _be_activate=be_activate, _be_name=be_name,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1873
                    _li_ignore=li_ignore, _li_md_only=li_md_only,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1874
                    _new_be=new_be, _noexecute=noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1875
                    _refresh_catalogs=refresh_catalogs, _repos=repos,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1876
                    _update_index=update_index, _ad_kwargs=ad_kwargs,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1877
                    li_pkg_updates=li_pkg_updates, reject_list=reject_list)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1878
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1879
        def gen_plan_detach(self, backup_be=None,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1880
            backup_be_name=None, be_activate=True, be_name=None, force=False,
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1881
            li_ignore=None, li_md_only=False, li_pkg_updates=True, new_be=False,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1882
            noexecute=False):
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1883
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1884
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1885
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1886
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1887
                Detach from a parent image and remove any constraints
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1888
                package from this image.  Once an operation has been planned,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1889
                it may be executed by first calling prepare(), and then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1890
                execute_plan().  After execution of a plan, or to abandon a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1891
                plan, reset() should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1892
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1893
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1894
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1895
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1896
                For all other parameters, refer to the 'gen_plan_install' and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1897
                'gen_plan_sync' functions for an explanation of their usage
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1898
                and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1899
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1900
                op = API_OP_DETACH
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1901
                ad_kwargs = {
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1902
                    "force": force
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1903
                }
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1904
                return self.__plan_op(op, _ad_kwargs=ad_kwargs,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1905
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1906
                    _be_activate=be_activate, _be_name=be_name,
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1907
                    _li_ignore=li_ignore, _li_md_only=li_md_only,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1908
                    _new_be=new_be, _noexecute=noexecute,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1909
                    _refresh_catalogs=False, _update_index=False,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1910
                    li_pkg_updates=li_pkg_updates)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1911
2382
b91a97e46434 18413 recursive uninstall functionality should be removed
Shawn Walker <shawn.walker@oracle.com>
parents: 2352
diff changeset
  1912
        def plan_uninstall(self, pkg_list, noexecute=False, update_index=True,
b91a97e46434 18413 recursive uninstall functionality should be removed
Shawn Walker <shawn.walker@oracle.com>
parents: 2352
diff changeset
  1913
            be_name=None, new_be=False, be_activate=True):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1914
                """DEPRECATED.  use gen_plan_uninstall()."""
2382
b91a97e46434 18413 recursive uninstall functionality should be removed
Shawn Walker <shawn.walker@oracle.com>
parents: 2352
diff changeset
  1915
                for pd in self.gen_plan_uninstall(pkgs_to_uninstall=pkg_list,
b91a97e46434 18413 recursive uninstall functionality should be removed
Shawn Walker <shawn.walker@oracle.com>
parents: 2352
diff changeset
  1916
                    noexecute=noexecute, update_index=update_index,
b91a97e46434 18413 recursive uninstall functionality should be removed
Shawn Walker <shawn.walker@oracle.com>
parents: 2352
diff changeset
  1917
                    be_name=be_name, new_be=new_be, be_activate=be_activate):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1918
                        continue
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1919
                return not self.planned_nothingtodo()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1920
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1921
        def gen_plan_uninstall(self, pkgs_to_uninstall,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1922
            backup_be=None, backup_be_name=None, be_activate=True,
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1923
            be_name=None, li_ignore=None, li_parent_sync=True, new_be=False,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1924
            noexecute=False, update_index=True):
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1925
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1926
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1927
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1928
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1929
                Constructs a plan to remove the packages provided in
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1930
                pkgs_to_uninstall.  Once an operation has been planned, it may
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1931
                be executed by first calling prepare(), and then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1932
                execute_plan().  After execution of a plan, or to abandon a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1933
                plan, reset() should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1934
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1935
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1936
                not by positional order.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1937
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1938
                'pkgs_to_uninstall' is a list of packages to uninstall.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1939
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1940
                For all other parameters, refer to the 'gen_plan_install'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1941
                function for an explanation of their usage and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1942
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1943
                # certain parameters must be specified
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1944
                assert pkgs_to_uninstall and type(pkgs_to_uninstall) == list
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1945
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1946
                op = API_OP_UNINSTALL
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1947
                return self.__plan_op(op,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1948
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1949
                    _be_activate=be_activate, _be_name=be_name,
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  1950
                    _li_ignore=li_ignore, _li_parent_sync=li_parent_sync,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  1951
                    _new_be=new_be, _noexecute=noexecute,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1952
                    _refresh_catalogs=False,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1953
                    _update_index=update_index,
2382
b91a97e46434 18413 recursive uninstall functionality should be removed
Shawn Walker <shawn.walker@oracle.com>
parents: 2352
diff changeset
  1954
                    pkgs_to_uninstall=pkgs_to_uninstall)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  1955
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1956
        def gen_plan_set_mediators(self, mediators, backup_be=None,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1957
            backup_be_name=None, be_activate=True, be_name=None, li_ignore=None,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1958
            li_parent_sync=True, new_be=None, noexecute=False,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1959
            update_index=True):
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1960
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1961
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  1962
                containing plan information for child images.
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1963
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1964
                Creates a plan to change the version and implementation values
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1965
                for mediators as specified in the provided dictionary.  Once an
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1966
                operation has been planned, it may be executed by first calling
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1967
                prepare(), and then execute_plan().  After execution of a plan,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1968
                or to abandon a plan, reset() should be called.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1969
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1970
                Callers should pass all arguments by name assignment and not by
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1971
                positional order.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1972
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1973
                'mediators' is a dict of dicts of the mediators to set version
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1974
                and implementation for.  If the dict for a given mediator-name
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1975
                is empty, it will be intepreted as a request to revert the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1976
                specified mediator to the default, "optimal" mediation.  It
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1977
                should be of the form:
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1978
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1979
                   {
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1980
                       mediator-name: {
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1981
                           "implementation": mediator-implementation-string,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1982
                           "version": mediator-version-string
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1983
                       }
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1984
                   }
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1985
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1986
                   'implementation' is an optional string that specifies the
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1987
                   implementation of the mediator for use in addition to or
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1988
                   instead of 'version'.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1989
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1990
                   'version' is an optional string that specifies the version
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1991
                   (expressed as a dot-separated sequence of non-negative
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1992
                   integers) of the mediator for use.
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1993
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1994
                For all other parameters, refer to the 'gen_plan_install'
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1995
                function for an explanation of their usage and effects."""
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1996
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  1997
                assert mediators
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  1998
                return self.__plan_op(API_OP_SET_MEDIATOR,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  1999
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2453
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  2000
                    _be_activate=be_activate, _be_name=be_name,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  2001
                    _li_ignore=li_ignore, _li_parent_sync=li_parent_sync,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  2002
                    mediators=mediators, _new_be=new_be, _noexecute=noexecute,
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  2003
                    _refresh_catalogs=False, _update_index=update_index)
330443795456 18619 link mediation support needed
Shawn Walker <shawn.walker@oracle.com>
parents: 2452
diff changeset
  2004
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2005
        def plan_change_varcets(self, variants=None, facets=None,
2319
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
  2006
            noexecute=False, be_name=None, new_be=None, repos=None,
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
  2007
            be_activate=True):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2008
                """DEPRECATED.  use gen_plan_change_varcets()."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2009
                for pd in self.gen_plan_change_varcets(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2010
                    variants=variants, facets=facets, noexecute=noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2011
                    be_name=be_name, new_be=new_be, repos=repos,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2012
                    be_activate=be_activate):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2013
                        continue
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2014
                return not self.planned_nothingtodo()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2015
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2016
        def gen_plan_change_varcets(self, facets=None, variants=None,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2017
            backup_be=None, backup_be_name=None, be_activate=True, be_name=None,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2018
            li_ignore=None, li_parent_sync=True, new_be=None, noexecute=False,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2019
            refresh_catalogs=True, reject_list=misc.EmptyI, repos=None,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2020
            update_index=True):
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2021
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2022
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2023
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2024
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2025
                Creates a plan to change the specified variants and/or
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2026
                facets for the image.  Once an operation has been planned, it
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2027
                may be executed by first calling prepare(), and then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2028
                execute_plan().  After execution of a plan, or to abandon a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2029
                plan, reset() should be called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2030
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2031
                Callers should pass all arguments by name assignment and
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2032
                not by positional order.
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2033
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2034
                'facets' is a dict of the facets to change the values of.
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2035
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2036
                'variants' is a dict of the variants to change the values of.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2037
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2038
                For all other parameters, refer to the 'gen_plan_install'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2039
                function for an explanation of their usage and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2040
2482
b47e1f7cc268 18646 traceback when setting a facet with no installed actions to 'None'
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2453
diff changeset
  2041
                # An empty facets dictionary is allowed because that's how to
b47e1f7cc268 18646 traceback when setting a facet with no installed actions to 'None'
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2453
diff changeset
  2042
                # unset all set facets.
b47e1f7cc268 18646 traceback when setting a facet with no installed actions to 'None'
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2453
diff changeset
  2043
                if not variants and facets is None:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2044
                        raise ValueError, "Nothing to do"
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2045
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2046
                if variants:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2047
                        op = API_OP_CHANGE_VARIANT
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2048
                else:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2049
                        op = API_OP_CHANGE_FACET
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2050
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2051
                return self.__plan_op(op, _backup_be=backup_be,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2052
                    _backup_be_name=backup_be_name, _be_activate=be_activate,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2053
                    _be_name=be_name, _li_ignore=li_ignore,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2054
                    _li_parent_sync=li_parent_sync, _new_be=new_be,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2055
                    _noexecute=noexecute, _refresh_catalogs=refresh_catalogs,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2056
                    _repos=repos,
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2057
                    _update_index=update_index, variants=variants,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2058
                    facets=facets, reject_list=reject_list)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2059
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
  2060
        def plan_revert(self, args, tagged=False, noexecute=True, be_name=None,
2319
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
  2061
            new_be=None, be_activate=True):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2062
                """DEPRECATED.  use gen_plan_revert()."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2063
                for pd in self.gen_plan_revert(
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2064
                    args=args, tagged=tagged, noexecute=noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2065
                    be_name=be_name, new_be=new_be, be_activate=be_activate):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2066
                        continue
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2067
                return not self.planned_nothingtodo()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2068
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2069
        def gen_plan_revert(self, args, backup_be=None, backup_be_name=None,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2070
            be_activate=True, be_name=None, new_be=None, noexecute=True,
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2071
            tagged=False):
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2072
                """This is a generator function that yields a PlanDescription
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2073
                object.  If parsable_version is set, it also yields dictionaries
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2074
                containing plan information for child images.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2075
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2076
                Plan to revert either files or all files tagged with
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2077
                specified values.  Args contains either path names or tag
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2078
                names to be reverted, tagged is True if args contains tags.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2079
                Once an operation has been planned, it may be executed by
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2080
                first calling prepare(), and then execute_plan().  After
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2081
                execution of a plan, or to abandon a plan, reset() should be
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2082
                called.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2083
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2084
                For all other parameters, refer to the 'gen_plan_install'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2085
                function for an explanation of their usage and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2086
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2087
                op = API_OP_REVERT
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2088
                return self.__plan_op(op, _be_activate=be_activate,
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2089
                    _backup_be=backup_be, _backup_be_name=backup_be_name,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2090
                    _be_name=be_name, _li_ignore=[], _new_be=new_be,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2091
                    _noexecute=noexecute, _refresh_catalogs=False,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2092
                    _update_index=False, args=args, tagged=tagged)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2093
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2094
        def attach_linked_child(self, lin, li_path, li_props=None,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2095
            accept=False, allow_relink=False, force=False, li_md_only=False,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2096
            li_pkg_updates=True, noexecute=False,
2444
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2097
            refresh_catalogs=True, reject_list=misc.EmptyI,
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2098
            show_licenses=False, update_index=True):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2099
                """Attach an image as a child to the current image (the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2100
                current image will become a parent image. This operation
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2101
                results in attempting to sync the child image with the parent
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2102
                image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2103
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2104
                'lin' is the name of the child image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2105
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2106
                'li_path' is the path to the child image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2107
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2108
                'li_props' optional linked image properties to apply to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2109
                child image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2110
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2111
                'allow_relink' indicates whether we should allow linking of a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2112
                child image that is already linked (the child may already
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2113
                be a child or a parent image).
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2114
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2115
                'force' indicates whether we should allow linking of a child
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2116
                image even if the specified linked image type doesn't support
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2117
                attaching of children.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2118
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2119
                'li_md_only' indicates whether we should only update linked
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2120
                image metadata and not actually try to sync the child image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2121
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2122
                'li_pkg_updates' indicates whether we should disallow pkg
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2123
                updates during the child image sync.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2124
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2125
                'noexecute' indicates if we should actually make any changes
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2126
                rather or just simulate the operation.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2127
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2128
                'refresh_catalogs' controls whether the catalogs will
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2129
                automatically be refreshed.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2130
2444
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2131
                'reject_list' is a list of patterns not to be permitted
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2132
                in solution; installed packages matching these patterns
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2133
                are removed.
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2134
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2135
                'update_index' determines whether client search indexes will
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2136
                be updated in the child after the sync operation completes.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2137
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2138
                This function returns a tuple of the format (rv, err) where rv
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2139
                is a pkg.client.pkgdefs return value and if an error was
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2140
                encountered err is an exception object which describes the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2141
                error."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2142
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2143
                return self._img.linked.attach_child(lin, li_path, li_props,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2144
                    accept=accept, allow_relink=allow_relink, force=force,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2145
                    li_md_only=li_md_only, li_pkg_updates=li_pkg_updates,
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2146
                    noexecute=noexecute,
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2147
                    progtrack=self.__progresstracker,
2444
9170dcd9559d 18349 linked image code needs to be more resilient in the face of zoneadm failure
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2433
diff changeset
  2148
                    refresh_catalogs=refresh_catalogs, reject_list=reject_list,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2149
                    show_licenses=show_licenses, update_index=update_index)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2150
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2151
        def detach_linked_children(self, li_list, force=False,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2152
            li_md_only=False, li_pkg_updates=True, noexecute=False):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2153
                """Detach one or more children from the current image. This
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2154
                operation results in the removal of any constraint package
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2155
                from the child images.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2156
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2157
                'li_list' a list of linked image name objects which specified
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2158
                which children to operate on.  If the list is empty then we
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2159
                operate on all children.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2160
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2161
                For all other parameters, refer to the 'attach_linked_child'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2162
                function for an explanation of their usage and effects.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2163
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2164
                This function returns a dictionary where the keys are linked
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2165
                image name objects and the values are the result of the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2166
                specified operation on the associated child image.  The result
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2167
                is a tuple of the format (rv, err) where rv is a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2168
                pkg.client.pkgdefs return value and if an error was
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2169
                encountered err is an exception object which describes the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2170
                error."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2171
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2172
                return self._img.linked.detach_children(li_list,
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2173
                    force=force, li_md_only=li_md_only,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2174
                    li_pkg_updates=li_pkg_updates,
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2175
                    noexecute=noexecute)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2176
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2177
        def detach_linked_rvdict2rv(self, rvdict):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2178
                """Convenience function that takes a dictionary returned from
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2179
                an operations on multiple children and merges the results into
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2180
                a single return code."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2181
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2182
                return self._img.linked.detach_rvdict2rv(rvdict)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2183
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2184
        def sync_linked_children(self, li_list,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2185
            accept=False, li_md_only=False,
2500
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2186
            li_pkg_updates=True, noexecute=False,
a63fead21404 18439 pkg commands that modify the image should have a parsable output option
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2496
diff changeset
  2187
            refresh_catalogs=True, show_licenses=False, update_index=True):
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2188
                """Sync one or more children of the current image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2189
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2190
                For all other parameters, refer to the 'attach_linked_child'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2191
                and 'detach_linked_children' functions for an explanation of
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2192
                their usage and effects.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2193
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2194
                For a description of the return value, refer to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2195
                'detach_linked_children' function."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2196
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2197
                rvdict = self._img.linked.sync_children(li_list,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2198
                    accept=accept, li_md_only=li_md_only,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2199
                    li_pkg_updates=li_pkg_updates, noexecute=noexecute,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2200
                    progtrack=self.__progresstracker,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2201
                    refresh_catalogs=refresh_catalogs,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2202
                    show_licenses=show_licenses, update_index=update_index)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2203
                return rvdict
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2204
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2205
        def sync_linked_rvdict2rv(self, rvdict):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2206
                """Convenience function that takes a dictionary returned from
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2207
                an operations on multiple children and merges the results into
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2208
                a single return code."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2209
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2210
                return self._img.linked.sync_rvdict2rv(rvdict)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2211
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2212
        def audit_linked_children(self, li_list):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2213
                """Audit one or more children of the current image to see if
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2214
                they are in sync with this image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2215
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2216
                For all parameters, refer to the 'detach_linked_children'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2217
                functions for an explanation of their usage and effects.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2218
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2219
                For a description of the return value, refer to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2220
                'detach_linked_children' function."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2221
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2222
                rvdict = self._img.linked.audit_children(li_list)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2223
                return rvdict
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2224
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2225
        def audit_linked_rvdict2rv(self, rvdict):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2226
                """Convenience function that takes a dictionary returned from
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2227
                an operations on multiple children and merges the results into
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2228
                a single return code."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2229
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2230
                return self._img.linked.audit_rvdict2rv(rvdict)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2231
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2232
        def audit_linked(self, li_parent_sync=True):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2233
                """If the current image is a child image, this function
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2234
                audits the current image to see if it's in sync with it's
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2235
                parent.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2236
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2237
                For a description of the return value, refer to the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2238
                'detach_linked_children' function."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2239
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2240
                lin = self._img.linked.child_name
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2241
                rvdict = {}
2925
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2242
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2243
                if li_parent_sync:
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2244
                        # refresh linked image data from parent image.
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2245
                        rvdict[lin] = self._img.linked.syncmd_from_parent(
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2246
                            catch_exception=True)
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2247
                        if rvdict[lin] is not None:
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2248
                                return rvdict
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2249
3e1fbeb31067 15743323 linked images should propagate incorporation facet version locks
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2910
diff changeset
  2250
                rvdict[lin] = self._img.linked.audit_self()
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2251
                return rvdict
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2252
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2253
        def ischild(self):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2254
                """Indicates whether the current image is a child image."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2255
                return self._img.linked.ischild()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2256
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2257
        def isparent(self, li_ignore=None):
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2258
                """Indicates whether the current image is a parent image."""
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2259
                return self._img.linked.isparent(li_ignore)
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2260
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2261
        @staticmethod
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2262
        def __utc_format(time_str, utc_now):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2263
                """Given a local time value string, formatted with
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2264
                "%Y-%m-%dT%H:%M:%S, return a UTC representation of that value,
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2265
                formatted with %Y%m%dT%H%M%SZ.  This raises a ValueError if the
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2266
                time was incorrectly formatted.  If the time_str is "now", it
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2267
                returns the value of utc_now"""
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2268
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2269
                if time_str == "now":
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2270
                        return utc_now
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2271
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2272
                try:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2273
                        local_dt = datetime.datetime.strptime(time_str,
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2274
                            "%Y-%m-%dT%H:%M:%S")
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2275
                        secs = time.mktime(local_dt.timetuple())
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2276
                        utc_dt = datetime.datetime.utcfromtimestamp(secs)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2277
                        return utc_dt.strftime("%Y%m%dT%H%M%SZ")
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2278
                except ValueError, e:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2279
                        raise apx.HistoryRequestException(e)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2280
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2281
        def __get_history_paths(self, time_val, utc_now):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2282
                """Given a local timestamp, either as a discrete value, or a
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2283
                range of values, formatted as '<timestamp>-<timestamp>', and a
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2284
                path to find history xml files, return an array of paths that
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2285
                match that timestamp.  utc_now is the current time expressed in
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2286
                UTC"""
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2287
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2288
                files = []
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2289
                if len(time_val) > 20 or time_val.startswith("now-"):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2290
                        if time_val.startswith("now-"):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2291
                                start = utc_now
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2292
                                finish = self.__utc_format(time_val[4:],
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2293
                                    utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2294
                        else:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2295
                                # our ranges are 19 chars of timestamp, a '-',
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2296
                                # and another timestamp
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2297
                                start = self.__utc_format(time_val[:19],
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2298
                                    utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2299
                                finish = self.__utc_format(time_val[20:],
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2300
                                    utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2301
                        if start > finish:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2302
                                raise apx.HistoryRequestException(_("Start "
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2303
                                    "time must be older than finish time: "
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2304
                                    "%s") % time_val)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2305
                        files = self.__get_history_range(start, finish)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2306
                else:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2307
                        # there can be multiple event files per timestamp
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2308
                        prefix = self.__utc_format(time_val, utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2309
                        files = glob.glob(os.path.join(self._img.history.path,
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2310
                            "%s*" % prefix))
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2311
                if not files:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2312
                        raise apx.HistoryRequestException(_("No history "
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2313
                            "entries found for %s") % time_val)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2314
                return files
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2315
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2316
        def __get_history_range(self, start, finish):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2317
                """Given a start and finish date, formatted as UTC date strings
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2318
                as per __utc_format(), return a list of history filenames that
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2319
                fall within that date range.  A range of two equal dates is
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2320
                the equivalent of just retrieving history for that single date
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2321
                string."""
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2322
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2323
                entries = []
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2324
                all_entries = sorted(os.listdir(self._img.history.path))
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2325
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2326
                for entry in all_entries:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2327
                        # our timestamps are always 16 character datestamps
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2328
                        basename = os.path.basename(entry)[:16]
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2329
                        if basename >= start:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2330
                                if basename > finish:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2331
                                        # we can stop looking now.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2332
                                        break
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2333
                                entries.append(entry)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2334
                return entries
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2335
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2336
        def gen_history(self, limit=None, times=misc.EmptyI):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2337
                """A generator function that returns History objects up to the
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2338
                limit specified matching the times specified.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2339
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2340
                'limit' is an optional integer value specifying the maximum
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2341
                number of entries to return.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2342
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2343
                'times' is a list of timestamp or timestamp range strings to
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2344
                restrict the returned entries to."""
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2345
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2346
                # Make entries a set to cope with multiple overlapping ranges or
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2347
                # times.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2348
                entries = set()
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2349
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2350
                utc_now = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2351
                for time_val in times:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2352
                        # Ranges are 19 chars of timestamp, a '-', and
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2353
                        # another timestamp.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2354
                        if len(time_val) > 20 or time_val.startswith("now-"):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2355
                                if time_val.startswith("now-"):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2356
                                        start = utc_now
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2357
                                        finish = self.__utc_format(time_val[4:],
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2358
                                            utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2359
                                else:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2360
                                        start = self.__utc_format(time_val[:19],
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2361
                                            utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2362
                                        finish = self.__utc_format(
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2363
                                            time_val[20:], utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2364
                                if start > finish:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2365
                                        raise apx.HistoryRequestException(
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2366
                                            _("Start time must be older than "
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2367
                                            "finish time: %s") % time_val)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2368
                                files = self.__get_history_range(start, finish)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2369
                        else:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2370
                                # There can be multiple entries per timestamp.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2371
                                prefix = self.__utc_format(time_val, utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2372
                                files = glob.glob(os.path.join(
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2373
                                    self._img.history.path, "%s*" % prefix))
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2374
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2375
                        try:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2376
                                files = self.__get_history_paths(time_val,
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2377
                                    utc_now)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2378
                                entries.update(files)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2379
                        except ValueError:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2380
                                raise apx.HistoryRequestException(_("Invalid "
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2381
                                    "time format '%s'.  Please use "
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2382
                                    "%%Y-%%m-%%dT%%H:%%M:%%S or\n"
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2383
                                    "%%Y-%%m-%%dT%%H:%%M:%%S-"
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2384
                                    "%%Y-%%m-%%dT%%H:%%M:%%S") % time_val)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2385
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2386
                if not times:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2387
                        try:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2388
                                entries = os.listdir(self._img.history.path)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2389
                        except EnvironmentError, e:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2390
                                if e.errno == errno.ENOENT:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2391
                                        # No history to list.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2392
                                        return
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2393
                                raise apx._convert_error(e)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2394
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2395
                entries = sorted(entries)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2396
                if limit:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2397
                        limit *= -1
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2398
                        entries = entries[limit:]
2648
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2399
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2400
                try:
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2401
                        uuid_be_dic = bootenv.BootEnv.get_uuid_be_dic()
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2402
                except apx.ApiException, e:
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2403
                        uuid_be_dic = {}
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2404
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2405
                for entry in entries:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2406
                        # Yield each history entry object as it is loaded.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2407
                        try:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2408
                                yield history.History(
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2409
                                    root_dir=self._img.history.root_dir,
2648
16a431283f0e 7158089 pkg history could be faster
Tim Foster <tim.s.foster@oracle.com>
parents: 2639
diff changeset
  2410
                                    filename=entry, uuid_be_dic=uuid_be_dic)
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2411
                        except apx.HistoryLoadException, e:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2412
                                if e.parse_failure:
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2413
                                        # Ignore corrupt entries.
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2414
                                        continue
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2415
                                raise
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  2416
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2417
        def get_linked_name(self):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2418
                """If the current image is a child image, this function
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2419
                returns a linked image name object which represents the name
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2420
                of the current image."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2421
                return self._img.linked.child_name
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2422
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2423
        def get_linked_props(self, lin=None):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2424
                """Return a dictionary which represents the linked image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2425
                properties associated with a linked image.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2426
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2427
                'lin' is the name of the child image.  If lin is None then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2428
                the current image is assumed to be a linked image and it's
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2429
                properties are returned."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2430
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2431
                return self._img.linked.child_props(lin=lin)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2432
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2433
        def list_linked(self, li_ignore=None):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2434
                """Returns a list of linked images associated with the
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2435
                current image.  This includes both child and parent images.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2436
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2437
                For all parameters, refer to the 'gen_plan_install' function
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2438
                for an explanation of their usage and effects.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2439
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2440
                The returned value is a list of tuples where each tuple
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2441
                contains (<li name>, <relationship>, <li path>)."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2442
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2443
                return self._img.linked.list_related(li_ignore=li_ignore)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2444
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2445
        def parse_linked_name(self, li_name, allow_unknown=False):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2446
                """Given a string representing a linked image child name,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2447
                returns linked image name object representing the same name.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2448
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2449
                'allow_unknown' indicates whether the name must represent
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2450
                actual children or simply be syntactically correct."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2451
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2452
                return self._img.linked.parse_name(li_name, allow_unknown)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2453
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2454
        def parse_linked_name_list(self, li_name_list, allow_unknown=False):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2455
                """Given a list of strings representing linked image child
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2456
                names, returns a list of linked image name objects
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2457
                representing the same names.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2458
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2459
                For all other parameters, refer to the 'parse_linked_name'
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2460
                function for an explanation of their usage and effects."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2461
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2462
                return [
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2463
                    self.parse_linked_name(li_name, allow_unknown)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2464
                    for li_name in li_name_list
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2465
                ]
2200
155eda704b2f 16279 Need a way to revert certain editable files to a as-installed state
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2183
diff changeset
  2466
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2467
        def describe(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2468
                """Returns None if no plan is ready yet, otherwise returns
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2469
                a PlanDescription."""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2470
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2471
                return self.__plan_desc
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2472
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2473
        def prepare(self):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2474
                """Takes care of things which must be done before the plan can
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2475
                be executed.  This includes downloading the packages to disk and
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2476
                preparing the indexes to be updated during execution.  Should
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2477
                only be called once a gen_plan_*() method has been called.  If
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2478
                a plan is abandoned after calling this method, reset() should
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2479
                be called."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2480
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2481
                self._acquire_activity_lock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2482
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2483
                        self._img.lock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2484
                except:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2485
                        self._activity_lock.release()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2486
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2487
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2488
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2489
                        if not self._img.imageplan:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2490
                                raise apx.PlanMissingException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2491
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2492
                        if not self.__planned_children:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2493
                                # if we never planned children images then we
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2494
                                # didn't finish planning.
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2495
                                raise apx.PlanMissingException()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2496
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2497
                        if self.__prepared:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2498
                                raise apx.AlreadyPreparedException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2499
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2500
                        self._enable_cancel()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2501
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2502
                        try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2503
                                self._img.imageplan.preexecute()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2504
                        except search_errors.ProblematicPermissionsIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2505
                                raise apx.ProblematicPermissionsIndexException(e)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2506
                        except:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2507
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2508
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2509
                        self._disable_cancel()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2510
                        self.__prepared = True
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2511
                except apx.CanceledException, e:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2512
                        self._cancel_done()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2513
                        if self._img.history.operation_name:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2514
                                # If an operation is in progress, log
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2515
                                # the error and mark its end.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2516
                                self.log_operation_end(error=e)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2517
                        raise
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2518
                except Exception, e:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2519
                        self._cancel_cleanup_exception()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2520
                        if self._img.history.operation_name:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2521
                                # If an operation is in progress, log
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2522
                                # the error and mark its end.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2523
                                self.log_operation_end(error=e)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2524
                        raise
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2525
                except:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2526
                        # Handle exceptions that are not subclasses of
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2527
                        # Exception.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2528
                        self._cancel_cleanup_exception()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2529
                        if self._img.history.operation_name:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2530
                                # If an operation is in progress, log
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2531
                                # the error and mark its end.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2532
                                exc_type, exc_value, exc_traceback = \
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2533
                                    sys.exc_info()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2534
                                self.log_operation_end(error=exc_type)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  2535
                        raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2536
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2537
                        self._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2538
                        self._img.unlock()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2539
                        try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2540
                                if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2541
                                        self._img.transport.stats.dump()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2542
                        except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2543
                                # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2544
                                # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2545
                                pass
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2546
                        self._activity_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2547
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2548
                self._img.linked.api_recurse_prepare(self.__progresstracker)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2549
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2550
        def execute_plan(self):
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2551
                """Executes the plan. This is uncancelable once it begins.
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2552
                Should only be called after the prepare method has been
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2553
                called.  After plan execution, reset() should be called."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2554
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2555
                self._acquire_activity_lock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2556
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2557
                        self._disable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2558
                        self._img.lock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2559
                except:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2560
                        self._activity_lock.release()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2561
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2562
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2563
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2564
                        if not self._img.imageplan:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2565
                                raise apx.PlanMissingException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2566
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2567
                        if not self.__prepared:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2568
                                raise apx.PrematureExecutionException()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2569
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2570
                        if self.__executed:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2571
                                raise apx.AlreadyExecutedException()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2572
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2573
                        try:
3003
0612a636198c 17734557 Bad formatting of error text from pkg update command
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2991
diff changeset
  2574
                                be = bootenv.BootEnv(self._img,
0612a636198c 17734557 Bad formatting of error text from pkg update command
Xiaobo Shen <xiaobo.shen@oracle.com>
parents: 2991
diff changeset
  2575
                                    self.__progresstracker)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2576
                        except RuntimeError:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2577
                                be = bootenv.BootEnvNull(self._img)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2578
                        self._img.bootenv = be
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2579
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2580
                        if self.__new_be == False and \
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2581
                            self._img.imageplan.reboot_needed() and \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2582
                            self._img.is_liveroot():
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2583
                                e = apx.RebootNeededOnLiveImageException()
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2584
                                self.log_operation_end(error=e)
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2585
                                raise e
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2586
2517
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2587
                        # Before proceeding, create a backup boot environment if
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2588
                        # requested.
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2589
                        if self.__backup_be == True:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2590
                                try:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2591
                                        be.create_backup_be(
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2592
                                            be_name=self.__backup_be_name)
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2593
                                except Exception, e:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2594
                                        self.log_operation_end(error=e)
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2595
                                        raise
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2596
                                except:
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2597
                                        # Handle exceptions that are not
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2598
                                        # subclasses of Exception.
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2599
                                        exc_type, exc_value, exc_traceback = \
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2600
                                            sys.exc_info()
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2601
                                        self.log_operation_end(error=exc_type)
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2602
                                        raise
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2603
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2604
                        # After (possibly) creating backup be, determine if
8f26a1d7100c 18827 pkg(1) should provide interfaces to control backup BE creation
Shawn Walker <shawn.walker@oracle.com>
parents: 2512
diff changeset
  2605
                        # operation should execute on a clone of current BE.
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2606
                        if self.__new_be == True:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2607
                                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2608
                                        be.init_image_recovery(self._img,
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  2609
                                            self.__be_name)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2610
                                except Exception, e:
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2611
                                        self.log_operation_end(error=e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2612
                                        raise
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2613
                                except:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2614
                                        # Handle exceptions that are not
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  2615
                                        # subclasses of Exception.
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2616
                                        exc_type, exc_value, exc_traceback = \
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2617
                                            sys.exc_info()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2618
                                        self.log_operation_end(error=exc_type)
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2619
                                        raise
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2620
                                # check if things gained underneath us
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2621
                                if self._img.is_liveroot():
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2622
                                        e = apx.UnableToCopyBE()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2623
                                        self.log_operation_end(error=e)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2624
                                        raise e
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2625
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2626
                        raise_later = None
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2627
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2628
                        # we're about to execute a plan so change our current
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2629
                        # working directory to / so that we won't fail if we
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2630
                        # try to remove our current working directory
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2631
                        os.chdir(os.sep)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2632
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2633
                        try:
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2634
                                try:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2635
                                        self._img.imageplan.execute()
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2636
                                except apx.WrapIndexingException, e:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2637
                                        raise_later = e
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2638
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2639
                                if not self._img.linked.nothingtodo():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2640
                                        self._img.linked.syncmd()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2641
                        except RuntimeError, e:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2642
                                if self.__new_be == True:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2643
                                        be.restore_image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2644
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2645
                                        be.restore_install_uninstall()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2646
                                # Must be done after bootenv restore.
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2647
                                self.log_operation_end(error=e)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2648
                                raise
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2649
                        except search_errors.IndexLockedException, e:
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2650
                                error = apx.IndexLockedException(e)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2651
                                self.log_operation_end(error=error)
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2652
                                raise error
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2653
                        except search_errors.ProblematicPermissionsIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2654
                                error = apx.ProblematicPermissionsIndexException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2655
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2656
                                raise error
2028
b2c674e6ee28 16744 repository multi-publisher on-disk format should be formalized and implemented
Shawn Walker <shawn.walker@oracle.com>
parents: 2026
diff changeset
  2657
                        except search_errors.InconsistentIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2658
                                error = apx.CorruptedIndexException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2659
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2660
                                raise error
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  2661
                        except NonzeroExitException, e:
2089
c8b9d6341530 2775 pkg should provide a way to downgrade (reinstall) packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2073
diff changeset
  2662
                                # Won't happen during update
1019
e61c57c724c9 7663 disable_fmri should be synchronous
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 996
diff changeset
  2663
                                be.restore_install_uninstall()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2664
                                error = apx.ActuatorException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2665
                                self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2666
                                raise error
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2667
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2668
                        except Exception, e:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2669
                                if self.__new_be == True:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2670
                                        be.restore_image()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2671
                                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2672
                                        be.restore_install_uninstall()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2673
                                # Must be done after bootenv restore.
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  2674
                                self.log_operation_end(error=e)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2675
                                raise
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2676
                        except:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2677
                                # Handle exceptions that are not subclasses of
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2678
                                # Exception.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2679
                                exc_type, exc_value, exc_traceback = \
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2680
                                    sys.exc_info()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2681
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2682
                                if self.__new_be == True:
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2683
                                        be.restore_image()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2684
                                else:
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2685
                                        be.restore_install_uninstall()
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2686
                                # Must be done after bootenv restore.
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2687
                                self.log_operation_end(error=exc_type)
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  2688
                                raise
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2689
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2690
                        self._img.linked.api_recurse_execute(
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2691
                            self.__progresstracker)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2692
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2693
                        self.__finished_execution(be)
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2694
                        if raise_later:
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2695
                                raise raise_later
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  2696
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2697
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2698
                        self._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2699
                        if self._img.locked:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2700
                                self._img.unlock()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2701
                        self._activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2702
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2703
        def __finished_execution(self, be):
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2704
                if self._img.imageplan.state != plandesc.EXECUTED_OK:
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2705
                        if self.__new_be == True:
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2706
                                be.restore_image()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2707
                        else:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2708
                                be.restore_install_uninstall()
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2709
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2710
                        error = apx.ImageplanStateException(
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2711
                            self._img.imageplan.state)
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2712
                        # Must be done after bootenv restore.
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2713
                        self.log_operation_end(error=error)
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2714
                        raise error
2105
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  2715
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2716
                if self._img.imageplan.boot_archive_needed() or \
2105
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  2717
                    self.__new_be:
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  2718
                        be.update_boot_archive()
212a253a462a 12530 pkg -R install doesn't update boot archive
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2100
diff changeset
  2719
2034
d5ee7746faeb 16108 boot environments should be created by default only when needed
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2033
diff changeset
  2720
                if self.__new_be == True:
2319
247375ff5e19 14165 pkg operations should provide option to skip BE activation
Shawn Walker <shawn.walker@oracle.com>
parents: 2313
diff changeset
  2721
                        be.activate_image(set_active=self.__be_activate)
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2722
                else:
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2723
                        be.activate_install_uninstall()
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2724
                self._img.cleanup_cached_content()
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2725
                # If the end of the operation wasn't already logged
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2726
                # by one of the previous operations, then log it as
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2727
                # ending now.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2728
                if self._img.history.operation_name:
2708
4dac3e277ccf 7137406 pkg image-update could display release notes (or pointer to)
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2701
diff changeset
  2729
                        self.log_operation_end(release_notes=
4dac3e277ccf 7137406 pkg image-update could display release notes (or pointer to)
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2701
diff changeset
  2730
                            self._img.imageplan.pd.release_notes_name)
1286
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2731
                self.__executed = True
2e5bb564a9e2 8948 search errors should make it clear that the rest of the command worked
Brock Pytlik <bpytlik@sun.com>
parents: 1279
diff changeset
  2732
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2733
        def set_plan_license_status(self, pfmri, plicense, accepted=None,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2734
            displayed=None):
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2735
                """Sets the license status for the given package FMRI and
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2736
                license entry.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2737
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2738
                'accepted' is an optional parameter that can be one of three
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2739
                values:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2740
                        None    leaves accepted status unchanged
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2741
                        False   sets accepted status to False
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2742
                        True    sets accepted status to True
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2743
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2744
                'displayed' is an optional parameter that can be one of three
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2745
                values:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2746
                        None    leaves displayed status unchanged
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2747
                        False   sets displayed status to False
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2748
                        True    sets displayed status to True"""
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2749
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2750
                self._acquire_activity_lock()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2751
                try:
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2752
                        try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2753
                                self._disable_cancel()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2754
                        except apx.CanceledException:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2755
                                self._cancel_done()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2756
                                raise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  2757
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2758
                        if not self._img.imageplan:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2759
                                raise apx.PlanMissingException()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2760
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  2761
                        for pp in self.__plan_desc.pkg_plans:
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2762
                                if pp.destination_fmri == pfmri:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2763
                                        pp.set_license_status(plicense,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2764
                                            accepted=accepted,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2765
                                            displayed=displayed)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2766
                                        break
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2767
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2768
                        self._activity_lock.release()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2769
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2770
        def refresh(self, full_refresh=False, pubs=None, immediate=False):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2771
                """Refreshes the metadata (e.g. catalog) for one or more
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2772
                publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2773
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2774
                'full_refresh' is an optional boolean value indicating whether
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2775
                a full retrieval of publisher metadata (e.g. catalogs) or only
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2776
                an update to the existing metadata should be performed.  When
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2777
                True, 'immediate' is also set to True.
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2778
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2779
                'pubs' is a list of publisher prefixes or publisher objects
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2780
                to refresh.  Passing an empty list or using the default value
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2781
                implies all publishers.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2782
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2783
                'immediate' is an optional boolean value indicating whether
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2784
                a refresh should occur now.  If False, a publisher's selected
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2785
                repository will only be checked for updates if the update
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  2786
                interval period recorded in the image configuration has been
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2787
                exceeded.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2788
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2789
                Currently returns an image object, allowing existing code to
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2790
                work while the rest of the API is put into place."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  2791
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2792
                self._acquire_activity_lock()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2793
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2794
                        self._disable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2795
                        self._img.lock()
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2796
                        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2797
                                self.__refresh(full_refresh=full_refresh,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2798
                                    pubs=pubs, immediate=immediate)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2799
                                return self._img
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  2800
                        finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2801
                                self._img.unlock()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2802
                                self._img.cleanup_downloads()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2803
                except apx.CanceledException:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2804
                        self._cancel_done()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2805
                        raise
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  2806
                finally:
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2807
                        try:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2808
                                if int(os.environ.get("PKG_DUMP_STATS", 0)) > 0:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2809
                                        self._img.transport.stats.dump()
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2810
                        except ValueError:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2811
                                # Don't generate stats if an invalid value
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2812
                                # is supplied.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  2813
                                pass
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2814
                        self._activity_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2815
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2816
        def __refresh(self, full_refresh=False, pubs=None, immediate=False):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2817
                """Private refresh method; caller responsible for locking and
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2818
                cleanup."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2819
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2820
                self._img.refresh_publishers(full_refresh=full_refresh,
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2821
                    immediate=immediate, pubs=pubs,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2822
                    progtrack=self.__progresstracker)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  2823
2313
62501ec54db1 18222 pkg info --license can fail with "unknown publisher" when using -g
Shawn Walker <shawn.walker@oracle.com>
parents: 2310
diff changeset
  2824
        def __licenses(self, pfmri, mfst, alt_pub=None):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2825
                """Private function. Returns the license info from the
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  2826
                manifest mfst."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2827
                license_lst = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2828
                for lic in mfst.gen_actions_by_type("license"):
1638
43c8e6c924a3 12852 pkg.server.api should have methods for getting package information
Rajkumar Srinivasan <rajkumar.srinivasan@sun.com>
parents: 1634
diff changeset
  2829
                        license_lst.append(LicenseInfo(pfmri, lic,
2313
62501ec54db1 18222 pkg info --license can fail with "unknown publisher" when using -g
Shawn Walker <shawn.walker@oracle.com>
parents: 2310
diff changeset
  2830
                            img=self._img, alt_pub=alt_pub))
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2831
                return license_lst
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  2832
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2833
        @_LockedCancelable()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2834
        def get_pkg_categories(self, installed=False, pubs=misc.EmptyI,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2835
            repos=None):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2836
                """Returns an ordered list of tuples of the form (scheme,
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2837
                category) containing the names of all categories in use by
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2838
                the last version of each unique package in the catalog on a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2839
                per-publisher basis.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2840
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2841
                'installed' is an optional boolean value indicating whether
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2842
                only the categories used by currently installed packages
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2843
                should be returned.  If False, the categories used by the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2844
                latest vesion of every known package will be returned
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2845
                instead.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2846
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2847
                'pubs' is an optional list of publisher prefixes to restrict
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2848
                the results to.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2849
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2850
                'repos' is a list of URI strings or RepositoryURI objects that
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2851
                represent the locations of package repositories to list packages
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2852
                for.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2853
                """
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2854
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2855
                if installed:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2856
                        excludes = misc.EmptyI
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2857
                else:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2858
                        excludes = self._img.list_excludes()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2859
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2860
                if repos:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2861
                        ignored, ignored, known_cat, inst_cat = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2862
                            self.__get_alt_pkg_data(repos)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2863
                        if installed:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2864
                                pkg_cat = inst_cat
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2865
                        else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2866
                                pkg_cat = known_cat
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2867
                elif installed:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2868
                        pkg_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2869
                            self._img.IMG_CATALOG_INSTALLED)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2870
                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2871
                        pkg_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2872
                            self._img.IMG_CATALOG_KNOWN)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2873
                return sorted(pkg_cat.categories(excludes=excludes, pubs=pubs))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2874
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  2875
        def __map_installed_newest(self, pubs, known_cat=None):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2876
                """Private function.  Maps incorporations and publisher
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2877
                relationships for installed packages and returns them
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2878
                as a tuple of (pub_ranks, inc_stems, inc_vers, inst_stems,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2879
                ren_stems, ren_inst_stems).
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2880
                """
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2881
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2882
                img_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2883
                    self._img.IMG_CATALOG_INSTALLED)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2884
                cat_info = frozenset([img_cat.DEPENDENCY])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2885
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2886
                inst_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2887
                ren_inst_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2888
                ren_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2889
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2890
                inc_stems = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2891
                inc_vers = {}
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2892
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2893
                pub_ranks = self._img.get_publisher_ranks()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2894
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
  2895
                # The incorporation list should include all installed,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2896
                # incorporated packages from all publishers.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2897
                for t in img_cat.entry_actions(cat_info):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2898
                        (pub, stem, ver), entry, actions = t
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2899
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2900
                        inst_stems[stem] = ver
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2901
                        pkgr = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2902
                        targets = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2903
                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2904
                                for a in actions:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2905
                                        if a.name == "set" and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2906
                                            a.attrs["name"] == "pkg.renamed":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2907
                                                pkgr = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2908
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2909
                                        elif a.name != "depend":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2910
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2911
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2912
                                        if a.attrs["type"] == "require":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2913
                                                # Because the actions are not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2914
                                                # returned in a guaranteed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2915
                                                # order, the dependencies will
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2916
                                                # have to be recorded for
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2917
                                                # evaluation later.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2918
                                                targets.add(a.attrs["fmri"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2919
                                        elif a.attrs["type"] == "incorporate":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2920
                                                # Record incorporated packages.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2921
                                                tgt = fmri.PkgFmri(
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  2922
                                                    a.attrs["fmri"])
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2923
                                                tver = tgt.version
2638
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  2924
                                                # incorporates without a version
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  2925
                                                # should be ignored.
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  2926
                                                if not tver:
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  2927
                                                        continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2928
                                                over = inc_vers.get(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2929
                                                    tgt.pkg_name, None)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2930
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2931
                                                # In case this package has been
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2932
                                                # incorporated more than once,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2933
                                                # use the newest version.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2934
                                                if over is not None and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2935
                                                    over > tver:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2936
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2937
                                                inc_vers[tgt.pkg_name] = tver
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2938
                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2939
                                # For mapping purposes, ignore unsupported
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2940
                                # (and invalid) actions.  This is necessary so
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2941
                                # that API consumers can discover new package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2942
                                # data that may be needed to perform an upgrade
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2943
                                # so that the API can understand them.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2944
                                pass
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2945
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2946
                        if pkgr:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2947
                                for f in targets:
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  2948
                                        tgt = fmri.PkgFmri(f)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2949
                                        ren_stems[tgt.pkg_name] = stem
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2950
                                        ren_inst_stems.setdefault(stem,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2951
                                            set())
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2952
                                        ren_inst_stems[stem].add(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2953
                                            tgt.pkg_name)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2954
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2955
                def check_stem(t, entry):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2956
                        pub, stem, ver = t
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2957
                        if stem in inst_stems:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2958
                                iver = inst_stems[stem]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2959
                                if stem in ren_inst_stems or \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2960
                                    ver == iver:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2961
                                        # The package has been renamed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2962
                                        # or the entry is for the same
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2963
                                        # version as that which is
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2964
                                        # installed, so doesn't need
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2965
                                        # to be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2966
                                        return False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2967
                                # The package may have been renamed in
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2968
                                # a newer version, so must be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2969
                                return True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2970
                        elif stem in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2971
                                # Package is incorporated, but not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2972
                                # installed, so should be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2973
                                return True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2974
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2975
                        tgt = ren_stems.get(stem, None)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2976
                        while tgt is not None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2977
                                # This seems counter-intuitive, but
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2978
                                # for performance and other reasons,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2979
                                # this stem should only be checked
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2980
                                # for a rename if it is incorporated
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2981
                                # or installed using a previous name.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2982
                                if tgt in inst_stems or \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2983
                                    tgt in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2984
                                        return True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2985
                                tgt = ren_stems.get(tgt, None)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2986
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2987
                        # Package should not be checked.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2988
                        return False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2989
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2990
                if not known_cat:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2991
                        known_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2992
                            self._img.IMG_CATALOG_KNOWN)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2993
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2994
                # Find terminal rename entry for all known packages not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2995
                # rejected by check_stem().
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  2996
                for t, entry, actions in known_cat.entry_actions(cat_info,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2997
                    cb=check_stem, last=True):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2998
                        pkgr = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  2999
                        targets = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3000
                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3001
                                for a in actions:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3002
                                        if a.name == "set" and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3003
                                            a.attrs["name"] == "pkg.renamed":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3004
                                                pkgr = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3005
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3006
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3007
                                        if a.name != "depend":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3008
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3009
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3010
                                        if a.attrs["type"] != "require":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3011
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3012
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3013
                                        # Because the actions are not
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3014
                                        # returned in a guaranteed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3015
                                        # order, the dependencies will
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3016
                                        # have to be recorded for
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3017
                                        # evaluation later.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3018
                                        targets.add(a.attrs["fmri"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3019
                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3020
                                # For mapping purposes, ignore unsupported
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3021
                                # (and invalid) actions.  This is necessary so
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3022
                                # that API consumers can discover new package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3023
                                # data that may be needed to perform an upgrade
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3024
                                # so that the API can understand them.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3025
                                pass
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3026
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3027
                        if pkgr:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3028
                                pub, stem, ver = t
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3029
                                for f in targets:
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  3030
                                        tgt = fmri.PkgFmri(f)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3031
                                        ren_stems[tgt.pkg_name] = stem
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3032
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3033
                # Determine highest ranked publisher for package stems
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3034
                # listed in installed incorporations.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3035
                def pub_order(a, b):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3036
                        return cmp(pub_ranks[a][0], pub_ranks[b][0])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3037
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3038
                for p in sorted(pub_ranks, cmp=pub_order):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3039
                        if pubs and p not in pubs:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3040
                                continue
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3041
                        for stem in known_cat.names(pubs=[p]):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3042
                                if stem in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3043
                                        inc_stems.setdefault(stem, p)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3044
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3045
                return (pub_ranks, inc_stems, inc_vers, inst_stems, ren_stems,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3046
                    ren_inst_stems)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3047
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3048
        def __get_temp_repo_pubs(self, repos):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3049
                """Private helper function to retrieve publisher information
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3050
                from list of temporary repositories.  Caller is responsible
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3051
                for locking."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3052
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3053
                ret_pubs = []
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3054
                for repo_uri in repos:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3055
                        if isinstance(repo_uri, basestring):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3056
                                repo = publisher.RepositoryURI(repo_uri)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3057
                        else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3058
                                # Already a RepositoryURI.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3059
                                repo = repo_uri
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3060
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3061
                        pubs = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3062
                        try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3063
                                pubs = self._img.transport.get_publisherdata(
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  3064
                                    repo, ccancel=self.__check_cancel)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3065
                        except apx.UnsupportedRepositoryOperation:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3066
                                raise apx.RepoPubConfigUnavailable(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3067
                                    location=str(repo))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3068
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3069
                        if not pubs:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3070
                                # Empty repository configuration.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3071
                                raise apx.RepoPubConfigUnavailable(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3072
                                    location=str(repo))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3073
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3074
                        for p in pubs:
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  3075
                                psrepo = p.repository
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3076
                                if not psrepo:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3077
                                        # Repository configuration info wasn't
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3078
                                        # provided, so assume origin is
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3079
                                        # repo_uri.
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  3080
                                        p.repository = publisher.Repository(
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  3081
                                            origins=[repo_uri])
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3082
                                elif not psrepo.origins:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3083
                                        # Repository configuration was provided,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3084
                                        # but without an origin.  Assume the
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3085
                                        # repo_uri is the origin.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3086
                                        psrepo.add_origin(repo_uri)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3087
                                elif repo not in psrepo.origins:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3088
                                        # If the repo_uri used is not
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3089
                                        # in the list of sources, then
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3090
                                        # add it as the first origin.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3091
                                        psrepo.origins.insert(0, repo)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3092
                        ret_pubs.extend(pubs)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3093
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3094
                return sorted(ret_pubs)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3095
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3096
        def __get_alt_pkg_data(self, repos):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3097
                """Private helper function to retrieve composite known and
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3098
                installed catalog and package repository map for temporary
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3099
                set of package repositories.  Returns (pkg_pub_map, alt_pubs,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3100
                known_cat, inst_cat)."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3101
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3102
                repos = set(repos)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3103
                eid = ",".join(sorted(map(str, repos)))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3104
                try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3105
                        return self.__alt_sources[eid]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3106
                except KeyError:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3107
                        # Need to cache new set of alternate sources.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3108
                        pass
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3109
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3110
                img_inst_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3111
                    self._img.IMG_CATALOG_INSTALLED)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3112
                op_time = datetime.datetime.utcnow()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3113
                pubs = self.__get_temp_repo_pubs(repos)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3114
                progtrack = self.__progresstracker
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3115
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3116
                # Create temporary directories.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3117
                tmpdir = tempfile.mkdtemp()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3118
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3119
                pkg_repos = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3120
                pkg_pub_map = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3121
                try:
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  3122
                        progtrack.refresh_start(len(pubs), full_refresh=False)
2808
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3123
                        failed = []
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3124
                        pub_cats = []
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3125
                        for pub in pubs:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3126
                                # Assign a temporary meta root to each
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3127
                                # publisher.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3128
                                meta_root = os.path.join(tmpdir, str(id(pub)))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3129
                                misc.makedirs(meta_root)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3130
                                pub.meta_root = meta_root
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3131
                                pub.transport = self._img.transport
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  3132
                                repo = pub.repository
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3133
                                pkg_repos[id(repo)] = repo
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3134
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3135
                                # Retrieve each publisher's catalog.
2693
cfee571ea6d5 7154388 Progress tracking API and functionality improvements
Dan Price <daniel.price@oracle.com>
parents: 2690
diff changeset
  3136
                                progtrack.refresh_start_pub(pub)
2808
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3137
                                try:
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3138
                                        pub.refresh()
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3139
                                except apx.PermissionsException, e:
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3140
                                        failed.append((pub, e))
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3141
                                        # No point in continuing since no data
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3142
                                        # can be written.
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3143
                                        break
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3144
                                except apx.ApiException, e:
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3145
                                        failed.append((pub, e))
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3146
                                        continue
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3147
                                finally:
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3148
                                        progtrack.refresh_end_pub(pub)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3149
                                pub_cats.append((
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3150
                                    pub.prefix,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3151
                                    repo,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3152
                                    pub.catalog
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3153
                                ))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3154
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3155
                        progtrack.refresh_done()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3156
2808
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3157
                        if failed:
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3158
                                total = len(pub_cats) + len(failed)
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3159
                                e = apx.CatalogRefreshException(failed, total,
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3160
                                    len(pub_cats))
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3161
                                raise e
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3162
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3163
                        # Determine upgradability.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3164
                        newest = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3165
                        for pfx, repo, cat in [(None, None, img_inst_cat)] + \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3166
                            pub_cats:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3167
                                if pfx:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3168
                                        pkg_list = cat.fmris(last=True,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3169
                                            pubs=[pfx])
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3170
                                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3171
                                        pkg_list = cat.fmris(last=True)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3172
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3173
                                for f in pkg_list:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3174
                                        nver, snver = newest.get(f.pkg_name,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3175
                                            (None, None))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3176
                                        if f.version > nver:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3177
                                                newest[f.pkg_name] = (f.version,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3178
                                                    str(f.version))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3179
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3180
                        # Build list of installed packages.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3181
                        inst_stems = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3182
                        for t, entry in img_inst_cat.tuple_entries():
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3183
                                states = entry["metadata"]["states"]
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3184
                                if pkgdefs.PKG_STATE_INSTALLED not in states:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3185
                                        continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3186
                                pub, stem, ver = t
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3187
                                inst_stems.setdefault(pub, {})
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3188
                                inst_stems[pub].setdefault(stem, {})
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3189
                                inst_stems[pub][stem][ver] = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3190
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3191
                        # Now create composite known and installed catalogs.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3192
                        compicat = pkg.catalog.Catalog(batch_mode=True,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3193
                            sign=False)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3194
                        compkcat = pkg.catalog.Catalog(batch_mode=True,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3195
                            sign=False)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3196
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3197
                        sparts = (
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3198
                           (pfx, cat, repo, name, cat.get_part(name, must_exist=True))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3199
                           for pfx, repo, cat in pub_cats
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3200
                           for name in cat.parts
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3201
                        )
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3202
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3203
                        excludes = self._img.list_excludes()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3204
                        proc_stems = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3205
                        for pfx, cat, repo, name, spart in sparts:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3206
                                # 'spart' is the source part.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3207
                                if spart is None:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3208
                                        # Client hasn't retrieved this part.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3209
                                        continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3210
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3211
                                # New known part.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3212
                                nkpart = compkcat.get_part(name)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3213
                                nipart = compicat.get_part(name)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3214
                                base = name.startswith("catalog.base.")
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3215
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3216
                                # Avoid accessor overhead since these will be
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3217
                                # used for every entry.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3218
                                cat_ver = cat.version
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3219
                                dp = cat.get_part("catalog.dependency.C",
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3220
                                    must_exist=True)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3221
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3222
                                for t, sentry in spart.tuple_entries(pubs=[pfx]):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3223
                                        pub, stem, ver = t
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3224
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3225
                                        pkg_pub_map.setdefault(pub, {})
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3226
                                        pkg_pub_map[pub].setdefault(stem, {})
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3227
                                        pkg_pub_map[pub][stem].setdefault(ver,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3228
                                            set())
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3229
                                        pkg_pub_map[pub][stem][ver].add(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3230
                                            id(repo))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3231
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3232
                                        if pub in proc_stems and \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3233
                                            stem in proc_stems[pub] and \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3234
                                            ver in proc_stems[pub][stem]:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3235
                                                if id(cat) != proc_stems[pub][stem][ver]:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3236
                                                        # Already added from another
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3237
                                                        # catalog.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3238
                                                        continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3239
                                        else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3240
                                                proc_stems.setdefault(pub, {})
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3241
                                                proc_stems[pub].setdefault(stem,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3242
                                                    {})
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3243
                                                proc_stems[pub][stem][ver] = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3244
                                                    id(cat)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3245
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3246
                                        installed = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3247
                                        if pub in inst_stems and \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3248
                                            stem in inst_stems[pub] and \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3249
                                            ver in inst_stems[pub][stem]:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3250
                                                installed = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3251
                                                inst_stems[pub][stem][ver] = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3252
                                                    True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3253
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3254
                                        # copy() is too slow here and catalog
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3255
                                        # entries are shallow so this should be
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3256
                                        # sufficient.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3257
                                        entry = dict(sentry.iteritems())
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3258
                                        if not base:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3259
                                                # Nothing else to do except add
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3260
                                                # the entry for non-base catalog
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3261
                                                # parts.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3262
                                                nkpart.add(metadata=entry,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3263
                                                    op_time=op_time, pub=pub,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3264
                                                    stem=stem, ver=ver)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3265
                                                if installed:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3266
                                                        nipart.add(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3267
                                                            metadata=entry,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3268
                                                            op_time=op_time,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3269
                                                            pub=pub, stem=stem,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3270
                                                            ver=ver)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3271
                                                continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3272
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3273
                                        # Only the base catalog part stores
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3274
                                        # package state information and/or
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3275
                                        # other metadata.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3276
                                        mdata = entry["metadata"] = {}
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3277
                                        states = [pkgdefs.PKG_STATE_KNOWN,
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3278
                                            pkgdefs.PKG_STATE_ALT_SOURCE]
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3279
                                        if cat_ver == 0:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3280
                                                states.append(
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3281
                                                    pkgdefs.PKG_STATE_V0)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3282
                                        else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3283
                                                # Assume V1 catalog source.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3284
                                                states.append(
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3285
                                                    pkgdefs.PKG_STATE_V1)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3286
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3287
                                        if installed:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3288
                                                states.append(
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3289
                                                    pkgdefs.PKG_STATE_INSTALLED)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3290
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3291
                                        nver, snver = newest.get(stem,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3292
                                            (None, None))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3293
                                        if snver is not None and ver != snver:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3294
                                                states.append(
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3295
                                                    pkgdefs.PKG_STATE_UPGRADABLE)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3296
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3297
                                        # Determine if package is obsolete or
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3298
                                        # has been renamed and mark with
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3299
                                        # appropriate state.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3300
                                        dpent = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3301
                                        if dp is not None:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3302
                                                dpent = dp.get_entry(pub=pub,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3303
                                                    stem=stem, ver=ver)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3304
                                        if dpent is not None:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3305
                                                for a in dpent["actions"]:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3306
                                                        # Constructing action
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3307
                                                        # objects for every
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3308
                                                        # action would be a lot
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3309
                                                        # slower, so a simple
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3310
                                                        # string match is done
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3311
                                                        # first so that only
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3312
                                                        # interesting actions
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3313
                                                        # get constructed.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3314
                                                        if not a.startswith("set"):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3315
                                                                continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3316
                                                        if not ("pkg.obsolete" in a or \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3317
                                                            "pkg.renamed" in a):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3318
                                                                continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3319
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3320
                                                        try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3321
                                                                act = pkg.actions.fromstr(a)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3322
                                                        except pkg.actions.ActionError:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3323
                                                                # If the action can't be
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3324
                                                                # parsed or is not yet
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3325
                                                                # supported, continue.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3326
                                                                continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3327
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3328
                                                        if act.attrs["value"].lower() != "true":
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3329
                                                                continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3330
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3331
                                                        if act.attrs["name"] == "pkg.obsolete":
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3332
                                                                states.append(
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3333
                                                                    pkgdefs.PKG_STATE_OBSOLETE)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3334
                                                        elif act.attrs["name"] == "pkg.renamed":
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3335
                                                                if not act.include_this(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3336
                                                                    excludes):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3337
                                                                        continue
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3338
                                                                states.append(
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3339
                                                                    pkgdefs.PKG_STATE_RENAMED)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3340
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3341
                                        mdata["states"] = states
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3342
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3343
                                        # Add base entries.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3344
                                        nkpart.add(metadata=entry,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3345
                                            op_time=op_time, pub=pub, stem=stem,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3346
                                            ver=ver)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3347
                                        if installed:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3348
                                                nipart.add(metadata=entry,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3349
                                                    op_time=op_time, pub=pub,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3350
                                                    stem=stem, ver=ver)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3351
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3352
                        pub_map = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3353
                        for pub in pubs:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3354
                                try:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3355
                                        opub = pub_map[pub.prefix]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3356
                                except KeyError:
2862
1ec958dbd40a 15949886 pkg traceback when using -g for repository with no packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2847
diff changeset
  3357
                                        nrepo = publisher.Repository()
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3358
                                        opub = publisher.Publisher(pub.prefix,
2808
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3359
                                            catalog=compkcat, repository=nrepo)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3360
                                        pub_map[pub.prefix] = opub
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3361
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3362
                        rid_map = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3363
                        for pub in pkg_pub_map:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3364
                                for stem in pkg_pub_map[pub]:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3365
                                        for ver in pkg_pub_map[pub][stem]:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3366
                                                rids = tuple(sorted(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3367
                                                    pkg_pub_map[pub][stem][ver]))
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3368
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3369
                                                if not rids in rid_map:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3370
                                                        # Create a publisher and
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3371
                                                        # repository for this
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3372
                                                        # unique set of origins.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3373
                                                        origins = []
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3374
                                                        map(origins.extend, [
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3375
                                                           pkg_repos.get(rid).origins
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3376
                                                           for rid in rids
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3377
                                                        ])
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3378
                                                        npub = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3379
                                                            copy.copy(pub_map[pub])
2808
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3380
                                                        nrepo = npub.repository
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3381
                                                        nrepo.origins = origins
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3382
                                                        assert npub.catalog == \
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3383
                                                            compkcat
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3384
                                                        rid_map[rids] = npub
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3385
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3386
                                                pkg_pub_map[pub][stem][ver] = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3387
                                                    rid_map[rids]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3388
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3389
                        # Now consolidate all origins for each publisher under
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3390
                        # a single repository object for the caller.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3391
                        for pub in pubs:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3392
                                npub = pub_map[pub.prefix]
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  3393
                                nrepo = npub.repository
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  3394
                                for o in pub.repository.origins:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3395
                                        if not nrepo.has_origin(o):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3396
                                                nrepo.add_origin(o)
2808
05c6015a8c62 7195369 corrupt manifests can end up on disk when -g is used
Dan Price <daniel.price@oracle.com>
parents: 2773
diff changeset
  3397
                                assert npub.catalog == compkcat
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3398
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3399
                        for compcat in (compicat, compkcat):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3400
                                compcat.batch_mode = False
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3401
                                compcat.finalize()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3402
                                compcat.read_only = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3403
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3404
                        # Cache these for future callers.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3405
                        self.__alt_sources[eid] = (pkg_pub_map,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3406
                            sorted(pub_map.values()), compkcat, compicat)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3407
                        return self.__alt_sources[eid]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3408
                finally:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3409
                        shutil.rmtree(tmpdir, ignore_errors=True)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3410
                        self._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3411
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3412
        @_LockedGenerator()
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3413
        def get_pkg_list(self, pkg_list, cats=None, collect_attrs=False,
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3414
            patterns=misc.EmptyI, pubs=misc.EmptyI, raise_unmatched=False,
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3415
            ranked=False, repos=None, return_fmris=False, variants=False):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3416
                """A generator function that produces tuples of the form:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3417
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3418
                    (
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3419
                        (
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3420
                            pub,    - (string) the publisher of the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3421
                            stem,   - (string) the name of the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3422
                            version - (string) the version of the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3423
                        ),
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3424
                        summary,    - (string) the package summary
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3425
                        categories, - (list) string tuples of (scheme, category)
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3426
                        states,     - (list) PackageInfo states
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3427
                        attributes  - (dict) package attributes
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3428
                    )
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3429
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3430
                Results are always sorted by stem, publisher, and then in
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3431
                descending version order.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3432
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3433
                'pkg_list' is one of the following constant values indicating
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3434
                what base set of package data should be used for results:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3435
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3436
                        LIST_ALL
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3437
                                All known packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3438
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3439
                        LIST_INSTALLED
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3440
                                Installed packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3441
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3442
                        LIST_INSTALLED_NEWEST
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3443
                                Installed packages and the newest
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3444
                                versions of packages not installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3445
                                Renamed packages that are listed in
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3446
                                an installed incorporation will be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3447
                                excluded unless they are installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3448
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3449
                        LIST_NEWEST
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3450
                                The newest versions of all known packages
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3451
                                that match the provided patterns and
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3452
                                other criteria.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3453
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3454
                        LIST_UPGRADABLE
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3455
                                Packages that are installed and upgradable.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3456
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3457
                'cats' is an optional list of package category tuples of the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3458
                form (scheme, cat) to restrict the results to.  If a package
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3459
                is assigned to any of the given categories, it will be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3460
                returned.  A value of [] will return packages not assigned
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3461
                to any package category.  A value of None indicates that no
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3462
                package category filtering should be applied.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3463
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3464
                'collect_attrs' is an optional boolean that indicates whether
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3465
                all package attributes should be collected and returned in the
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3466
                fifth element of the return tuple.  If False, that element will
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3467
                be an empty dictionary.
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3468
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3469
                'patterns' is an optional list of FMRI wildcard strings to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3470
                filter results by.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3471
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3472
                'pubs' is an optional list of publisher prefixes to restrict
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3473
                the results to.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3474
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3475
                'raise_unmatched' is an optional boolean value that indicates
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3476
                whether an InventoryException should be raised if any patterns
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3477
                (after applying all other filtering and returning all results)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3478
                didn't match any packages.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3479
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3480
                'ranked' is an optional boolean value that indicates whether
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3481
                only the matching package versions from the highest-ranked
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3482
                publisher should be returned.  This option is ignored for
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3483
                patterns that explicitly specify the publisher to match.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3484
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3485
                'repos' is a list of URI strings or RepositoryURI objects that
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3486
                represent the locations of package repositories to list packages
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3487
                for.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3488
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3489
                'return_fmris' is an optional boolean value that indicates that
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3490
                an FMRI object should be returned in place of the (pub, stem,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3491
                ver) tuple that is normally returned.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3492
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3493
                'variants' is an optional boolean value that indicates that
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3494
                packages that are for arch or zone variants not applicable to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3495
                this image should be returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3496
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3497
                Please note that this function may invoke network operations
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3498
                to retrieve the requested package information."""
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3499
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3500
                return self.__get_pkg_list(pkg_list, cats=cats,
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3501
                    collect_attrs=collect_attrs, patterns=patterns, pubs=pubs,
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3502
                    raise_unmatched=raise_unmatched, ranked=ranked, repos=repos,
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3503
                    return_fmris=return_fmris, variants=variants)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3504
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3505
        def __get_pkg_list(self, pkg_list, cats=None, collect_attrs=False,
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3506
            inst_cat=None, known_cat=None, patterns=misc.EmptyI,
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3507
            pubs=misc.EmptyI, raise_unmatched=False, ranked=False, repos=None,
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3508
            return_fmris=False, variants=False):
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3509
                """This is the implementation of get_pkg_list.  The other
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3510
                function is a wrapper that uses locking.  The separation was
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3511
                necessary because of API functions that already perform locking
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3512
                but need to use get_pkg_list().  This is a generator
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3513
                function."""
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3514
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3515
                installed = inst_newest = newest = upgradable = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3516
                if pkg_list == self.LIST_INSTALLED:
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3517
                        installed = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3518
                elif pkg_list == self.LIST_INSTALLED_NEWEST:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3519
                        inst_newest = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3520
                elif pkg_list == self.LIST_NEWEST:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3521
                        newest = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3522
                elif pkg_list == self.LIST_UPGRADABLE:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3523
                        upgradable = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3524
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3525
                # Each pattern in patterns can be a partial or full FMRI, so
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3526
                # extract the individual components for use in filtering.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3527
                illegals = []
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3528
                pat_tuples = {}
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3529
                pat_versioned = False
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3530
                latest_pats = set()
2260
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3531
                seen = set()
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3532
                npatterns = set()
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3533
                for pat, error, pfmri, matcher in self.parse_fmri_patterns(
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3534
                    patterns):
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3535
                        if error:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3536
                                illegals.append(error)
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3537
                                continue
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3538
2260
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3539
                        # Duplicate patterns are ignored.
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3540
                        sfmri = str(pfmri)
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3541
                        if sfmri in seen:
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3542
                                # A different form of the same pattern
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3543
                                # was specified already; ignore this
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3544
                                # one (e.g. pkg:/network/ping,
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3545
                                # /network/ping).
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3546
                                continue
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3547
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3548
                        # Track used patterns.
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3549
                        seen.add(sfmri)
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3550
                        npatterns.add(pat)
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3551
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3552
                        if "@" in pat:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3553
                                # Mark that a pattern contained version
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3554
                                # information.  This is used for a listing
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3555
                                # optimization later on.
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3556
                                pat_versioned = True
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3557
                        if getattr(pfmri.version, "match_latest", None):
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3558
                                latest_pats.add(pat)
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3559
                        pat_tuples[pat] = (pfmri.tuple(), matcher)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3560
2260
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3561
                patterns = npatterns
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3562
                del npatterns, seen
ea8567aa3ef8 17944 specifying multiple forms of the same pattern should not result in a matching error
Shawn Walker <shawn.walker@oracle.com>
parents: 2228
diff changeset
  3563
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3564
                if illegals:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3565
                        raise apx.InventoryException(illegal=illegals)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3566
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3567
                if repos:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3568
                        ignored, ignored, known_cat, inst_cat = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3569
                            self.__get_alt_pkg_data(repos)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3570
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3571
                # For LIST_INSTALLED_NEWEST, installed packages need to be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3572
                # determined and incorporation and publisher relationships
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3573
                # mapped.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3574
                if inst_newest:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3575
                        pub_ranks, inc_stems, inc_vers, inst_stems, ren_stems, \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3576
                            ren_inst_stems = self.__map_installed_newest(
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  3577
                            pubs, known_cat=known_cat)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3578
                else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3579
                        pub_ranks = inc_stems = inc_vers = inst_stems = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3580
                            ren_stems = ren_inst_stems = misc.EmptyDict
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3581
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3582
                if installed or upgradable:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3583
                        if inst_cat:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3584
                                pkg_cat = inst_cat
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3585
                        else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3586
                                pkg_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3587
                                    self._img.IMG_CATALOG_INSTALLED)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3588
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3589
                        # Don't need to perform variant filtering if only
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3590
                        # listing installed packages.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3591
                        variants = True
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3592
                elif known_cat:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3593
                        pkg_cat = known_cat
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3594
                else:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3595
                        pkg_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3596
                            self._img.IMG_CATALOG_KNOWN)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3597
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3598
                cat_info = frozenset([pkg_cat.DEPENDENCY, pkg_cat.SUMMARY])
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3599
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3600
                # Keep track of when the newest version has been found for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3601
                # each incorporated stem.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3602
                slist = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3603
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3604
                # Keep track of listed stems for all other packages on a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3605
                # per-publisher basis.
1853
8f8a90301844 15234 "pkg list -a" doesn't account for pattern versions
Shawn Walker <shawn.walker@oracle.com>
parents: 1843
diff changeset
  3606
                nlist = collections.defaultdict(int)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3607
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3608
                def check_state(t, entry):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3609
                        states = entry["metadata"]["states"]
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3610
                        pkgi = pkgdefs.PKG_STATE_INSTALLED in states
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3611
                        pkgu = pkgdefs.PKG_STATE_UPGRADABLE in states
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3612
                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3613
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3614
                        if upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3615
                                # If package is marked upgradable, return it.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3616
                                return pkgu
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3617
                        elif pkgi:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3618
                                # Nothing more to do here.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3619
                                return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3620
                        elif stem in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3621
                                # Some other version of this package is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3622
                                # installed, so this one should not be
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3623
                                # returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3624
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3625
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3626
                        # Attempt to determine if this package is installed
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3627
                        # under a different name or constrained under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3628
                        # different name.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3629
                        tgt = ren_stems.get(stem, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3630
                        while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3631
                                if tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3632
                                        # Package is incorporated under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3633
                                        # different name, so allow this
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3634
                                        # to fallthrough to the incoporation
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3635
                                        # evaluation.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3636
                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3637
                                elif tgt in inst_stems:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3638
                                        # Package is installed under a
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3639
                                        # different name, so skip it.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3640
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3641
                                tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3642
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3643
                        # Attempt to find a suitable version to return.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3644
                        if stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3645
                                # For package stems that are incorporated, only
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3646
                                # return the newest successor version  based on
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3647
                                # publisher rank.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3648
                                if stem in slist:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3649
                                        # Newest version already returned.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3650
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3651
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3652
                                if stem in inc_stems and \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3653
                                    pub != inc_stems[stem]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3654
                                        # This entry is for a lower-ranked
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3655
                                        # publisher.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3656
                                        return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3657
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3658
                                # XXX version should not require build release.
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  3659
                                ever = pkg.version.Version(ver)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3660
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3661
                                # If the entry's version is a successor to
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3662
                                # the incorporated version, then this is the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3663
                                # 'newest' version of this package since
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3664
                                # entries are processed in descending version
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3665
                                # order.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3666
                                iver = inc_vers[stem]
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3667
                                if ever.is_successor(iver,
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3668
                                    pkg.version.CONSTRAINT_AUTO):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3669
                                        slist.add(stem)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3670
                                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3671
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3672
1853
8f8a90301844 15234 "pkg list -a" doesn't account for pattern versions
Shawn Walker <shawn.walker@oracle.com>
parents: 1843
diff changeset
  3673
                        pkg_stem = "!".join((pub, stem))
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3674
                        if pkg_stem in nlist:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3675
                                # A newer version has already been listed for
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3676
                                # this stem and publisher.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3677
                                return False
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3678
                        return True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3679
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3680
                filter_cb = None
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3681
                if inst_newest or upgradable:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3682
                        # Filtering needs to be applied.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3683
                        filter_cb = check_state
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3684
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3685
                excludes = self._img.list_excludes()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3686
                img_variants = self._img.get_variants()
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3687
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3688
                matched_pats = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3689
                pkg_matching_pats = None
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3690
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3691
                # Retrieve only the newest package versions for LIST_NEWEST if
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3692
                # none of the patterns have version information and variants are
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3693
                # included.  (This cuts down on the number of entries that have
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3694
                # to be filtered.)
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3695
                use_last = newest and not pat_versioned and variants
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3696
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3697
                if ranked:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3698
                        # If caller requested results to be ranked by publisher,
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3699
                        # then the list of publishers to return must be passed
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3700
                        # to entry_actions() in rank order.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3701
                        pub_ranks = self._img.get_publisher_ranks()
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3702
                        if not pubs:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3703
                                # It's important that the list of possible
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3704
                                # publishers is gleaned from the catalog
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3705
                                # directly and not image configuration so
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3706
                                # that temporary sources (archives, etc.)
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3707
                                # work as expected.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3708
                                pubs = pkg_cat.publishers()
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3709
                        for p in pubs:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3710
                                pub_ranks.setdefault(p, (99, (p, False, False)))
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3711
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3712
                        def pub_order(a, b):
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3713
                                res = cmp(pub_ranks[a], pub_ranks[b])
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3714
                                if res != 0:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3715
                                        return res
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3716
                                return cmp(a, b)
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3717
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3718
                        pubs = sorted(pubs, cmp=pub_order)
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3719
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3720
                ranked_stems = {}
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  3721
                for t, entry, actions in pkg_cat.entry_actions(cat_info,
2024
95751b5fb20b 16651 can't access versions of packages other than newest for list -n, info -r, and contents -r
Shawn Walker <shawn.walker@oracle.com>
parents: 1970
diff changeset
  3722
                    cb=filter_cb, excludes=excludes, last=use_last,
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3723
                    ordered=True, pubs=pubs):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3724
                        pub, stem, ver = t
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3725
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3726
                        omit_ver = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3727
                        omit_package = None
2033
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3728
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3729
                        pkg_stem = "!".join((pub, stem))
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3730
                        if newest and pkg_stem in nlist:
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3731
                                # A newer version has already been listed, so
2033
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3732
                                # any additional entries need to be marked for
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3733
                                # omission before continuing.
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3734
                                omit_package = True
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3735
                        elif ranked and not patterns and \
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3736
                            ranked_stems.get(stem, pub) != pub:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3737
                                # A different version from a higher-ranked
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3738
                                # publisher has been returned already, so skip
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3739
                                # this one.  This can only be done safely at
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3740
                                # this point if no patterns have been specified,
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3741
                                # since publisher-specific patterns override
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3742
                                # ranking behaviour.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3743
                                omit_package = True
2033
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3744
                        else:
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3745
                                nlist[pkg_stem] += 1
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3746
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3747
                        if raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3748
                                pkg_matching_pats = set()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3749
                        if not omit_package:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3750
                                ever = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3751
                                for pat in patterns:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3752
                                        (pat_pub, pat_stem, pat_ver), matcher = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3753
                                            pat_tuples[pat]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3754
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3755
                                        if pat_pub is not None and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3756
                                            pub != pat_pub:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3757
                                                # Publisher doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3758
                                                if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3759
                                                        omit_package = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3760
                                                continue
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3761
                                        elif ranked and not pat_pub and \
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3762
                                            ranked_stems.get(stem, pub) != pub:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3763
                                                # A different version from a
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3764
                                                # higher-ranked publisher has
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3765
                                                # been returned already, so skip
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3766
                                                # this one since no publisher
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3767
                                                # was specified for the pattern.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3768
                                                if omit_package is None:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3769
                                                        omit_package = True
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3770
                                                continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3771
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3772
                                        if matcher == self.MATCH_EXACT:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3773
                                                if pat_stem != stem:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3774
                                                        # Stem doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3775
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3776
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3777
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3778
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3779
                                        elif matcher == self.MATCH_FMRI:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3780
                                                if not ("/" + stem).endswith(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3781
                                                    "/" + pat_stem):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3782
                                                        # Stem doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3783
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3784
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3785
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3786
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3787
                                        elif matcher == self.MATCH_GLOB:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3788
                                                if not fnmatch.fnmatchcase(stem,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3789
                                                    pat_stem):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3790
                                                        # Stem doesn't match.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3791
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3792
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3793
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3794
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3795
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3796
                                        if pat_ver is not None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3797
                                                if ever is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3798
                                                        # Avoid constructing a
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3799
                                                        # version object more
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3800
                                                        # than once for each
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3801
                                                        # entry.
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  3802
                                                        ever = pkg.version.Version(ver)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3803
                                                if not ever.is_successor(pat_ver,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3804
                                                    pkg.version.CONSTRAINT_AUTO):
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3805
                                                        if omit_package is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3806
                                                                omit_package = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3807
                                                                    True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3808
                                                        omit_ver = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3809
                                                        continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3810
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3811
                                        if pat in latest_pats and \
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3812
                                            nlist[pkg_stem] > 1:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3813
                                                # Package allowed by pattern,
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3814
                                                # but isn't the "latest"
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3815
                                                # version.
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3816
                                                if omit_package is None:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3817
                                                        omit_package = True
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3818
                                                omit_ver = True
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3819
                                                continue
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  3820
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3821
                                        # If this entry matched at least one
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3822
                                        # pattern, then ensure it is returned.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3823
                                        omit_package = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3824
                                        if not raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3825
                                                # It's faster to stop as soon
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3826
                                                # as a match is found.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3827
                                                break
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3828
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3829
                                        # If caller has requested other match
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3830
                                        # cases be raised as an exception, then
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3831
                                        # all patterns must be tested for every
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3832
                                        # entry.  This is slower, so only done
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3833
                                        # if necessary.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3834
                                        pkg_matching_pats.add(pat)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3835
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3836
                        if omit_package:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3837
                                # Package didn't match critera; skip it.
2033
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3838
                                if (filter_cb is not None or (newest and
601cc09f180a 16811 get_pkg_list LIST_NEWEST returns all matching instead of newest matching version
Shawn Walker <shawn.walker@oracle.com>
parents: 2028
diff changeset
  3839
                                    pat_versioned)) and omit_ver and \
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3840
                                    nlist[pkg_stem] == 1:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3841
                                        # If omitting because of version, and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3842
                                        # no other versions have been returned
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3843
                                        # yet for this stem, then discard
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3844
                                        # tracking entry so that other
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3845
                                        # versions will be listed.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3846
                                        del nlist[pkg_stem]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3847
                                        slist.discard(stem)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3848
                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3849
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3850
                        # Perform image arch and zone variant filtering so
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3851
                        # that only packages appropriate for this image are
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3852
                        # returned, but only do this for packages that are
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3853
                        # not installed.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3854
                        pcats = []
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3855
                        pkgr = False
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3856
                        unsupported = False
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3857
                        summ = None
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3858
                        targets = set()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3859
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3860
                        omit_var = False
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3861
                        states = entry["metadata"]["states"]
2616
3c00fe4465d3 19148 PKG_STATE_* defines need a new home
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2612
diff changeset
  3862
                        pkgi = pkgdefs.PKG_STATE_INSTALLED in states
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3863
                        ddm = lambda: collections.defaultdict(list)
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3864
                        attrs = collections.defaultdict(ddm)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3865
                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3866
                                for a in actions:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3867
                                        if a.name == "depend" and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3868
                                            a.attrs["type"] == "require":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3869
                                                targets.add(a.attrs["fmri"])
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3870
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3871
                                        if a.name != "set":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3872
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3873
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3874
                                        atname = a.attrs["name"]
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3875
                                        atvalue = a.attrs["value"]
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3876
                                        if collect_attrs:
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3877
                                                atvlist = a.attrlist("value")
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3878
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3879
                                                # XXX Need to describe this data
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3880
                                                # structure sanely somewhere.
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3881
                                                mods = tuple(
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3882
                                                    (k, tuple(sorted(a.attrlist(k))))
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3883
                                                    for k in sorted(a.attrs.iterkeys())
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3884
                                                    if k not in ("name", "value")
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3885
                                                )
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3886
                                                attrs[atname][mods].extend(atvlist)
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3887
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3888
                                        if atname == "pkg.summary":
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3889
                                                summ = atvalue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3890
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3891
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3892
                                        if atname == "description":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3893
                                                if summ is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3894
                                                        # Historical summary
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3895
                                                        # field.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3896
                                                        summ = atvalue
2828
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
  3897
                                                        # pylint: disable=W0106
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3898
                                                        collect_attrs and \
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3899
                                                            attrs["pkg.summary"] \
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3900
                                                            [mods]. \
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  3901
                                                            extend(atvlist)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3902
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3903
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3904
                                        if atname == "info.classification":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3905
                                                pcats.extend(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3906
                                                    a.parse_category_info())
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3907
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3908
                                        if pkgi:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3909
                                                # No filtering for installed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3910
                                                # packages.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3911
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3912
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3913
                                        # Rename filtering should only be
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3914
                                        # performed for incorporated packages
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3915
                                        # at this point.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3916
                                        if atname == "pkg.renamed":
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3917
                                                if stem in inc_vers:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3918
                                                        pkgr = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3919
                                                continue
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3920
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3921
                                        if variants or \
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3922
                                            not atname.startswith("variant."):
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3923
                                                # No variant filtering required.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3924
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3925
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3926
                                        # For all variants explicitly set in the
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3927
                                        # image, elide packages that are not for
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3928
                                        # a matching variant value.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3929
                                        is_list = type(atvalue) == list
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3930
                                        for vn, vv in img_variants.iteritems():
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3931
                                                if vn == atname and \
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3932
                                                    ((is_list and
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3933
                                                    vv not in atvalue) or \
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3934
                                                    (not is_list and
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3935
                                                    vv != atvalue)):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3936
                                                        omit_package = True
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3937
                                                        omit_var = True
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3938
                                                        break
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3939
                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3940
                                # Ignore errors for packages that have invalid
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3941
                                # or unsupported metadata.  This is necessary so
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3942
                                # that API consumers can discover new package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3943
                                # data that may be needed to perform an upgrade
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3944
                                # so that the API can understand them.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3945
                                states = set(states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3946
                                states.add(PackageInfo.UNSUPPORTED)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3947
                                unsupported = True
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3948
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3949
                        if not pkgi and pkgr and stem in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3950
                                # If the package is not installed, but this is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3951
                                # the terminal version entry for the stem and
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3952
                                # it is an incorporated package, then omit the
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3953
                                # package if it has been installed or is
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3954
                                # incorporated using one of the new names.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3955
                                for e in targets:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3956
                                        tgt = e
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3957
                                        while tgt is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3958
                                                if tgt in ren_inst_stems or \
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3959
                                                    tgt in inc_vers:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3960
                                                        omit_package = True
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3961
                                                        break
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3962
                                                tgt = ren_stems.get(tgt, None)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3963
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3964
                        if omit_package:
2212
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3965
                                # Package didn't match criteria; skip it.
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3966
                                if (filter_cb is not None or newest) and \
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3967
                                    omit_var and nlist[pkg_stem] == 1:
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3968
                                        # If omitting because of variant, and
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3969
                                        # no other versions have been returned
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3970
                                        # yet for this stem, then discard
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3971
                                        # tracking entry so that other
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3972
                                        # versions will be listed.
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3973
                                        del nlist[pkg_stem]
9936333985a6 738 "install world" for pkg
Shawn Walker <shawn.walker@oracle.com>
parents: 2207
diff changeset
  3974
                                        slist.discard(stem)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3975
                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3976
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3977
                        if cats is not None:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3978
                                if not cats:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3979
                                        if pcats:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3980
                                                # Only want packages with no
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3981
                                                # categories.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3982
                                                continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3983
                                elif not [sc for sc in cats if sc in pcats]:
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3984
                                        # Package doesn't match specified
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3985
                                        # category criteria.
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3986
                                        continue
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3987
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  3988
                        # Return the requested package data.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3989
                        if not unsupported:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3990
                                # Prevent modification of state data.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3991
                                states = frozenset(states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3992
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3993
                        if raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3994
                                # Only after all other filtering has been
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3995
                                # applied are the patterns that the package
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3996
                                # matched considered "matching".
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  3997
                                matched_pats.update(pkg_matching_pats)
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3998
                        if ranked:
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  3999
                                # Only after all other filtering has been
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4000
                                # applied is the stem considered to have been
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4001
                                # a "ranked" match.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4002
                                ranked_stems.setdefault(stem, pub)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4003
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4004
                        if return_fmris:
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  4005
                                pfmri = fmri.PkgFmri(name=stem, publisher=pub,
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  4006
                                        version=ver)
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4007
                                yield (pfmri, summ, pcats, states, attrs)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4008
                        else:
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4009
                                yield (t, summ, pcats, states, attrs)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4010
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4011
                if raise_unmatched:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4012
                        # Caller has requested that non-matching patterns or
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4013
                        # patterns that match multiple packages cause an
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4014
                        # exception to be raised.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4015
                        notfound = set(pat_tuples.keys()) - matched_pats
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4016
                        if raise_unmatched and notfound:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4017
                                raise apx.InventoryException(notfound=notfound)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  4018
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4019
        @_LockedCancelable()
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4020
        def info(self, fmri_strings, local, info_needed, ranked=False,
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4021
            repos=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4022
                """Gathers information about fmris.  fmri_strings is a list
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4023
                of fmri_names for which information is desired.  local
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  4024
                determines whether to retrieve the information locally
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  4025
                (if possible).  It returns a dictionary of lists.  The keys
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  4026
                for the dictionary are the constants specified in the class
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  4027
                definition.  The values are lists of PackageInfo objects or
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4028
                strings.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4029
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4030
                'ranked' is an optional boolean value that indicates whether
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4031
                only the matching package versions from the highest-ranked
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4032
                publisher should be returned.  This option is ignored for
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4033
                patterns that explicitly specify the publisher to match.
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4034
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4035
                'repos' is a list of URI strings or RepositoryURI objects that
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4036
                represent the locations of packages to return information for.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4037
                """
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4038
917
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  4039
                bad_opts = info_needed - PackageInfo.ALL_OPTIONS
eed22f430a9f 6902 api.info needs a "fast" flag or a way to pass a set of the information required
Brock Pytlik <bpytlik@sun.com>
parents: 884
diff changeset
  4040
                if bad_opts:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4041
                        raise apx.UnrecognizedOptionsToInfo(bad_opts)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4042
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4043
                self.log_operation_start("info")
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4044
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4045
                # Common logic for image and temp repos case.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4046
                if local:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4047
                        ilist = self.LIST_INSTALLED
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4048
                else:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4049
                        # Verify validity of certificates before attempting
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4050
                        # network operations.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4051
                        self.__cert_verify(log_op_end=[apx.CertificateError])
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4052
                        ilist = self.LIST_NEWEST
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4053
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4054
                # The pkg_pub_map is only populated when temp repos are
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4055
                # specified and maps packages to the repositories that
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4056
                # contain them for manifest retrieval.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4057
                pkg_pub_map = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4058
                known_cat = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4059
                inst_cat = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4060
                if repos:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4061
                        pkg_pub_map, ignored, known_cat, inst_cat = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4062
                            self.__get_alt_pkg_data(repos)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4063
                        if local:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4064
                                pkg_cat = inst_cat
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4065
                        else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4066
                                pkg_cat = known_cat
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4067
                elif local:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4068
                        pkg_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4069
                            self._img.IMG_CATALOG_INSTALLED)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4070
                        if not fmri_strings and pkg_cat.package_count == 0:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4071
                                self.log_operation_end(
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4072
                                    result=RESULT_NOTHING_TO_DO)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4073
                                raise apx.NoPackagesInstalledException()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4074
                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4075
                        pkg_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4076
                            self._img.IMG_CATALOG_KNOWN)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4077
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4078
                excludes = self._img.list_excludes()
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4079
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  4080
                # Set of options that can use catalog data.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4081
                cat_opts = frozenset([PackageInfo.DESCRIPTION,
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  4082
                    PackageInfo.DEPENDENCIES])
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4083
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4084
                # Set of options that require manifest retrieval.
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4085
                act_opts = PackageInfo.ACTION_OPTIONS - \
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4086
                    frozenset([PackageInfo.DEPENDENCIES])
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4087
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4088
                collect_attrs = PackageInfo.ALL_ATTRIBUTES in info_needed
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4089
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4090
                pis = []
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4091
                rval = {
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4092
                    self.INFO_FOUND: pis,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4093
                    self.INFO_MISSING: misc.EmptyI,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4094
                    self.INFO_ILLEGALS: misc.EmptyI,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4095
                }
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4096
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4097
                try:
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4098
                        for pfmri, summary, cats, states, attrs in self.__get_pkg_list(
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4099
                            ilist, collect_attrs=collect_attrs,
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4100
                            inst_cat=inst_cat, known_cat=known_cat,
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4101
                            patterns=fmri_strings, raise_unmatched=True,
2547
032eaff05522 17801 contents -r should return only highest-ranked match by default
Shawn Walker <shawn.walker@oracle.com>
parents: 2524
diff changeset
  4102
                            ranked=ranked, return_fmris=True, variants=True):
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4103
                                release = build_release = branch = \
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4104
                                    packaging_date = None
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4105
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4106
                                pub, name, version = pfmri.tuple()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4107
                                alt_pub = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4108
                                if pkg_pub_map:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4109
                                        alt_pub = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4110
                                            pkg_pub_map[pub][name][str(version)]
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4111
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4112
                                if PackageInfo.IDENTITY in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4113
                                        release = version.release
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4114
                                        build_release = version.build_release
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4115
                                        branch = version.branch
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4116
                                        packaging_date = \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4117
                                            version.get_timestamp().strftime(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4118
                                            "%c")
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4119
                                else:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4120
                                        pub = name = version = None
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4121
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4122
                                links = hardlinks = files = dirs = \
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  4123
                                    csize = size = licenses = cat_info = \
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4124
                                    description = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4125
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4126
                                if PackageInfo.CATEGORIES in info_needed:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4127
                                        cat_info = [
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  4128
                                            PackageCategory(scheme, cat)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4129
                                            for scheme, cat in cats
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  4130
                                        ]
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1389
diff changeset
  4131
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4132
                                ret_cat_data = cat_opts & info_needed
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4133
                                dependencies = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4134
                                unsupported = False
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4135
                                if ret_cat_data:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4136
                                        try:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4137
                                                ignored, description, ignored, \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4138
                                                    dependencies = \
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4139
                                                    _get_pkg_cat_data(pkg_cat,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4140
                                                        ret_cat_data,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4141
                                                        excludes=excludes,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4142
                                                        pfmri=pfmri)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4143
                                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4144
                                                # If the information can't be
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4145
                                                # retrieved because the manifest
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4146
                                                # can't be parsed, mark it and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4147
                                                # continue.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4148
                                                unsupported = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4149
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4150
                                if dependencies is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4151
                                        dependencies = misc.EmptyI
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4152
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4153
                                mfst = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4154
                                if not unsupported and \
2183
21ae45e8dfcf 17581 There should be a way of removing a package as part of upgrade
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2158
diff changeset
  4155
                                    (frozenset([PackageInfo.SIZE,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4156
                                    PackageInfo.LICENSES]) | act_opts) & \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4157
                                    info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4158
                                        try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4159
                                                mfst = self._img.get_manifest(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4160
                                                    pfmri, alt_pub=alt_pub)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4161
                                        except apx.InvalidPackageErrors:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4162
                                                # If the information can't be
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4163
                                                # retrieved because the manifest
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4164
                                                # can't be parsed, mark it and
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4165
                                                # continue.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4166
                                                unsupported = True
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4167
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4168
                                if mfst is not None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4169
                                        if PackageInfo.LICENSES in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4170
                                                licenses = self.__licenses(pfmri,
2313
62501ec54db1 18222 pkg info --license can fail with "unknown publisher" when using -g
Shawn Walker <shawn.walker@oracle.com>
parents: 2310
diff changeset
  4171
                                                    mfst, alt_pub=alt_pub)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4172
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4173
                                        if PackageInfo.SIZE in info_needed:
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  4174
                                                size, csize = mfst.get_size(
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4175
                                                    excludes=excludes)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4176
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4177
                                        if act_opts & info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4178
                                                if PackageInfo.LINKS in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4179
                                                        links = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4180
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4181
                                                            "link", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4182
                                                if PackageInfo.HARDLINKS in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4183
                                                        hardlinks = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4184
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4185
                                                            "hardlink", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4186
                                                if PackageInfo.FILES in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4187
                                                        files = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4188
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4189
                                                            "file", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4190
                                                if PackageInfo.DIRS in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4191
                                                        dirs = list(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4192
                                                            mfst.gen_key_attribute_value_by_type(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4193
                                                            "dir", excludes))
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4194
                                elif PackageInfo.SIZE in info_needed:
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  4195
                                        size = csize = 0
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4196
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4197
                                # Trim response set.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4198
                                if PackageInfo.STATE in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4199
                                        if unsupported is True and \
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4200
                                            PackageInfo.UNSUPPORTED not in states:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4201
                                                # Mark package as
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4202
                                                # unsupported so that
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4203
                                                # caller can decide
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4204
                                                # what to do.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4205
                                                states = set(states)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4206
                                                states.add(
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4207
                                                    PackageInfo.UNSUPPORTED)
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4208
                                else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4209
                                        states = misc.EmptyI
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4210
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4211
                                if PackageInfo.CATEGORIES not in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4212
                                        cats = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4213
                                if PackageInfo.SUMMARY in info_needed:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4214
                                        if summary is None:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4215
                                                summary = ""
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4216
                                else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4217
                                        summary = None
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4218
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4219
                                pis.append(PackageInfo(pkg_stem=name,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4220
                                    summary=summary, category_info_list=cat_info,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4221
                                    states=states, publisher=pub, version=release,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4222
                                    build_release=build_release, branch=branch,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4223
                                    packaging_date=packaging_date, size=size,
2910
2bb9f6ffdff9 15654935 pkg facet/variant should also display those implicitly set
Shawn Walker <shawn.walker@oracle.com>
parents: 2862
diff changeset
  4224
                                    csize=csize, pfmri=pfmri, licenses=licenses,
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4225
                                    links=links, hardlinks=hardlinks, files=files,
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4226
                                    dirs=dirs, dependencies=dependencies,
2493
5db1603f0c3f 18609 support for a human-readable version string
Danek Duvall <danek.duvall@oracle.com>
parents: 2488
diff changeset
  4227
                                    description=description, attrs=attrs))
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4228
                except apx.InventoryException, e:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4229
                        if e.illegal:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4230
                                self.log_operation_end(
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4231
                                    result=RESULT_FAILED_BAD_REQUEST)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4232
                        rval[self.INFO_MISSING] = e.notfound
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4233
                        rval[self.INFO_ILLEGALS] = e.illegal
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4234
                else:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4235
                        if pis:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4236
                                self.log_operation_end()
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4237
                        else:
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4238
                                self.log_operation_end(
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4239
                                    result=RESULT_NOTHING_TO_DO)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4240
                return rval
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4241
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4242
        def can_be_canceled(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4243
                """Returns true if the API is in a cancelable state."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4244
                return self.__can_be_canceled
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4245
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4246
        def _disable_cancel(self):
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4247
                """Sets_can_be_canceled to False in a way that prevents missed
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4248
                wakeups.  This may raise CanceledException, if a
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4249
                cancellation is pending."""
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4250
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4251
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4252
                if self.__canceling:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4253
                        self.__cancel_lock.release()
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4254
                        self._img.transport.reset()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4255
                        raise apx.CanceledException()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4256
                else:
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4257
                        self.__set_can_be_canceled(False)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4258
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4259
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4260
        def _enable_cancel(self):
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4261
                """Sets can_be_canceled to True while grabbing the cancel
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4262
                locks.  The caller must still hold the activity lock while
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4263
                calling this function."""
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4264
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4265
                self.__cancel_lock.acquire()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4266
                self.__set_can_be_canceled(True)
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4267
                self.__cancel_lock.release()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4268
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4269
        def __set_can_be_canceled(self, status):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4270
                """Private method. Handles the details of changing the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4271
                cancelable state."""
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4272
                assert self.__cancel_lock._is_owned()
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4273
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4274
                # If caller requests a change to current state there is
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4275
                # nothing to do.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4276
                if self.__can_be_canceled == status:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4277
                        return
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4278
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4279
                if status == True:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4280
                        # Callers must hold activity lock for operations
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4281
                        # that they will make cancelable.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4282
                        assert self._activity_lock._is_owned()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4283
                        # In any situation where the caller holds the activity
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4284
                        # lock and wants to set cancelable to true, a cancel
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4285
                        # should not already be in progress.  This is because
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4286
                        # it should not be possible to invoke cancel until
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4287
                        # this routine has finished.  Assert that we're not
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4288
                        # canceling.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4289
                        assert not self.__canceling
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4290
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4291
                self.__can_be_canceled = status
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4292
                if self.__cancel_state_callable:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4293
                        self.__cancel_state_callable(self.__can_be_canceled)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4294
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4295
        def reset(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4296
                """Resets the API back the the initial state. Note:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4297
                this does not necessarily return the disk to its initial state
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4298
                since the indexes or download cache may have been changed by
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4299
                the prepare method."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4300
                self._acquire_activity_lock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4301
                self.__reset_unlock()
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4302
                self._activity_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4303
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4304
        def __reset_unlock(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4305
                """Private method. Provides a way to reset without taking the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4306
                activity lock. Should only be called by a thread which already
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4307
                holds the activity lock."""
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4308
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4309
                assert self._activity_lock._is_owned()
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  4310
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4311
                # This needs to be done first so that find_root can use it.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4312
                self.__progresstracker.reset()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4313
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4314
                # Ensure alternate sources are always cleared in an
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4315
                # exception scenario.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4316
                self.__set_img_alt_sources(None)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4317
                self.__alt_sources = {}
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4318
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4319
                self._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4320
                self._img.transport.shutdown()
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  4321
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  4322
                # Recreate the image object using the path the api
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  4323
                # object was created with instead of the current path.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4324
                self._img = image.Image(self._img_path,
2158
5a688b5b92a3 15864 inferring image location from current working directory can be harmful
Shawn Walker <shawn.walker@oracle.com>
parents: 2144
diff changeset
  4325
                    progtrack=self.__progresstracker,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4326
                    user_provided_dir=True,
2690
11a8cae074e0 7140224 package downloaded messages displayed twice for each zone
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2683
diff changeset
  4327
                    cmdpath=self.cmdpath)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4328
                self._img.blocking_locks = self.__blocking_locks
1242
f6aa06e1c391 6758 api should recreate image object on reset
Shawn Walker <srw@sun.com>
parents: 1240
diff changeset
  4329
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4330
                lin = None
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4331
                if self._img.linked.ischild():
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4332
                        lin = self._img.linked.child_name
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4333
                self.__progresstracker.set_linked_name(lin)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4334
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4335
                self.__plan_desc = None
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4336
                self.__planned_children = False
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4337
                self.__plan_type = None
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4338
                self.__prepared = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4339
                self.__executed = False
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4340
                self.__be_name = None
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4341
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4342
                self._cancel_cleanup_exception()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4343
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4344
        def __check_cancel(self):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4345
                """Private method. Provides a callback method for internal
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4346
                code to use to determine whether the current action has been
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4347
                canceled."""
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4348
                return self.__canceling
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4349
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4350
        def _cancel_cleanup_exception(self):
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4351
                """A private method that is called from exception handlers.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4352
                This is not needed if the method calls reset unlock,
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4353
                which will call this method too.  This catches the case
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4354
                where a caller might have called cancel and gone to sleep,
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4355
                but the requested operation failed with an exception before
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4356
                it could raise a CanceledException."""
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4357
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4358
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4359
                self.__set_can_be_canceled(False)
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4360
                self.__canceling = False
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4361
                # Wake up any threads that are waiting on this aborted
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4362
                # operation.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4363
                self.__cancel_cv.notify_all()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4364
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4365
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4366
        def _cancel_done(self):
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4367
                """A private method that wakes any threads that have been
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4368
                sleeping, waiting for a cancellation to finish."""
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4369
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4370
                self.__cancel_lock.acquire()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4371
                if self.__canceling:
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4372
                        self.__canceling = False
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4373
                        self.__cancel_cv.notify_all()
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4374
                self.__cancel_lock.release()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4375
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4376
        def cancel(self):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4377
                """Used for asynchronous cancelation. It returns the API
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4378
                to the state it was in prior to the current method being
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4379
                invoked.  Canceling during a plan phase returns the API to
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4380
                its initial state. Canceling during prepare puts the API
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4381
                into the state it was in just after planning had completed.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4382
                Plan execution cannot be canceled. A call to this method blocks
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4383
                until the cancellation has happened. Note: this does not
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4384
                necessarily return the disk to its initial state since the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4385
                indexes or download cache may have been changed by the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4386
                prepare method."""
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4387
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4388
                self.__cancel_lock.acquire()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4389
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4390
                if not self.__can_be_canceled:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4391
                        self.__cancel_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4392
                        return False
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4393
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4394
                self.__set_can_be_canceled(False)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4395
                self.__canceling = True
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4396
                # Wait until the cancelled operation wakes us up.
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4397
                self.__cancel_cv.wait()
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4398
                self.__cancel_lock.release()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4399
                return True
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  4400
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4401
        def clear_history(self):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4402
                """Discard history information about in-progress operations."""
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4403
                self._img.history.clear()
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4404
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  4405
        def __set_history_PlanCreationException(self, e):
1141
a74d6815a7fc 4178 unfound_fmris is a poor name
Rich Burridge <rich.burridge@sun.com>
parents: 1140
diff changeset
  4406
                if e.unmatched_fmris or e.multiple_matches or \
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  4407
                    e.missing_matches or e.illegal:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4408
                        self.log_operation_end(error=e,
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  4409
                            result=RESULT_FAILED_BAD_REQUEST)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4410
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4411
                        self.log_operation_end(error=e)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4412
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4413
        @_LockedGenerator()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4414
        def local_search(self, query_lst):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4415
                """local_search takes a list of Query objects and performs
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4416
                each query against the installed packages of the image."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4417
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4418
                l = query_p.QueryLexer()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4419
                l.build()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4420
                qp = query_p.QueryParser(l)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4421
                ssu = None
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4422
                for i, q in enumerate(query_lst):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4423
                        try:
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4424
                                query = qp.parse(q.text)
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4425
                                query_rr = qp.parse(q.text)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4426
                                if query_rr.remove_root(self._img.root):
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4427
                                        query.add_or(query_rr)
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4428
                                if q.return_type == \
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4429
                                    query_p.Query.RETURN_PACKAGES:
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4430
                                        query.propagate_pkg_return()
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  4431
                        except query_p.BooleanQueryException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4432
                                raise apx.BooleanQueryException(e)
1053
00fe9773d072 8098 parsing errors should not cause a stacktrace
Brock Pytlik <bpytlik@sun.com>
parents: 1051
diff changeset
  4433
                        except query_p.ParseError, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4434
                                raise apx.ParseError(e)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4435
                        self._img.update_index_dir()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4436
                        assert self._img.index_dir
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4437
                        try:
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  4438
                                query.set_info(num_to_return=q.num_to_return,
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  4439
                                    start_point=q.start_point,
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4440
                                    index_dir=self._img.index_dir,
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  4441
                                    get_manifest_path=\
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4442
                                        self._img.get_manifest_path,
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  4443
                                    gen_installed_pkg_names=\
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4444
                                        self._img.gen_installed_pkg_names,
1337
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  4445
                                    case_sensitive=q.case_sensitive)
52e101b7cc31 9293 there should be a way to automatically infer/audit package dependencies for a package
Brock Pytlik <bpytlik@sun.com>
parents: 1335
diff changeset
  4446
                                res = query.search(
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4447
                                    self._img.gen_installed_pkgs,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4448
                                    self._img.get_manifest_path,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4449
                                    self._img.list_excludes())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4450
                        except search_errors.InconsistentIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4451
                                raise apx.InconsistentIndexException(e)
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4452
                        # i is being inserted to track which query the results
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4453
                        # are for.  None is being inserted since there is no
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4454
                        # publisher being searched against.
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4455
                        try:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4456
                                for r in res:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4457
                                        yield i, None, r
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4458
                        except apx.SlowSearchUsed, e:
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4459
                                ssu = e
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4460
                if ssu:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4461
                        raise ssu
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4462
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4463
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4464
        def __parse_v_0(line, pub, v):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4465
                """This function parses the string returned by a version 0
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4466
                search server and puts it into the expected format of
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4467
                (query_number, publisher, (version, return_type, (results))).
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1257
diff changeset
  4468
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4469
                "query_number" in the return value is fixed at 0 since search
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4470
                v0 servers cannot accept multiple queries in a single HTTP
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4471
                request."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4472
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4473
                line = line.strip()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4474
                fields = line.split(None, 3)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4475
                return (0, pub, (v, Query.RETURN_ACTIONS, (fields[:4])))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4476
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4477
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4478
        def __parse_v_1(line, pub, v):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4479
                """This function parses the string returned by a version 1
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4480
                search server and puts it into the expected format of
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4481
                (query_number, publisher, (version, return_type, (results)))
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4482
                If it receives a line it can't parse, it raises a
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4483
                ServerReturnError."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4484
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4485
                fields = line.split(None, 2)
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4486
                if len(fields) != 3:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4487
                        raise apx.ServerReturnError(line)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4488
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4489
                        return_type = int(fields[1])
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4490
                        query_num = int(fields[0])
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4491
                except ValueError:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4492
                        raise apx.ServerReturnError(line)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4493
                if return_type == Query.RETURN_ACTIONS:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4494
                        subfields = fields[2].split(None, 2)
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4495
                        pfmri = fmri.PkgFmri(subfields[0])
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4496
                        return pfmri, (query_num, pub, (v, return_type,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4497
                            (pfmri, urllib.unquote(subfields[1]),
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4498
                            subfields[2])))
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4499
                elif return_type == Query.RETURN_PACKAGES:
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4500
                        pfmri = fmri.PkgFmri(fields[2])
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4501
                        return pfmri, (query_num, pub, (v, return_type, pfmri))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4502
                else:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4503
                        raise apx.ServerReturnError(line)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4504
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4505
        @_LockedGenerator()
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4506
        def remote_search(self, query_str_and_args_lst, servers=None,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4507
            prune_versions=True):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4508
                """This function takes a list of Query objects, and optionally
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4509
                a list of servers to search against.  It performs each query
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4510
                against each server and yields the results in turn.  If no
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4511
                servers are provided, the search is conducted against all
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4512
                active servers known by the image.
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4513
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4514
                The servers argument is a list of servers in two possible
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4515
                forms: the old deprecated form of a publisher, in a
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4516
                dictionary, or a Publisher object.
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4517
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4518
                A call to this function returns a generator that holds
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4519
                API locks.  Callers must either iterate through all of the
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4520
                results, or call close() on the resulting object.  Otherwise
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4521
                it is possible to get deadlocks or NRLock reentrance
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4522
                exceptions."""
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4523
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4524
                failed = []
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4525
                invalid = []
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4526
                unsupported = []
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  4527
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4528
                if not servers:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4529
                        servers = self._img.gen_publishers()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4530
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4531
                new_qs = []
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4532
                l = query_p.QueryLexer()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4533
                l.build()
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4534
                qp = query_p.QueryParser(l)
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4535
                for q in query_str_and_args_lst:
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4536
                        try:
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4537
                                query = qp.parse(q.text)
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4538
                                query_rr = qp.parse(q.text)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4539
                                if query_rr.remove_root(self._img.root):
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4540
                                        query.add_or(query_rr)
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4541
                                if q.return_type == \
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4542
                                    query_p.Query.RETURN_PACKAGES:
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4543
                                        query.propagate_pkg_return()
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4544
                                new_qs.append(query_p.Query(str(query),
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4545
                                    q.case_sensitive, q.return_type,
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4546
                                    q.num_to_return, q.start_point))
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4547
                        except query_p.BooleanQueryException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4548
                                raise apx.BooleanQueryException(e)
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4549
                        except query_p.ParseError, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4550
                                raise apx.ParseError(e)
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4551
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4552
                query_str_and_args_lst = new_qs
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4553
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4554
                incorp_info, inst_stems = self.get_incorp_info()
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4555
2352
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4556
                slist = []
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4557
                for entry in servers:
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4558
                        if isinstance(entry, dict):
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4559
                                origin = entry["origin"]
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4560
                                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4561
                                        pub = self._img.get_publisher(
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4562
                                            origin=origin)
2847
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4563
                                        pub_uri = publisher.RepositoryURI(
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4564
                                            origin)
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4565
                                        repo = publisher.Repository(
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4566
                                            origins=[pub_uri])
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4567
                                except apx.UnknownPublisher:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4568
                                        pub = publisher.RepositoryURI(origin)
2847
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4569
                                        repo = publisher.Repository(
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4570
                                            origins=[pub])
5c572d3a1276 15822242 update-refresh.sh produces noise via cron email
thejaswini.k@oracle.com
parents: 2840
diff changeset
  4571
                                slist.append((pub, repo, origin))
2352
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4572
                                continue
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4573
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4574
                        # Must be a publisher object.
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4575
                        osets = entry.get_origin_sets()
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4576
                        if not osets:
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4577
                                unsupported.append((entry.prefix,
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4578
                                    apx.NoPublisherRepositories(
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4579
                                    entry.prefix)))
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4580
                                continue
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4581
                        for repo in osets:
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4582
                                slist.append((entry, repo, entry.prefix))
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4583
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4584
                for pub, alt_repo, descriptive_name in slist:
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4585
                        if self.__canceling:
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4586
                                raise apx.CanceledException()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4587
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4588
                        try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4589
                                res = self._img.transport.do_search(pub,
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4590
                                    query_str_and_args_lst,
2352
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4591
                                    ccancel=self.__check_cancel,
3c17f86cd994 18105 api should support multiple repositories (origins) with different package data
Shawn Walker <shawn.walker@oracle.com>
parents: 2339
diff changeset
  4592
                                    alt_repo=alt_repo)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4593
                        except apx.CanceledException:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4594
                                raise
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4595
                        except apx.NegativeSearchResult:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4596
                                continue
2593
39deb6a29774 18716 captive_portal_test requires at least one configured source to be reachable even when specifying temporary sources
Shawn Walker <shawn.walker@oracle.com>
parents: 2550
diff changeset
  4597
                        except (apx.InvalidDepotResponseException,
39deb6a29774 18716 captive_portal_test requires at least one configured source to be reachable even when specifying temporary sources
Shawn Walker <shawn.walker@oracle.com>
parents: 2550
diff changeset
  4598
                            apx.TransportError), e:
39deb6a29774 18716 captive_portal_test requires at least one configured source to be reachable even when specifying temporary sources
Shawn Walker <shawn.walker@oracle.com>
parents: 2550
diff changeset
  4599
                                # Alternate source failed portal test or can't
39deb6a29774 18716 captive_portal_test requires at least one configured source to be reachable even when specifying temporary sources
Shawn Walker <shawn.walker@oracle.com>
parents: 2550
diff changeset
  4600
                                # be contacted at all.
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4601
                                failed.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4602
                                continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4603
                        except apx.UnsupportedSearchError, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4604
                                unsupported.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4605
                                continue
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4606
                        except apx.MalformedSearchRequest, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4607
                                ex = self._validate_search(
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4608
                                    query_str_and_args_lst)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4609
                                if ex:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4610
                                        raise ex
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4611
                                failed.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4612
                                continue
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4613
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4614
                        try:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4615
                                if not self.validate_response(res, 1):
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4616
                                        invalid.append(descriptive_name)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4617
                                        continue
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4618
                                for line in res:
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4619
                                        pfmri, ret = self.__parse_v_1(line, pub,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4620
                                            1)
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4621
                                        pstem = pfmri.pkg_name
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4622
                                        pver = pfmri.version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4623
                                        # Skip this package if a newer version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4624
                                        # is already installed and version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4625
                                        # pruning is enabled.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4626
                                        if prune_versions and \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4627
                                            pstem in inst_stems and \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4628
                                            pver < inst_stems[pstem]:
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4629
                                                continue
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4630
                                        # Return this result if version pruning
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4631
                                        # is disabled, the package is not
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4632
                                        # incorporated, or the version of the
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4633
                                        # package matches the incorporation.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4634
                                        if not prune_versions or \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4635
                                            pstem not in incorp_info or \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4636
                                            pfmri.version.is_successor(
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4637
                                                incorp_info[pstem],
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4638
                                                pkg.version.CONSTRAINT_AUTO):
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4639
                                                yield ret
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4640
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4641
                        except apx.CanceledException:
1569
b1d8ed54f455 8584 allow remote search to be canceled via api.cancel
johansen <johansen@sun.com>
parents: 1538
diff changeset
  4642
                                raise
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4643
                        except apx.TransportError, e:
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4644
                                failed.append((descriptive_name, e))
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4645
                                continue
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4646
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4647
                if failed or invalid or unsupported:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4648
                        raise apx.ProblematicSearchServers(failed,
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4649
                            invalid, unsupported)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4650
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4651
        def get_incorp_info(self):
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4652
                """This function returns a mapping of package stems to the
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4653
                version at which they are incorporated, if they are
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4654
                incorporated, and the version at which they are installed, if
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4655
                they are installed."""
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4656
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4657
                # This maps fmris to the version at which they're incorporated.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4658
                inc_vers = {}
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4659
                inst_stems = {}
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4660
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4661
                img_cat = self._img.get_catalog(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4662
                    self._img.IMG_CATALOG_INSTALLED)
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4663
                cat_info = frozenset([img_cat.DEPENDENCY])
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4664
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4665
                # The incorporation list should include all installed,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4666
                # incorporated packages from all publishers.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4667
                for pfmri, actions in img_cat.actions(cat_info):
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4668
                        inst_stems[pfmri.pkg_name] = pfmri.version
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4669
                        for a in actions:
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4670
                                if a.name != "depend" or \
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4671
                                    a.attrs["type"] != "incorporate":
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4672
                                        continue
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4673
                                # Record incorporated packages.
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  4674
                                tgt = fmri.PkgFmri(a.attrs["fmri"])
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4675
                                tver = tgt.version
2638
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  4676
                                # incorporates without a version should be
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  4677
                                # ignored.
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  4678
                                if not tver:
4cc18217756f 7149876 get_pkg_list can fail if versionless incorporate dependency is installed
Shawn Walker <shawn.walker@oracle.com>
parents: 2631
diff changeset
  4679
                                        continue
1843
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4680
                                over = inc_vers.get(
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4681
                                    tgt.pkg_name, None)
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4682
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4683
                                # In case this package has been
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4684
                                # incorporated more than once,
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4685
                                # use the newest version.
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4686
                                if over > tver:
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4687
                                        continue
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4688
                                inc_vers[tgt.pkg_name] = tver
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4689
                return inc_vers, inst_stems
b9333a197e40 6177 filtering search against a particular incorporation is needed
Brock Pytlik <bpytlik@sun.com>
parents: 1835
diff changeset
  4690
1360
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4691
        @staticmethod
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4692
        def __unconvert_return_type(v):
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4693
                return v == query_p.Query.RETURN_ACTIONS
fbf184c6d55b 1059 search both original input and paths with image root removed
Brock Pytlik <bpytlik@sun.com>
parents: 1352
diff changeset
  4694
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4695
        def _validate_search(self, query_str_lst):
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4696
                """Called by remote search if server responds that the
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4697
                request was invalid.  In this case, parse the query on
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4698
                the client-side and determine what went wrong."""
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4699
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4700
                for q in query_str_lst:
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4701
                        l = query_p.QueryLexer()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4702
                        l.build()
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4703
                        qp = query_p.QueryParser(l)
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4704
                        try:
1893
d935808d8050 15457 pkg search -p should do more than just wrap the query in <>
Brock Pytlik <bpytlik@sun.com>
parents: 1877
diff changeset
  4705
                                query = qp.parse(q.text)
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4706
                        except query_p.BooleanQueryException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4707
                                return apx.BooleanQueryException(e)
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4708
                        except query_p.ParseError, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4709
                                return apx.ParseError(e)
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4710
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
  4711
                return None
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4712
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4713
        def rebuild_search_index(self):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4714
                """Rebuilds the search indexes.  Removes all
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4715
                existing indexes and replaces them from scratch rather than
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4716
                performing the incremental update which is usually used.
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4717
                This is useful for times when the index for the client has
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4718
                been corrupted."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4719
                self._img.update_index_dir()
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  4720
                self.log_operation_start("rebuild-index")
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4721
                if not os.path.isdir(self._img.index_dir):
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4722
                        self._img.mkdirs()
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4723
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4724
                        ind = indexer.Indexer(self._img, self._img.get_manifest,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4725
                            self._img.get_manifest_path,
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4726
                            self.__progresstracker, self._img.list_excludes())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4727
                        ind.rebuild_index_from_scratch(
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4728
                            self._img.gen_installed_pkgs())
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4729
                except search_errors.ProblematicPermissionsIndexException, e:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4730
                        error = apx.ProblematicPermissionsIndexException(e)
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  4731
                        self.log_operation_end(error=error)
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  4732
                        raise error
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4733
                else:
1027
e827313523d8 7774 image history discarded when bootenv operations fail or succeed
Shawn Walker <srw@sun.com>
parents: 1019
diff changeset
  4734
                        self.log_operation_end()
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  4735
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4736
        def get_manifest(self, pfmri, all_variants=True, repos=None):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4737
                """Returns the Manifest object for the given package FMRI.
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4738
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4739
                'all_variants' is an optional boolean value indicating whther
2608
2231afa43dc7 19104 CliTestCase.pkgsend needs to display traceback when pkgsend tracesback
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2593
diff changeset
  4740
                the manifest should include metadata for all variants and
2231afa43dc7 19104 CliTestCase.pkgsend needs to display traceback when pkgsend tracesback
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2593
diff changeset
  4741
                facets.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4742
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4743
                'repos' is a list of URI strings or RepositoryURI objects that
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4744
                represent the locations of additional sources of package data to
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4745
                use during the planned operation.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4746
                """
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4747
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4748
                alt_pub = None
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4749
                if repos:
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4750
                        pkg_pub_map, ignored, known_cat, inst_cat = \
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4751
                            self.__get_alt_pkg_data(repos)
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4752
                        alt_pub = pkg_pub_map.get(pfmri.publisher, {}).get(
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4753
                            pfmri.pkg_name, {}).get(str(pfmri.version), None)
2631
93d1e439acae 7136535 use_excludes has wrong meaning
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2619
diff changeset
  4754
                return self._img.get_manifest(pfmri,
93d1e439acae 7136535 use_excludes has wrong meaning
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2619
diff changeset
  4755
                    ignore_excludes=all_variants, alt_pub=alt_pub)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4756
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4757
        @staticmethod
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4758
        def validate_response(res, v):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4759
                """This function is used to determine whether the first
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4760
                line returned from a server is expected.  This ensures that
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4761
                search is really communicating with a search-enabled server."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  4762
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4763
                try:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4764
                        s = res.next()
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4765
                        return s == Query.VALIDATION_STRING[v]
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4766
                except StopIteration:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4767
                        return False
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  4768
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  4769
        def add_publisher(self, pub, refresh_allowed=True,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  4770
            approved_cas=misc.EmptyI, revoked_cas=misc.EmptyI,
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4771
            search_after=None, search_before=None, search_first=None,
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  4772
            unset_cas=misc.EmptyI):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4773
                """Add the provided publisher object to the image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4774
                configuration."""
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  4775
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4776
                        self._img.add_publisher(pub,
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  4777
                            refresh_allowed=refresh_allowed,
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  4778
                            progtrack=self.__progresstracker,
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  4779
                            approved_cas=approved_cas, revoked_cas=revoked_cas,
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4780
                            search_after=search_after,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4781
                            search_before=search_before,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4782
                            search_first=search_first,
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  4783
                            unset_cas=unset_cas)
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1472
diff changeset
  4784
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4785
                        self._img.cleanup_downloads()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4786
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4787
        def get_highest_ranked_publisher(self):
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4788
                """Returns the highest ranked publisher object for the image."""
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4789
                return self._img.get_highest_ranked_publisher()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4790
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4791
        def get_publisher(self, prefix=None, alias=None, duplicate=False):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4792
                """Retrieves a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4793
                (name) or alias.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4794
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4795
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4796
                a copy of the publisher object should be returned instead
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4797
                of the original.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4798
                """
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4799
                pub = self._img.get_publisher(prefix=prefix, alias=alias)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4800
                if duplicate:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4801
                        # Never return the original so that changes to the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4802
                        # retrieved object are not reflected until
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4803
                        # update_publisher is called.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4804
                        return copy.copy(pub)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4805
                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4806
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4807
        @_LockedCancelable()
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4808
        def get_publisherdata(self, pub=None, repo=None):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4809
                """Attempts to retrieve publisher configuration information from
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4810
                the specified publisher's repository or the provided repository.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4811
                If successful, it will either return an empty list (in the case
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4812
                that the repository supports the operation, but doesn't offer
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4813
                configuration information) or a list of Publisher objects.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4814
                If this operation is not supported by the publisher or the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4815
                specified repository, an UnsupportedRepositoryOperation
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4816
                exception will be raised.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4817
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4818
                'pub' is an optional Publisher object.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4819
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4820
                'repo' is an optional RepositoryURI object.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4821
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4822
                Either 'pub' or 'repo' must be provided."""
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4823
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4824
                assert (pub or repo) and not (pub and repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4825
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4826
                # Transport accepts either type of object, but a distinction is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4827
                # made in the client API for clarity.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4828
                pub = max(pub, repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4829
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4830
                return self._img.transport.get_publisherdata(pub,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4831
                    ccancel=self.__check_cancel)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4832
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4833
        def get_publishers(self, duplicate=False):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4834
                """Returns a list of the publisher objects for the current
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4835
                image.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4836
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4837
                'duplicate' is an optional boolean value indicating whether
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4838
                copies of the publisher objects should be returned instead
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4839
                of the originals.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4840
                """
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4841
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4842
                res = self._img.get_sorted_publishers()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4843
                if duplicate:
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4844
                        return [copy.copy(p) for p in res]
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4845
                return res
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  4846
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4847
        def get_publisher_last_update_time(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4848
                """Returns a datetime object representing the last time the
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4849
                catalog for a publisher was modified or None."""
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4850
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4851
                if alias:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4852
                        pub = self.get_publisher(alias=alias)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4853
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4854
                        pub = self.get_publisher(prefix=prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4855
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4856
                if pub.disabled:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4857
                        return None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4858
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4859
                dt = None
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4860
                self._acquire_activity_lock()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4861
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4862
                        self._enable_cancel()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4863
                        try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  4864
                                dt = pub.catalog.last_modified
1032
ff3c6b09f430 8072 history load code needs to be more resilient against unexpected data format
Shawn Walker <srw@sun.com>
parents: 1027
diff changeset
  4865
                        except:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4866
                                self.__reset_unlock()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4867
                                raise
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4868
                        try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4869
                                self._disable_cancel()
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4870
                        except apx.CanceledException:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4871
                                self._cancel_done()
1693
1d855833b718 3720 Race condition exists for cancelation using the API
johansen <johansen@sun.com>
parents: 1685
diff changeset
  4872
                                raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4873
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4874
                        self._activity_lock.release()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4875
                return dt
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4876
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4877
        def has_publisher(self, prefix=None, alias=None):
1252
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1242
diff changeset
  4878
                """Returns a boolean value indicating whether a publisher using
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1242
diff changeset
  4879
                the given prefix or alias exists."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4880
                return self._img.has_publisher(prefix=prefix, alias=alias)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4881
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4882
        def remove_publisher(self, prefix=None, alias=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4883
                """Removes a publisher object matching the provided prefix
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4884
                (name) or alias."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4885
                self._img.remove_publisher(prefix=prefix, alias=alias,
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  4886
                    progtrack=self.__progresstracker)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4887
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4888
        def update_publisher(self, pub, refresh_allowed=True, search_after=None,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4889
            search_before=None, search_first=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4890
                """Replaces an existing publisher object with the provided one
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4891
                using the _source_object_id identifier set during copy.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4892
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4893
                'refresh_allowed' is an optional boolean value indicating
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4894
                whether a refresh of publisher metadata (such as its catalog)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4895
                should be performed if transport information is changed for a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4896
                repository, mirror, or origin.  If False, no attempt will be
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4897
                made to retrieve publisher metadata."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4898
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4899
                self._acquire_activity_lock()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4900
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4901
                        self._disable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4902
                        with self._img.locked_op("update-publisher"):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4903
                                return self.__update_publisher(pub,
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4904
                                    refresh_allowed=refresh_allowed,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4905
                                    search_after=search_after,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4906
                                    search_before=search_before,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4907
                                    search_first=search_first)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4908
                except apx.CanceledException, e:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4909
                        self._cancel_done()
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4910
                        raise
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4911
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4912
                        self._img.cleanup_downloads()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4913
                        self._activity_lock.release()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4914
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4915
        def __update_publisher(self, pub, refresh_allowed=True,
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4916
            search_after=None, search_before=None, search_first=None):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4917
                """Private publisher update method; caller responsible for
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1693
diff changeset
  4918
                locking."""
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4919
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4920
                assert (not search_after and not search_before) or \
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4921
                    (not search_after and not search_first) or \
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4922
                    (not search_before and not search_first)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4923
2433
7af4ccfa1c06 5060 cert and key files should be validated when adding or updating publishers
Shawn Walker <shawn.walker@oracle.com>
parents: 2410
diff changeset
  4924
                # Before continuing, validate SSL information.
7af4ccfa1c06 5060 cert and key files should be validated when adding or updating publishers
Shawn Walker <shawn.walker@oracle.com>
parents: 2410
diff changeset
  4925
                try:
7af4ccfa1c06 5060 cert and key files should be validated when adding or updating publishers
Shawn Walker <shawn.walker@oracle.com>
parents: 2410
diff changeset
  4926
                        self._img.check_cert_validity(pubs=[pub])
7af4ccfa1c06 5060 cert and key files should be validated when adding or updating publishers
Shawn Walker <shawn.walker@oracle.com>
parents: 2410
diff changeset
  4927
                except apx.ExpiringCertificate, e:
3010
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  4928
                        logger.warning(str(e))
2433
7af4ccfa1c06 5060 cert and key files should be validated when adding or updating publishers
Shawn Walker <shawn.walker@oracle.com>
parents: 2410
diff changeset
  4929
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4930
                def origins_changed(oldr, newr):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4931
                        old_origins = set([
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4932
                            (o.uri, o.ssl_cert,
2701
55bf0cb749ae 7136244 granular configuration of http_proxy option
Tim Foster <tim.s.foster@oracle.com>
parents: 2693
diff changeset
  4933
                                o.ssl_key, tuple(sorted(o.proxies)))
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4934
                            for o in oldr.origins
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4935
                        ])
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4936
                        new_origins = set([
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4937
                            (o.uri, o.ssl_cert,
2701
55bf0cb749ae 7136244 granular configuration of http_proxy option
Tim Foster <tim.s.foster@oracle.com>
parents: 2693
diff changeset
  4938
                                o.ssl_key, tuple(sorted(o.proxies)))
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4939
                            for o in newr.origins
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4940
                        ])
2749
9d664b5d7896 7175436 removal-only of origins with set-publisher can result in stale image catalog
Shawn Walker <shawn.walker@oracle.com>
parents: 2708
diff changeset
  4941
                        return (new_origins - old_origins), \
9d664b5d7896 7175436 removal-only of origins with set-publisher can result in stale image catalog
Shawn Walker <shawn.walker@oracle.com>
parents: 2708
diff changeset
  4942
                            new_origins.symmetric_difference(old_origins)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4943
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4944
                def need_refresh(oldo, newo):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4945
                        if newo.disabled:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4946
                                # The publisher is disabled, so no refresh
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4947
                                # should be performed.
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4948
                                return False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4949
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4950
                        if oldo.disabled and not newo.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4951
                                # The publisher has been re-enabled, so
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4952
                                # retrieve the catalog.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4953
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4954
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4955
                        oldr = oldo.repository
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  4956
                        newr = newo.repository
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4957
                        if newr._source_object_id != id(oldr):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  4958
                                # Selected repository has changed.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4959
                                return True
2749
9d664b5d7896 7175436 removal-only of origins with set-publisher can result in stale image catalog
Shawn Walker <shawn.walker@oracle.com>
parents: 2708
diff changeset
  4960
                        # If any were added or removed, refresh.
9d664b5d7896 7175436 removal-only of origins with set-publisher can result in stale image catalog
Shawn Walker <shawn.walker@oracle.com>
parents: 2708
diff changeset
  4961
                        return len(origins_changed(oldr, newr)[1]) != 0
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4962
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 941
diff changeset
  4963
                refresh_catalog = False
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4964
                disable = False
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  4965
                orig_pub = None
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4966
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4967
                # Configuration must be manipulated directly.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  4968
                publishers = self._img.cfg.publishers
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4969
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4970
                # First, attempt to match the updated publisher object to an
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4971
                # existing one using the object id that was stored during
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4972
                # copy().
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4973
                for key, old in publishers.iteritems():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  4974
                        if pub._source_object_id == id(old):
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4975
                                # Store the new publisher's id and the old
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4976
                                # publisher object so it can be restored if the
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4977
                                # update operation fails.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4978
                                orig_pub = (id(pub), old)
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4979
                                break
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4980
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4981
                if not orig_pub:
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4982
                        # If a matching publisher couldn't be found and
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4983
                        # replaced, something is wrong (client api usage
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4984
                        # error).
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4985
                        raise apx.UnknownPublisher(pub)
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4986
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4987
                # Next, be certain that the publisher's prefix and alias
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4988
                # are not already in use by another publisher.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4989
                for key, old in publishers.iteritems():
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4990
                        if pub._source_object_id == id(old):
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4991
                                # Don't check the object we're replacing.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4992
                                continue
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4993
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4994
                        if pub.prefix == old.prefix or \
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4995
                            pub.prefix == old.alias or \
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4996
                            pub.alias and (pub.alias == old.alias or
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4997
                            pub.alias == old.prefix):
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  4998
                                raise apx.DuplicatePublisher(pub)
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  4999
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  5000
                # Next, determine what needs updating and add the updated
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  5001
                # publisher.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  5002
                for key, old in publishers.iteritems():
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  5003
                        if pub._source_object_id == id(old):
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  5004
                                old = orig_pub[-1]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5005
                                if need_refresh(old, pub):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5006
                                        refresh_catalog = True
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5007
                                if not old.disabled and pub.disabled:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5008
                                        disable = True
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5009
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5010
                                # Now remove the old publisher object using the
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
  5011
                                # iterator key if the prefix has changed.
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  5012
                                if key != pub.prefix:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  5013
                                        del publishers[key]
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5014
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  5015
                                # Prepare the new publisher object.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  5016
                                pub.meta_root = \
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5017
                                    self._img._get_publisher_meta_root(
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  5018
                                    pub.prefix)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5019
                                pub.transport = self._img.transport
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1346
diff changeset
  5020
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5021
                                # Finally, add the new publisher object.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5022
                                publishers[pub.prefix] = pub
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5023
                                break
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5024
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5025
                def cleanup():
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5026
                        new_id, old_pub = orig_pub
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5027
                        for new_pfx, new_pub in publishers.iteritems():
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5028
                                if id(new_pub) == new_id:
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5029
                                        publishers[old_pub.prefix] = old_pub
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5030
                                        break
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5031
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5032
                repo = pub.repository
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5033
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5034
                validate = origins_changed(orig_pub[-1].repository,
2749
9d664b5d7896 7175436 removal-only of origins with set-publisher can result in stale image catalog
Shawn Walker <shawn.walker@oracle.com>
parents: 2708
diff changeset
  5035
                    pub.repository)[0]
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5036
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5037
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5038
                        if disable or (not repo.origins and
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5039
                            orig_pub[-1].repository.origins):
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5040
                                # Remove the publisher's metadata (such as
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5041
                                # catalogs, etc.).  This only needs to be done
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5042
                                # in the event that a publisher is disabled or
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5043
                                # has transitioned from having origins to not
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5044
                                # having any at all; in any other case (the
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5045
                                # origins changing, etc.), refresh() will do the
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5046
                                # right thing.
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5047
                                self._img.remove_publisher_metadata(pub)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5048
                        elif not pub.disabled and not refresh_catalog:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5049
                                refresh_catalog = pub.needs_refresh
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5050
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5051
                        if refresh_catalog and refresh_allowed:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5052
                                # One of the publisher's repository origins may
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5053
                                # have changed, so the publisher needs to be
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5054
                                # revalidated.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5055
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5056
                                if validate:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5057
                                        self._img.transport.valid_publisher_test(
1240
b261f33b84bd 10145 ImageInterface client api exposes private attributes
Shawn Walker <srw@sun.com>
parents: 1231
diff changeset
  5058
                                            pub)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5059
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5060
                                # Validate all new origins against publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5061
                                # configuration.
2701
55bf0cb749ae 7136244 granular configuration of http_proxy option
Tim Foster <tim.s.foster@oracle.com>
parents: 2693
diff changeset
  5062
                                for uri, ssl_cert, ssl_key, proxies in validate:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5063
                                        repo = publisher.RepositoryURI(uri,
2701
55bf0cb749ae 7136244 granular configuration of http_proxy option
Tim Foster <tim.s.foster@oracle.com>
parents: 2693
diff changeset
  5064
                                            ssl_cert=ssl_cert, ssl_key=ssl_key,
55bf0cb749ae 7136244 granular configuration of http_proxy option
Tim Foster <tim.s.foster@oracle.com>
parents: 2693
diff changeset
  5065
                                            proxies=proxies)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5066
                                        pub.validate_config(repo)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5067
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5068
                                self.__refresh(pubs=[pub], immediate=True)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5069
                        elif refresh_catalog:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5070
                                # Something has changed (such as a repository
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5071
                                # origin) for the publisher, so a refresh should
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5072
                                # occur, but isn't currently allowed.  As such,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5073
                                # clear the last_refreshed time so that the next
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5074
                                # time the client checks to see if a refresh is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5075
                                # needed and is allowed, one will be performed.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5076
                                pub.last_refreshed = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5077
                except Exception, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5078
                        # If any of the above fails, the original publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5079
                        # information needs to be restored so that state is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5080
                        # consistent.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5081
                        cleanup()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5082
                        raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5083
                except:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5084
                        # If any of the above fails, the original publisher
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5085
                        # information needs to be restored so that state is
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5086
                        # consistent.
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1100
diff changeset
  5087
                        cleanup()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1081
diff changeset
  5088
                        raise
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5089
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5090
                if search_first:
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5091
                        self._img.set_highest_ranked_publisher(
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5092
                            prefix=pub.prefix)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5093
                elif search_before:
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5094
                        self._img.pub_search_before(pub.prefix, search_before)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5095
                elif search_after:
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5096
                        self._img.pub_search_after(pub.prefix, search_after)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5097
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5098
                # Successful; so save configuration.
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5099
                self._img.save_config()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5100
2708
4dac3e277ccf 7137406 pkg image-update could display release notes (or pointer to)
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2701
diff changeset
  5101
        def log_operation_end(self, error=None, result=None, 
4dac3e277ccf 7137406 pkg image-update could display release notes (or pointer to)
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2701
diff changeset
  5102
            release_notes=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5103
                """Marks the end of an operation to be recorded in image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5104
                history.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5105
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5106
                'result' should be a pkg.client.history constant value
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5107
                representing the outcome of an operation.  If not provided,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5108
                and 'error' is provided, the final result of the operation will
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5109
                be based on the class of 'error' and 'error' will be recorded
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5110
                for the current operation.  If 'result' and 'error' is not
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5111
                provided, success is assumed."""
2708
4dac3e277ccf 7137406 pkg image-update could display release notes (or pointer to)
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2701
diff changeset
  5112
                self._img.history.log_operation_end(error=error, result=result,
4dac3e277ccf 7137406 pkg image-update could display release notes (or pointer to)
Bart Smaalders <Bart.Smaalders@Oracle.COM>
parents: 2701
diff changeset
  5113
                release_notes=release_notes)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5114
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5115
        def log_operation_error(self, error):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5116
                """Adds an error to the list of errors to be recorded in image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5117
                history for the current opreation."""
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5118
                self._img.history.log_operation_error(error)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5119
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5120
        def log_operation_start(self, name):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5121
                """Marks the start of an operation to be recorded in image
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5122
                history."""
2750
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5123
                # If an operation is going to be discarded, then don't take the
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5124
                # performance hit of actually getting the BE info.
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5125
                if name in history.DISCARDED_OPERATIONS:
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5126
                        be_name, be_uuid = None, None
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5127
                else:
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5128
                        be_name, be_uuid = bootenv.BootEnv.get_be_name(
9982917e7fee 7185843 pkg makes too many calls to be.beList
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2749
diff changeset
  5129
                            self._img.root)
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5130
                self._img.history.log_operation_start(name,
2141
3757a0f8a7d1 17385 history should store uuids for boot environments
Tim Foster <tim.s.foster@oracle.com>
parents: 2135
diff changeset
  5131
                    be_name=be_name, be_uuid=be_uuid)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5132
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5133
        def parse_liname(self, name, unknown_ok=False):
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5134
                """Parse a linked image name string and return a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5135
                LinkedImageName object.  If "unknown_ok" is true then
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5136
                liname must correspond to an existing linked image.  If
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5137
                "unknown_ok" is false and liname doesn't correspond to
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5138
                an existing linked image then liname must be a
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5139
                syntactically valid and fully qualified linked image
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5140
                name."""
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5141
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5142
                return self._img.linked.parse_name(name, unknown_ok=unknown_ok)
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5143
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5144
        def parse_p5i(self, data=None, fileobj=None, location=None):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5145
                """Reads the pkg(5) publisher JSON formatted data at 'location'
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5146
                or from the provided file-like object 'fileobj' and returns a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5147
                list of tuples of the format (publisher object, pkg_names).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5148
                pkg_names is a list of strings representing package names or
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5149
                FMRIs.  If any pkg_names not specific to a publisher were
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5150
                provided, the last tuple returned will be of the format (None,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5151
                pkg_names).
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5152
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5153
                'data' is an optional string containing the p5i data.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5154
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5155
                'fileobj' is an optional file-like object that must support a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5156
                'read' method for retrieving data.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5157
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5158
                'location' is an optional string value that should either start
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5159
                with a leading slash and be pathname of a file or a URI string.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5160
                If it is a URI string, supported protocol schemes are 'file',
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5161
                'ftp', 'http', and 'https'.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5162
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5163
                'data' or 'fileobj' or 'location' must be provided."""
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5164
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5165
                return p5i.parse(data=data, fileobj=fileobj, location=location)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5166
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5167
        def parse_fmri_patterns(self, patterns):
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5168
                """A generator function that yields a list of tuples of the form
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5169
                (pattern, error, fmri, matcher) based on the provided patterns,
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5170
                where 'error' is any exception encountered while parsing the
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5171
                pattern, 'fmri' is the resulting FMRI object, and 'matcher' is
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5172
                one of the following constant values:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5173
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5174
                        MATCH_EXACT
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5175
                                Indicates that the name portion of the pattern
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5176
                                must match exactly and the version (if provided)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5177
                                must be considered a successor or equal to the
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5178
                                target FMRI.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5179
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5180
                        MATCH_FMRI
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5181
                                Indicates that the name portion of the pattern
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5182
                                must be a proper subset and the version (if
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5183
                                provided) must be considered a successor or
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5184
                                equal to the target FMRI.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5185
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5186
                        MATCH_GLOB
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5187
                                Indicates that the name portion of the pattern
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5188
                                uses fnmatch rules for pattern matching (shell-
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5189
                                style wildcards) and that the version can either
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5190
                                match exactly, match partially, or contain
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5191
                                wildcards.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5192
                """
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5193
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5194
                for pat in patterns:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5195
                        error = None
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5196
                        matcher = None
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5197
                        npat = None
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5198
                        try:
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5199
                                parts = pat.split("@", 1)
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5200
                                pat_stem = parts[0]
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5201
                                pat_ver = None
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5202
                                if len(parts) > 1:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5203
                                        pat_ver = parts[1]
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5204
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5205
                                if "*" in pat_stem or "?" in pat_stem:
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5206
                                        matcher = self.MATCH_GLOB
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5207
                                elif pat_stem.startswith("pkg:/") or \
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5208
                                    pat_stem.startswith("/"):
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5209
                                        matcher = self.MATCH_EXACT
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5210
                                else:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5211
                                        matcher = self.MATCH_FMRI
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5212
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5213
                                if matcher == self.MATCH_GLOB:
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  5214
                                        npat = fmri.MatchingPkgFmri(pat_stem)
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5215
                                else:
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  5216
                                        npat = fmri.PkgFmri(pat_stem)
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5217
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5218
                                if not pat_ver:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5219
                                        # Do nothing.
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5220
                                        pass
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5221
                                elif "*" in pat_ver or "?" in pat_ver or \
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5222
                                    pat_ver == "latest":
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5223
                                        npat.version = \
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  5224
                                            pkg.version.MatchingVersion(pat_ver)
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5225
                                else:
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5226
                                        npat.version = \
2958
868e07939116 16851082 build_release (aka build version) should not be displayed
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 2925
diff changeset
  5227
                                            pkg.version.Version(pat_ver)
2224
dba01788128c 17824 api install and update should allow specifying "latest" version of packages
Shawn Walker <shawn.walker@oracle.com>
parents: 2219
diff changeset
  5228
1835
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5229
                        except (fmri.FmriError, pkg.version.VersionError), e:
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5230
                                # Whatever the error was, return it.
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5231
                                error = e
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5232
                        yield (pat, error, npat, matcher)
13fdfa2f7993 15029 pkg list can traceback if character only allowed with wildcards used
Shawn Walker <shawn.walker@oracle.com>
parents: 1834
diff changeset
  5233
2524
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  5234
        def purge_history(self):
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  5235
                """Deletes all client history."""
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  5236
                be_name, be_uuid = bootenv.BootEnv.get_be_name(self._img.root)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  5237
                self._img.history.purge(be_name=be_name, be_uuid=be_uuid)
0c32a79b1684 17252 pkg.client.api should provide history management interface
Shawn Walker <shawn.walker@oracle.com>
parents: 2519
diff changeset
  5238
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5239
        def update_format(self):
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5240
                """Attempt to update the on-disk format of the image to the
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5241
                newest version.  Returns a boolean indicating whether any action
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5242
                was taken."""
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5243
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5244
                self._acquire_activity_lock()
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5245
                try:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5246
                        self._disable_cancel()
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5247
                        self._img.allow_ondisk_upgrade = True
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5248
                        return self._img.update_format(
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5249
                            progtrack=self.__progresstracker)
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5250
                except apx.CanceledException, e:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5251
                        self._cancel_done()
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5252
                        raise
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5253
                finally:
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5254
                        self._activity_lock.release()
2144
2ac203b826ab 7276 /var/pkg metadata needs reorg (looks busy)
Shawn Walker <shawn.walker@oracle.com>
parents: 2141
diff changeset
  5255
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5256
        def write_p5i(self, fileobj, pkg_names=None, pubs=None):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5257
                """Writes the publisher, repository, and provided package names
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5258
                to the provided file-like object 'fileobj' in JSON p5i format.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5259
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5260
                'fileobj' is only required to have a 'write' method that accepts
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5261
                data to be written as a parameter.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5262
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5263
                'pkg_names' is a dict of lists, tuples, or sets indexed by
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5264
                publisher prefix that contain package names, FMRI strings, or
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5265
                package info objects.  A prefix of "" can be used for packages
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5266
                that are not specific to a publisher.
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5267
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5268
                'pubs' is an optional list of publisher prefixes or Publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5269
                objects.  If not provided, the information for all publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5270
                (excluding those disabled) will be output."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5271
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5272
                if not pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5273
                        plist = [
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5274
                            p for p in self.get_publishers()
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5275
                            if not p.disabled
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5276
                        ]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5277
                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5278
                        plist = []
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5279
                        for p in pubs:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5280
                                if not isinstance(p, publisher.Publisher):
2219
60ad60f7592c 2152 standalone package support needed (on-disk format)
Shawn Walker <shawn.walker@oracle.com>
parents: 2215
diff changeset
  5281
                                        plist.append(self._img.get_publisher(
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5282
                                            prefix=p, alias=p))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5283
                                else:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5284
                                        plist.append(p)
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5285
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5286
                # Transform PackageInfo object entries into PkgFmri entries
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5287
                # before passing them to the p5i module.
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5288
                new_pkg_names = {}
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5289
                for pub in pkg_names:
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5290
                        pkglist = []
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5291
                        for p in pkg_names[pub]:
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5292
                                if isinstance(p, PackageInfo):
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5293
                                        pkglist.append(p.fmri)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 917
diff changeset
  5294
                                else:
1257
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5295
                                        pkglist.append(p)
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5296
                        new_pkg_names[pub] = pkglist
d911e4542c41 9025 pkg.client.api needs to use p5i module
Shawn Walker <srw@sun.com>
parents: 1256
diff changeset
  5297
                p5i.write(fileobj, plist, pkg_names=new_pkg_names)
716
b836c1b14137 4639 history result info differs for install and uninstall of nonexistent packages
Brock Pytlik <bpytlik@sun.com>
parents: 707
diff changeset
  5298
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5299
        def write_syspub(self, path, prefixes, version):
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5300
                """Write the syspub/version response to the provided path."""
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5301
                if version != 0:
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5302
                        raise apx.UnsupportedP5SVersion(version)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5303
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5304
                pubs = [
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5305
                    p for p in self.get_publishers()
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5306
                    if p.prefix in prefixes
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5307
                ]
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5308
                fd, fp = tempfile.mkstemp()
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5309
                try:
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5310
                        fh = os.fdopen(fd, "wb")
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5311
                        p5s.write(fh, pubs, self._img.cfg)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5312
                        fh.close()
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5313
                        portable.rename(fp, path)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5314
                except:
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5315
                        if os.path.exists(fp):
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5316
                                portable.remove(fp)
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5317
                        raise
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5318
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
  5319
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5320
class Query(query_p.Query):
1100
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  5321
        """This class is the object used to pass queries into the api functions.
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  5322
        It encapsulates the possible options available for a query as well as
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  5323
        the text of the query itself."""
22a8b08d460a 7364 documentation and code comments needed for fix for 6175
Brock Pytlik <bpytlik@sun.com>
parents: 1087
diff changeset
  5324
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5325
        def __init__(self, text, case_sensitive, return_actions=True,
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5326
            num_to_return=None, start_point=None):
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5327
                if return_actions:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5328
                        return_type = query_p.Query.RETURN_ACTIONS
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5329
                else:
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5330
                        return_type = query_p.Query.RETURN_PACKAGES
2961
b0a96696db84 15776364 SUNBT7150266 pkg search -r /usr/bin/* causes a traceback
thejaswini.k@oracle.com
parents: 2958
diff changeset
  5331
                try:
b0a96696db84 15776364 SUNBT7150266 pkg search -r /usr/bin/* causes a traceback
thejaswini.k@oracle.com
parents: 2958
diff changeset
  5332
                        query_p.Query.__init__(self, text, case_sensitive,
b0a96696db84 15776364 SUNBT7150266 pkg search -r /usr/bin/* causes a traceback
thejaswini.k@oracle.com
parents: 2958
diff changeset
  5333
                            return_type, num_to_return, start_point)
b0a96696db84 15776364 SUNBT7150266 pkg search -r /usr/bin/* causes a traceback
thejaswini.k@oracle.com
parents: 2958
diff changeset
  5334
                except query_p.QueryLengthExceeded, e:
b0a96696db84 15776364 SUNBT7150266 pkg search -r /usr/bin/* causes a traceback
thejaswini.k@oracle.com
parents: 2958
diff changeset
  5335
                        raise apx.ParseError(e)
941
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5336
e7bff46da54e 6175 search needs to be moved to version 1
Brock Pytlik <bpytlik@sun.com>
parents: 938
diff changeset
  5337
2488
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5338
def get_default_image_root(orig_cwd=None):
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5339
        """Returns a tuple of (root, exact_match) where 'root' is the absolute
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5340
        path of the default image root based on current environment given the
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5341
        client working directory and platform defaults, and 'exact_match' is a
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5342
        boolean specifying how the default should be treated by ImageInterface.
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5343
        Note that the root returned may not actually be the valid root of an
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5344
        image; it is merely the default location a client should use when
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5345
        initializing an ImageInterface (e.g. '/' is not a valid image on Solaris
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5346
        10).
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5347
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5348
        The ImageInterface object will use the root provided as a starting point
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5349
        to find an image, searching upwards through each parent directory until
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5350
        '/' is reached based on the value of exact_match.
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5351
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5352
        'orig_cwd' should be the original current working directory at the time
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5353
        of client startup.  This value is assumed to be valid if provided,
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5354
        although permission and access errors will be gracefully handled.
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5355
        """
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5356
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5357
        # If an image location wasn't explicitly specified, check $PKG_IMAGE in
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5358
        # the environment.
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5359
        root = os.environ.get("PKG_IMAGE")
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5360
        exact_match = True
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5361
        if not root:
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5362
                if os.environ.get("PKG_FIND_IMAGE") or \
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5363
                    portable.osname != "sunos":
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5364
                        # If no image location was found in the environment,
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5365
                        # then see if user enabled finding image or if current
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5366
                        # platform isn't Solaris.  If so, attempt to find the
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5367
                        # image starting with the working directory.
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5368
                        root = orig_cwd
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5369
                        if root:
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5370
                                exact_match = False
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5371
                if not root:
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5372
                        # If no image directory has been determined based on
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5373
                        # request or environment, default to live root.
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5374
                        root = misc.liveroot()
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5375
        return root, exact_match
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5376
010931d9cabe 18688 pkg clients shouldn't attempt to find an image at startup
Shawn Walker <shawn.walker@oracle.com>
parents: 2482
diff changeset
  5377
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5378
def image_create(pkg_client_name, version_id, root, imgtype, is_zone,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5379
    cancel_state_callable=None, facets=misc.EmptyDict, force=False,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5380
    mirrors=misc.EmptyI, origins=misc.EmptyI, prefix=None, refresh_allowed=True,
2100
6a366b063036 17144 Unix socket support is defunct
johansen <johansen@opensolaris.org>
parents: 2097
diff changeset
  5381
    repo_uri=None, ssl_cert=None, ssl_key=None, user_provided_dir=False,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5382
    progtrack=None, variants=misc.EmptyDict, props=misc.EmptyDict,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5383
    cmdpath=None):
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5384
        """Creates an image at the specified location.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5385
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5386
        'pkg_client_name' is a string containing the name of the client,
2991
75e616731cc3 16635525 EOL of packagemanager and related components
Shawn Walker <shawn.walker@oracle.com>
parents: 2961
diff changeset
  5387
        such as "pkg".
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5388
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5389
        'version_id' indicates the version of the api the client is
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5390
        expecting to use.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5391
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5392
        'root' is the absolute path of the directory where the image will
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5393
        be created.  If it does not exist, it will be created.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5394
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5395
        'imgtype' is an IMG_TYPE constant representing the type of image
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5396
        to create.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5397
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5398
        'is_zone' is a boolean value indicating whether the image being
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5399
        created is for a zone.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5400
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5401
        'cancel_state_callable' is an optional function reference that will
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5402
        be called if the cancellable status of an operation changes.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5403
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5404
        'facets' is a dictionary of facet names and values to set during
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5405
        the image creation process.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5406
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5407
        'force' is an optional boolean value indicating that if an image
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5408
        already exists at the specified 'root' that it should be overwritten.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5409
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5410
        'mirrors' is an optional list of URI strings that should be added to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5411
        all publishers configured during image creation as mirrors.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5412
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5413
        'origins' is an optional list of URI strings that should be added to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5414
        all publishers configured during image creation as origins.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5415
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5416
        'prefix' is an optional publisher prefix to configure as a publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5417
        for the new image if origins is provided, or to restrict which publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5418
        will be configured if 'repo_uri' is provided.  If this prefix does not
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5419
        match the publisher configuration retrieved from the repository, an
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5420
        UnknownRepositoryPublishers exception will be raised.  If not provided,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5421
        'refresh_allowed' cannot be False.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5422
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  5423
        'props' is an optional dictionary mapping image property names to values
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  5424
        to be set while creating the image.
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  5425
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5426
        'refresh_allowed' is an optional boolean value indicating whether
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5427
        publisher configuration data and metadata can be retrieved during
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5428
        image creation.  If False, 'repo_uri' cannot be specified and
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5429
        a 'prefix' must be provided.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5430
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5431
        'repo_uri' is an optional URI string of a package repository to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5432
        retrieve publisher configuration information from.  If the target
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5433
        repository supports this, all publishers found will be added to the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5434
        image and any origins or mirrors will be added to all of those
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5435
        publishers.  If the target repository does not support this, and a
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5436
        prefix was not specified, an UnsupportedRepositoryOperation exception
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5437
        will be raised.  If the target repository supports the operation, but
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5438
        does not provide complete configuration information, a
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5439
        RepoPubConfigUnavailable exception will be raised.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5440
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5441
        'ssl_cert' is an optional pathname of an SSL Certificate file to
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5442
        configure all publishers with and to use when retrieving publisher
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5443
        configuration information.  If provided, 'ssl_key' must also be
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5444
        provided.  The certificate file must be pem-encoded.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5445
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5446
        'ssl_key' is an optional pathname of an SSL Key file to configure all
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5447
        publishers with and to use when retrieving publisher configuration
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5448
        information.  If provided, 'ssl_cert' must also be provided.  The
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5449
        key file must be pem-encoded.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5450
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5451
        'user_provided_dir' is an optional boolean value indicating that the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5452
        provided 'root' was user-supplied and that additional error handling
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5453
        should be enforced.  This primarily affects cases where a relative
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5454
        root has been provided or the root was based on the current working
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5455
        directory.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5456
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5457
        'progtrack' is an optional ProgressTracker object.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5458
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5459
        'variants' is a dictionary of variant names and values to set during
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5460
        the image creation process.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5461
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5462
        Callers must provide one of the following when calling this function:
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5463
         * no 'prefix' and no 'origins'
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5464
         * a 'prefix' and 'repo_uri' (origins and mirrors are optional)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5465
         * no 'prefix' and a 'repo_uri'  (origins and mirrors are optional)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5466
         * a 'prefix' and 'origins'
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5467
        """
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5468
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5469
        # Caller must provide a prefix and repository, or no prefix and a
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5470
        # repository, or a prefix and origins, or no prefix and no origins.
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5471
        assert (prefix and repo_uri) or (not prefix and repo_uri) or (prefix and
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5472
            origins or (not prefix and not origins))
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5473
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5474
        # If prefix isn't provided and refresh isn't allowed, then auto-config
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5475
        # cannot be done.
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5476
        assert (prefix or refresh_allowed) or not repo_uri
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5477
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5478
        destroy_root = False
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5479
        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5480
                destroy_root = not os.path.exists(root)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5481
        except EnvironmentError, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5482
                if e.errno == errno.EACCES:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5483
                        raise apx.PermissionsException(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5484
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5485
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5486
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5487
        # The image object must be created first since transport may be
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5488
        # needed to retrieve publisher configuration information.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5489
        img = image.Image(root, force=force, imgtype=imgtype,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5490
            progtrack=progtrack, should_exist=False,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5491
            user_provided_dir=user_provided_dir, cmdpath=cmdpath,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5492
            props=props)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5493
        api_inst = ImageInterface(img, version_id,
2339
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5494
            progtrack, cancel_state_callable, pkg_client_name,
aa5954c06b9d 16148 need linked image support for zones, phase 1
Edward Pilatowicz <edward.pilatowicz@oracle.com>
parents: 2319
diff changeset
  5495
            cmdpath=cmdpath)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5496
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5497
        pubs = []
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5498
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5499
        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5500
                if repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5501
                        # Assume auto configuration.
1834
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  5502
                        if ssl_cert:
3010
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5503
                                try:
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5504
                                        misc.validate_ssl_cert(
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5505
                                            ssl_cert,
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5506
                                            prefix=prefix,
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5507
                                            uri=repo_uri)
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5508
                                except apx.ExpiringCertificate, e:
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5509
                                        logger.warning(e)
1834
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  5510
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5511
                        repo = publisher.RepositoryURI(repo_uri,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5512
                            ssl_cert=ssl_cert, ssl_key=ssl_key)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5513
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5514
                        pubs = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5515
                        try:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5516
                                pubs = api_inst.get_publisherdata(repo=repo)
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5517
                        except apx.UnsupportedRepositoryOperation:
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5518
                                if not prefix:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5519
                                        raise apx.RepoPubConfigUnavailable(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5520
                                            location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5521
                                # For a v0 repo where a prefix was specified,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5522
                                # fallback to manual configuration.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5523
                                if not origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5524
                                        origins = [repo_uri]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5525
                                repo_uri = None
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5526
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5527
                        if not prefix and not pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5528
                                # Empty repository configuration.
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5529
                                raise apx.RepoPubConfigUnavailable(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5530
                                    location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5531
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5532
                        if repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5533
                                for p in pubs:
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5534
                                        psrepo = p.repository
1795
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5535
                                        if not psrepo:
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5536
                                                # Repository configuration info
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5537
                                                # was not provided, so assume
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5538
                                                # origin is repo_uri.
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5539
                                                p.repository = \
1795
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5540
                                                    publisher.Repository(
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5541
                                                    origins=[repo_uri])
1795
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5542
                                        elif not psrepo.origins:
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5543
                                                # Repository configuration was
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5544
                                                # provided, but without an
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5545
                                                # origin.  Assume the repo_uri
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5546
                                                # is the origin.
1b3bed835773 14856 image-create / set-publisher shouldn't require repository configuration to have origins
Shawn Walker <srw@sun.com>
parents: 1764
diff changeset
  5547
                                                psrepo.add_origin(repo_uri)
1895
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  5548
                                        elif repo not in psrepo.origins:
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  5549
                                                # If the repo_uri used is not
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  5550
                                                # in the list of sources, then
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  5551
                                                # add it as the first origin.
0a260cc2a689 15762 client support for filesystem-based repository access
Shawn Walker <shawn.walker@oracle.com>
parents: 1893
diff changeset
  5552
                                                psrepo.origins.insert(0, repo)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5553
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5554
                if prefix and not repo_uri:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5555
                        # Auto-configuration not possible or not requested.
1834
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  5556
                        if ssl_cert:
3010
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5557
                                try:
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5558
                                        misc.validate_ssl_cert(
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5559
                                            ssl_cert,
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5560
                                            prefix=prefix,
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5561
                                            uri=origins[0])
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5562
                                except apx.ExpiringCertificate, e:
2741200f3d9e 17768096 pkg.client.api.image_create should not raise exception for expiring certificates
Yiteng Zhang <yiteng.zhang@oracle.com>
parents: 3003
diff changeset
  5563
                                        logger.warning(e)
1834
43fcb0ca2c26 15120 image-create fails for ssl-based publisher repositories
Shawn Walker <shawn.walker@oracle.com>
parents: 1829
diff changeset
  5564
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5565
                        repo = publisher.Repository()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5566
                        for o in origins:
2828
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
  5567
                                repo.add_origin(o) # pylint: disable=E1103
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5568
                        for m in mirrors:
2828
d1d4d120c4c5 15875724 pylint update broke the build
Tim Foster <tim.s.foster@oracle.com>
parents: 2819
diff changeset
  5569
                                repo.add_mirror(m) # pylint: disable=E1103
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5570
                        pub = publisher.Publisher(prefix,
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5571
                            repository=repo)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5572
                        pubs = [pub]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5573
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5574
                if prefix and prefix not in pubs:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5575
                        # If publisher prefix requested isn't found in the list
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5576
                        # of publishers at this point, then configuration isn't
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5577
                        # possible.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5578
                        known = [p.prefix for p in pubs]
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5579
                        raise apx.UnknownRepositoryPublishers(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5580
                            known=known, unknown=[prefix], location=repo_uri)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5581
                elif prefix:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5582
                        # Filter out any publishers that weren't requested.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5583
                        pubs = [
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5584
                            p for p in pubs
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5585
                            if p.prefix == prefix
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5586
                        ]
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5587
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5588
                # Add additional origins and mirrors that weren't found in the
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5589
                # publisher configuration if provided.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5590
                for p in pubs:
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5591
                        pr = p.repository
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5592
                        for o in origins:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5593
                                if not pr.has_origin(o):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5594
                                        pr.add_origin(o)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5595
                        for m in mirrors:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5596
                                if not pr.has_mirror(m):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5597
                                        pr.add_mirror(m)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5598
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5599
                # Set provided SSL Cert/Key for all configured publishers.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5600
                for p in pubs:
2310
ce10607d5332 11684 desire option to not propagate certs to non-global zones
Brock Pytlik <brock.pytlik@oracle.com>
parents: 2293
diff changeset
  5601
                        repo = p.repository
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5602
                        for o in repo.origins:
2269
460556da69d6 17278 pkg(1) should allow mixing https origins with other types
Shawn Walker <shawn.walker@oracle.com>
parents: 2260
diff changeset
  5603
                                if o.scheme not in publisher.SSL_SCHEMES:
460556da69d6 17278 pkg(1) should allow mixing https origins with other types
Shawn Walker <shawn.walker@oracle.com>
parents: 2260
diff changeset
  5604
                                        continue
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5605
                                o.ssl_cert = ssl_cert
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5606
                                o.ssl_key = ssl_key
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5607
                        for m in repo.mirrors:
2269
460556da69d6 17278 pkg(1) should allow mixing https origins with other types
Shawn Walker <shawn.walker@oracle.com>
parents: 2260
diff changeset
  5608
                                if m.scheme not in publisher.SSL_SCHEMES:
460556da69d6 17278 pkg(1) should allow mixing https origins with other types
Shawn Walker <shawn.walker@oracle.com>
parents: 2260
diff changeset
  5609
                                        continue
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5610
                                m.ssl_cert = ssl_cert
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5611
                                m.ssl_key = ssl_key
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5612
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5613
                img.create(pubs, facets=facets, is_zone=is_zone,
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5614
                    progtrack=progtrack, refresh_allowed=refresh_allowed,
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 2024
diff changeset
  5615
                    variants=variants, props=props)
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5616
        except EnvironmentError, e:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5617
                if e.errno == errno.EACCES:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5618
                        raise apx.PermissionsException(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5619
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5620
                if e.errno == errno.EROFS:
1970
60471574c487 16238 client api should ignore invalid and not yet supported packages
Shawn Walker <shawn.walker@oracle.com>
parents: 1937
diff changeset
  5621
                        raise apx.ReadOnlyFileSystemException(
1736
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5622
                            e.filename)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5623
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5624
        except:
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5625
                # Ensure a defunct image isn't left behind.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5626
                img.destroy()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5627
                if destroy_root and \
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5628
                    os.path.abspath(root) != "/" and \
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5629
                    os.path.exists(root):
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5630
                        # Root didn't exist before create and isn't '/',
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5631
                        # so remove it.
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5632
                        shutil.rmtree(root, True)
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5633
                raise
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5634
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5635
        img.cleanup_downloads()
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5636
727dda1e7968 11522 pkg should require publisher prefix to match repository information
Shawn Walker <srw@sun.com>
parents: 1735
diff changeset
  5637
        return api_inst