src/modules/client/image.py
author Shawn Walker <srw@sun.com>
Mon, 08 Feb 2010 09:56:21 -0600
changeset 1733 7ffa6f902aa0
parent 1710 139720e2e756
child 1736 727dda1e7968
permissions -rw-r--r--
9218 pkg.client.api should check for cross-alias/prefix duplicates
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: 1507
diff changeset
     1
#!/usr/bin/python
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     2
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     3
# CDDL HEADER START
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     4
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     8
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    11
# See the License for the specific language governing permissions
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    12
# and limitations under the License.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    13
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    19
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    20
# CDDL HEADER END
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    21
#
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    22
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    23
#
1672
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1631
diff changeset
    24
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    25
# Use is subject to license terms.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    26
#
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    27
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
    28
import datetime
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
    29
import errno
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
    30
import fcntl
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    31
import os
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    32
import platform
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    33
import shutil
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    34
import tempfile
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
    35
import time
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
    36
import urllib
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
    37
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
    38
from contextlib import contextmanager
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
    39
from pkg.client import global_settings
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
    40
logger = global_settings.logger
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
    41
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
    42
import pkg.catalog
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    43
import pkg.client.api_errors            as api_errors
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    44
import pkg.client.history               as history
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    45
import pkg.client.imageconfig           as imageconfig
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    46
import pkg.client.imageplan             as imageplan
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    47
import pkg.client.pkgplan               as pkgplan
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    48
import pkg.client.progress              as progress
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    49
import pkg.client.publisher             as publisher
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    50
import pkg.client.transport.transport   as transport
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
    51
import pkg.fmri
1191
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    52
import pkg.manifest                     as manifest
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    53
import pkg.misc                         as misc
a48bee2a4b2e 305 http_proxy value needs more checking for valid url syntax
johansen <johansen@sun.com>
parents: 1158
diff changeset
    54
import pkg.portable                     as portable
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
    55
import pkg.server.catalog
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
    56
import pkg.version
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
    57
1328
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1288
diff changeset
    58
from pkg.client.debugvalues import DebugValues
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
    59
from pkg.client.imagetypes import IMG_USER, IMG_ENTIRE
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
    60
from pkg.misc import CfgCacheError, EmptyI, EmptyDict
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    61
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    62
img_user_prefix = ".org.opensolaris,pkg"
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    63
img_root_prefix = "var/pkg"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    64
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
    65
IMG_PUB_DIR = "publisher"
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
    66
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    67
class Image(object):
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    68
        """An Image object is a directory tree containing the laid-down contents
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    69
        of a self-consistent graph of Packages.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    70
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    71
        An Image has a root path.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    72
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    73
        An Image of type IMG_ENTIRE does not have a parent Image.  Other Image
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    74
        types must have a parent Image.  The external state of the parent Image
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    75
        must be accessible from the Image's context, or duplicated within the
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    76
        Image (IMG_PARTIAL for zones, for instance).
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    77
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    78
        The parent of a user Image can be a partial Image.  The parent of a
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    79
        partial Image must be an entire Image.
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    80
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    81
        An Image of type IMG_USER stores its external state at self.root +
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    82
        ".org.opensolaris,pkg".
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    83
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    84
        An Image of type IMG_ENTIRE or IMG_PARTIAL stores its external state at
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    85
        self.root + "/var/pkg".
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
    86
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    87
        An Image needs to be able to have a different repository set than the
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    88
        system's root Image.
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
    89
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    90
        Directory layout
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
    91
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    92
          $IROOT/file
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    93
               Directory containing file hashes of installed packages.
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    94
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    95
          $IROOT/pkg
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
    96
               Directory containing manifests.
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
    97
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
    98
          $IROOT/index
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
    99
               Directory containing search indices.
60
6bd5cd83cfb1 Reverse index database and searching support.
Danek Duvall <danek.duvall@sun.com>
parents: 59
diff changeset
   100
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   101
          $IROOT/cfg_cache
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   102
               File containing image's cached configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   103
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   104
          $IROOT/opaque
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   105
               File containing image's opaque state.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   106
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   107
          $IROOT/publisher
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   108
                Directory containing publisher metadata.
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   109
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   110
        All of these directories and files other than state are considered
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   111
        essential for any image to be complete. To add a new essential file or
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   112
        subdirectory, the following steps should be done.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   113
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   114
        If it's a directory, add it to the image_subdirs list below and it will
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   115
        be created automatically. The programmer must fill the directory as
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   116
        needed. If a file is added, the programmer is responsible for creating
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   117
        that file during image creation at an appropriate place and time.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   118
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   119
        If a directory is required to be present in order for an image to be
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   120
        identifiable as such, it should go into required_subdirs instead.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   121
        However, upgrade issues abound; this list should probably not change.
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
   122
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   123
        Once those steps have been carried out, the change should be added
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   124
        to the test suite for image corruption (t_pkg_install_corrupt_image.py).
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   125
        This will likely also involve a change to
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   126
        SingleDepotTestCaseCorruptImage in testutils.py. Each of these files
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   127
        outline what must be updated.
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   128
19
c5d16aa074bf begin comments on Image object
"Stephen Hahn <sch@sun.com>"
parents:
diff changeset
   129
        XXX Root path probably can't be absolute, so that we can combine or
30
f06ad6cb4b3f stop using flavour terminology
Stephen Hahn <sch@sun.com>
parents: 29
diff changeset
   130
        reuse Image contents.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   131
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   132
        XXX Image file format?  Image file manipulation API?"""
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   133
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   134
        # Class constants
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   135
        IMG_CATALOG_KNOWN = "known"
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   136
        IMG_CATALOG_INSTALLED = "installed"
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   137
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   138
        # Please note that the values of these PKG_STATE constants should not
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   139
        # be changed as it would invalidate existing catalog data stored in the
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   140
        # image.  This means that if a constant is removed, the values of the
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   141
        # other constants should not change, etc.
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   142
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   143
        # This state indicates that a package is present in a repository
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   144
        # catalog.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   145
        PKG_STATE_KNOWN = 0
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   146
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   147
        # This is a transitory state used to indicate that a package is no
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   148
        # longer present in a repository catalog; it is only used to clear
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   149
        # PKG_STATE_KNOWN.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   150
        PKG_STATE_UNKNOWN = 1
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   151
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   152
        # This state indicates that a package is installed.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   153
        PKG_STATE_INSTALLED = 2
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   154
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   155
        # This is a transitory state used to indicate that a package is no
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   156
        # longer installed; it is only used to clear PKG_STATE_INSTALLED.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   157
        PKG_STATE_UNINSTALLED = 3
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   158
        PKG_STATE_UPGRADABLE = 4
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   159
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   160
        # These states are used to indicate the package's related catalog
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   161
        # version.  This is helpful to consumers of the catalog data so that
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   162
        # they can be aware of what metadata may not immediately available
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   163
        # (require manifest retrieval) based on the catalog version.
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   164
        PKG_STATE_V0 = 6
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
   165
        PKG_STATE_V1 = 7
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   166
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
   167
        PKG_STATE_OBSOLETE = 8
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
   168
        PKG_STATE_RENAMED = 9
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
   169
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   170
        # Class properties
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   171
        required_subdirs = [ "file", "pkg" ]
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   172
        image_subdirs = required_subdirs + [ "index", IMG_PUB_DIR,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   173
            "state/installed", "state/known" ]
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   174
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   175
        def __init__(self, root, user_provided_dir=False, progtrack=None,
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   176
            should_exist=True, imgtype=None, force=False):
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   177
                if should_exist:
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   178
                        assert(imgtype is None)
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   179
                        assert(not force)
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   180
                else:
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   181
                        assert(imgtype is not None)
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   182
                self.__init_catalogs()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   183
                self.__upgraded = False
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   184
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   185
                self.attrs = {
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   186
                    "Policy-Require-Optional": False,
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   187
                    "Policy-Pursue-Latest": True
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   188
                }
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   189
                self.blocking_locks = False
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   190
                self.cfg_cache = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   191
                self.dl_cache_dir = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   192
                self.dl_cache_incoming = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   193
                self.history = history.History()
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
   194
                self.imageplan = None # valid after evaluation succeeds
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   195
                self.img_prefix = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   196
                self.imgdir = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   197
                self.index_dir = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   198
                self.is_user_cache_dir = False
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   199
                self.pkgdir = None
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   200
                self.root = root
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   201
                self.__lock = pkg.nrlock.NRLock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   202
                self.__locked = False
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   203
                self.__lockf = 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
   204
                self.__req_dependents = None
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   205
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   206
                # Transport operations for this image
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   207
                self.transport = transport.Transport(self)
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   208
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   209
                if should_exist:
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   210
                        self.find_root(self.root, user_provided_dir,
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   211
                            progtrack)
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   212
                else:
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   213
                        if not force and self.image_type(self.root) != None:
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   214
                                raise api_errors.ImageAlreadyExists(self.root)
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   215
                        if not force and os.path.exists(self.root) and \
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   216
                            len(os.listdir(self.root)) > 0:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   217
                                raise api_errors.CreatingImageInNonEmptyDir(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   218
                                    self.root)
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   219
                        self.__set_dirs(root=self.root, imgtype=imgtype,
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   220
                            progtrack=progtrack)
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   221
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   222
                # a place to keep info about saved_files; needed by file action
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   223
                self.saved_files = {}
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   224
674
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   225
                # right now we don't explicitly set dir/file modes everywhere;
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   226
                # set umask to proper value to prevent problems w/ overly
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   227
                # locked down umask.
674
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   228
                os.umask(0022)
e740c8c3bed1 166 os.makedirs() does not set directory mode
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 664
diff changeset
   229
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   230
        def _check_subdirs(self, sub_d, prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   231
                for n in self.required_subdirs:
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   232
                        if not os.path.isdir(os.path.join(sub_d, prefix, n)):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   233
                                return False
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   234
                return True
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   235
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   236
        def __catalog_loaded(self, name):
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   237
                """Returns a boolean value indicating whether the named catalog
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   238
                has already been loaded.  This is intended to be used as an
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   239
                optimization function to determine which catalog to request."""
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   240
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   241
                return name in self.__catalogs
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   242
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   243
        def __init_catalogs(self):
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   244
                """Initializes default catalog state.  Actual data is provided
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   245
                on demand via get_catalog()"""
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   246
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   247
                # This is used to cache image catalogs.
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   248
                self.__catalogs = {}
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   249
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   250
                # This is used to keep track of what packages have been added
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   251
                # to IMG_CATALOG_KNOWN by set_pkg_state().
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   252
                self.__catalog_new_installs = set()
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   253
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   254
        @property
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   255
        def locked(self):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   256
                """Returns a boolean value indicating whether the image is
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   257
                currently locked."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   258
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   259
                return self.__locked
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   260
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   261
        @contextmanager
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   262
        def locked_op(self, op, allow_unprivileged=False):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   263
                """Helper method for executing an image-modifying operation
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   264
                that needs locking.  It also automatically handles calling
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   265
                log_operation_start and log_operation_end.  Locking behaviour
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   266
                is controlled by the blocking_locks image property.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   267
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   268
                'allow_unprivileged' is an optional boolean value indicating
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   269
                that permissions-related exceptions should be ignored when
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   270
                attempting to obtain the lock as the related operation will
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   271
                still work correctly even though the image cannot (presumably)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   272
                be modified.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   273
                """
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   274
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   275
                error = None
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   276
                self.lock(allow_unprivileged=allow_unprivileged)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   277
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   278
                        self.history.log_operation_start(op)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   279
                        yield
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   280
                except Exception, e:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   281
                        error = e
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   282
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   283
                finally:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   284
                        self.history.log_operation_end(error=error)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   285
                        self.unlock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   286
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   287
        def lock(self, allow_unprivileged=False):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   288
                """Locks the image in preparation for an image-modifying
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   289
                operation.  Raises an ImageLockedError exception on failure.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   290
                Locking behaviour is controlled by the blocking_locks image
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   291
                property.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   292
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   293
                'allow_unprivileged' is an optional boolean value indicating
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   294
                that permissions-related exceptions should be ignored when
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   295
                attempting to obtain the lock as the related operation will
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   296
                still work correctly even though the image cannot (presumably)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   297
                be modified.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   298
                """
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   299
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   300
                blocking = self.blocking_locks
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   301
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   302
                # First, attempt to obtain a thread lock.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   303
                if not self.__lock.acquire(blocking=blocking):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   304
                        raise api_errors.ImageLockedError()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   305
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   306
                self.__locked = True
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   307
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   308
                        # Attempt to obtain a file lock.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   309
                        self.__lock_process()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   310
                except api_errors.PermissionsException:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   311
                        if not allow_unprivileged:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   312
                                self.__lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   313
                                raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   314
                except:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   315
                        # If process lock fails, ensure thread lock is released.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   316
                        self.__lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   317
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   318
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   319
        def __lock_process(self):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   320
                """Locks the image to prevent modification by other
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   321
                processes."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   322
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   323
                if not os.path.exists(self.imgdir):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   324
                        # Image structure doesn't exist yet so a file lock
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   325
                        # cannot be obtained.  This path should only happen
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   326
                        # during image-create.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   327
                        return
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   328
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   329
                # Attempt to obtain a file lock for the image.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   330
                lfpath = os.path.join(self.imgdir, "lock")
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   331
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   332
                lock_type = fcntl.LOCK_EX
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   333
                if not self.blocking_locks:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   334
                        lock_type |= fcntl.LOCK_NB
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   335
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   336
                # Attempt an initial open of the lock file.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   337
                lf = None
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   338
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   339
                        lf = open(lfpath, "ab+")
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   340
                except EnvironmentError, e:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   341
                        if e.errno == errno.EACCES:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   342
                                raise api_errors.PermissionsException(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   343
                                    e.filename)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   344
                        if e.errno == errno.EROFS:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   345
                                raise api_errors.ReadOnlyFileSystemException(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   346
                                    e.filename)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   347
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   348
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   349
                # Attempt to lock the file.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   350
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   351
                        fcntl.lockf(lf, lock_type)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   352
                except IOError, e:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   353
                        if e.errno not in (errno.EAGAIN, errno.EACCES):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   354
                                raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   355
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   356
                        # If the lock failed (because it is likely contended),
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   357
                        # then extract the information about the lock acquirer
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   358
                        # and raise an exception.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   359
                        pid_data = lf.read().strip()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   360
                        pid, pid_name, hostname, lock_ts = \
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   361
                            pid_data.split("\n", 4)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   362
                        raise api_errors.ImageLockedError(pid=pid,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   363
                            pid_name=pid_name, hostname=hostname)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   364
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   365
                # Store lock time as ISO-8601 basic UTC timestamp in lock file.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   366
                lock_ts = pkg.catalog.now_to_basic_ts()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   367
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   368
                # Store information about the lock acquirer and write it.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   369
                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   370
                        lf.truncate(0)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   371
                        lf.write("\n".join((str(os.getpid()),
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   372
                            global_settings.client_name,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   373
                            platform.node(), lock_ts, "\n")))
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   374
                        lf.flush()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   375
                        self.__lockf = lf
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   376
                except EnvironmentError, e:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   377
                        if e.errno == errno.EACCES:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   378
                                raise api_errors.PermissionsException(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   379
                                    e.filename)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   380
                        if e.errno == errno.EROFS:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   381
                                raise api_errors.ReadOnlyFileSystemException(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   382
                                    e.filename)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   383
                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   384
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   385
        def unlock(self):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   386
                """Unlocks the image."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   387
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   388
                if self.__lockf:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   389
                        # To avoid race conditions with the next caller waiting
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   390
                        # for the lock file, it is simply truncated instead of
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   391
                        # removed.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   392
                        self.__lockf.truncate(0)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   393
                        self.__lockf.close()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   394
                        self.__lockf = None
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   395
                self.__locked = False
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   396
                self.__lock.release()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   397
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   398
        def image_type(self, d):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   399
                """Returns the type of image at directory: d; or None"""
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   400
                rv = None
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   401
                if os.path.isdir(os.path.join(d, img_user_prefix)) and \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   402
                        os.path.isfile(os.path.join(d, img_user_prefix,
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   403
                            imageconfig.CFG_FILE)) and \
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   404
                            self._check_subdirs(d, img_user_prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   405
                        rv = IMG_USER
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   406
                elif os.path.isdir(os.path.join(d, img_root_prefix)) \
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   407
                         and os.path.isfile(os.path.join(d,
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   408
                             img_root_prefix, imageconfig.CFG_FILE)) and \
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   409
                             self._check_subdirs(d, img_root_prefix):
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   410
                        rv = IMG_ENTIRE
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   411
                return rv
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   412
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   413
        def find_root(self, d, exact_match=False, progtrack=None):
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   414
                # Ascend from the given directory d to find first
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   415
                # encountered image.  If exact_match is true, if the
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   416
                # image found doesn't match startd, raise an
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   417
                # ImageNotFoundException.
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
   418
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   419
                startd = d
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   420
                # eliminate problem if relative path such as "." is passed in
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   421
                d = os.path.realpath(d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   422
                while True:
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   423
                        imgtype = self.image_type(d)
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   424
                        if imgtype == IMG_USER:
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   425
                                # XXX Should look at image file to determine
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   426
                                # repo URIs.
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   427
                                if exact_match and \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   428
                                    os.path.realpath(startd) != \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   429
                                    os.path.realpath(d):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   430
                                        raise api_errors.ImageNotFoundException(
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   431
                                            exact_match, startd, d)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   432
                                self.__set_dirs(imgtype=imgtype, root=d,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   433
                                    progtrack=progtrack)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   434
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   435
                                return
582
303fa3b78f93 3588 Ensure that users don't image-create over top of an image
Brad Hall <bhall@eng.sun.com>
parents: 577
diff changeset
   436
                        elif imgtype == IMG_ENTIRE:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   437
                                # XXX Look at image file to determine
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   438
                                # repo URIs.
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   439
                                # XXX Look at image file to determine if this
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   440
                                # image is a partial image.
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   441
                                if exact_match and \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   442
                                    os.path.realpath(startd) != \
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   443
                                    os.path.realpath(d):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   444
                                        raise api_errors.ImageNotFoundException(
561
be1ad23e7704 1651 pkg treats -R <bogus-dir> as "use the image at /"
Brock Pytlik <bpytlik@sun.com>
parents: 560
diff changeset
   445
                                            exact_match, startd, d)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   446
                                self.__set_dirs(imgtype=imgtype, root=d,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   447
                                    progtrack=progtrack)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
   448
                                self.attrs["Build-Release"] = "5.11"
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   449
                                return
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   450
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   451
                        # XXX follow symlinks or not?
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   452
                        oldpath = d
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   453
                        d = os.path.normpath(os.path.join(d, os.path.pardir))
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   454
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   455
                        # Make sure we are making progress and aren't in an
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   456
                        # infinite loop.
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   457
                        #
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   458
                        # (XXX - Need to deal with symlinks here too)
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
   459
                        if d == oldpath:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
   460
                                raise api_errors.ImageNotFoundException(
596
f4519e2a99bc 3704 InventoryException raised if optional dependencies not in catalog
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 583
diff changeset
   461
                                    exact_match, startd, d)
26
ab188d4682d5 catalog processing begins
"Stephen Hahn <sch@sun.com>"
parents: 22
diff changeset
   462
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   463
        def __load_config(self):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   464
                """Load this image's cached configuration from the default
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   465
                location."""
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   466
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   467
                # XXX Incomplete with respect to doc/image.txt description of
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   468
                # configuration.
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   469
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   470
                if self.root == None:
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   471
                        raise RuntimeError, "self.root must be set"
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   472
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   473
                ic = imageconfig.ImageConfig(self.root,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   474
                    self._get_publisher_meta_dir())
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   475
                ic.read(self.imgdir)
1111
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1107
diff changeset
   476
                self.cfg_cache = ic
26c3e2407c53 8570 zone installer needs support for ssl certs & keys
Dan Price <dp@eng.sun.com>
parents: 1107
diff changeset
   477
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   478
                for pub in self.gen_publishers(inc_disabled=True):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   479
                        pub.transport = self.transport
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   480
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   481
        def save_config(self):
1143
71becfca5cfd 8777 image-create traceback with --no-refresh
Shawn Walker <srw@sun.com>
parents: 1141
diff changeset
   482
                # First, create the image directories if they haven't been, so
71becfca5cfd 8777 image-create traceback with --no-refresh
Shawn Walker <srw@sun.com>
parents: 1141
diff changeset
   483
                # the cfg_cache can be written.
71becfca5cfd 8777 image-create traceback with --no-refresh
Shawn Walker <srw@sun.com>
parents: 1141
diff changeset
   484
                self.mkdirs()
786
a400f8c4d1c0 2340 support authority enable and disable
Tom Mueller <Tom.Mueller@sun.com>
parents: 756
diff changeset
   485
                self.cfg_cache.write(self.imgdir)
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   486
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   487
        # XXX mkdirs and set_attrs() need to be combined into a create
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   488
        # operation.
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   489
        def mkdirs(self):
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   490
                for sd in self.image_subdirs:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   491
                        if os.path.isdir(os.path.join(self.imgdir, sd)):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   492
                                continue
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   493
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   494
                        try:
397
617be57c5f2b 777 Image.find_root thinks a repository is an image
Brock Pytlik <bpytlik@sun.com>
parents: 394
diff changeset
   495
                                os.makedirs(os.path.join(self.imgdir, sd))
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   496
                        except EnvironmentError, e:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   497
                                if e.errno == errno.EACCES:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   498
                                        raise api_errors.PermissionsException(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   499
                                            e.filename)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   500
                                if e.errno == errno.EROFS:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   501
                                        raise api_errors.ReadOnlyFileSystemException(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   502
                                            e.filename)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   503
                                raise
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   504
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   505
        def __set_dirs(self, imgtype, root, progtrack=None):
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   506
                self.type = imgtype
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   507
                self.root = root
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   508
                if self.type == IMG_USER:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   509
                        self.img_prefix = img_user_prefix
22
379f0f6809ff pkgsend open, pkgsend add file, pkgsend close; Transaction object
"Stephen Hahn <sch@sun.com>"
parents: 19
diff changeset
   510
                else:
271
ec8a7669bff2 659 package that delivers existing automounter mountpoint fails installation
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 268
diff changeset
   511
                        self.img_prefix = img_root_prefix
993
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   512
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   513
                # Change directory to the root of the image so that we can
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   514
                # remove any directories beneath us.  If we're changing the
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   515
                # image, don't chdir, as we're likely changing to a new BE
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   516
                # and want to be able to unmount it later.
999
04c29b9c97a0 7811 pkg image-create no longer creates image path if it doesn't exist
Danek Duvall <danek.duvall@sun.com>
parents: 996
diff changeset
   517
                if not self.imgdir and os.path.isdir(root):
993
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   518
                        os.chdir(root)
7cfbab7739c3 588 directory remove of cwd fails due to EPERM or EINVAL
Danek Duvall <danek.duvall@sun.com>
parents: 988
diff changeset
   519
1133
2c28e4526a6e 8720 image-create with a non-absolute path can cause strange results
Shawn Walker <srw@sun.com>
parents: 1125
diff changeset
   520
                        # The specified root may have been a relative path.
2c28e4526a6e 8720 image-create with a non-absolute path can cause strange results
Shawn Walker <srw@sun.com>
parents: 1125
diff changeset
   521
                        self.root = os.getcwd()
2c28e4526a6e 8720 image-create with a non-absolute path can cause strange results
Shawn Walker <srw@sun.com>
parents: 1125
diff changeset
   522
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
   523
                if not os.path.isabs(self.root):
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
   524
                        self.root = os.path.abspath(self.root)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
   525
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   526
                # If current image is locked, then it should be unlocked
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   527
                # and then relocked after the imgdir is changed.  This
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   528
                # ensures that alternate BE scenarios work.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   529
                relock = self.imgdir and self.__locked
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   530
                if relock:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   531
                        self.unlock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   532
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
   533
                self.imgdir = os.path.join(self.root, self.img_prefix)
1037
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
   534
                self.pkgdir = os.path.join(self.imgdir, "pkg")
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   535
                self.history.root_dir = self.imgdir
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   536
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   537
                if relock:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   538
                        self.lock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   539
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   540
                if "PKG_CACHEDIR" in os.environ:
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   541
                        self.dl_cache_dir = os.path.normpath( \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   542
                            os.environ["PKG_CACHEDIR"])
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   543
                        self.is_user_cache_dir = True
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   544
                else:
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   545
                        self.dl_cache_dir = os.path.normpath( \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   546
                            os.path.join(self.imgdir, "download"))
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   547
                self.dl_cache_incoming = os.path.normpath(os.path.join(
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   548
                    self.dl_cache_dir, "incoming-%d" % os.getpid()))
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
   549
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   550
                # Test if we have the permissions to create the cache
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   551
                # incoming directory in this hiearachy.  If not, we'll need to
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   552
                # move it somewhere else.
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   553
                try:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   554
                        os.makedirs(self.dl_cache_incoming)
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   555
                except EnvironmentError, e:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   556
                        if e.errno == errno.EACCES or e.errno == errno.EROFS:
1672
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1631
diff changeset
   557
                                self.dl_cache_dir = tempfile.mkdtemp(
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1631
diff changeset
   558
                                    prefix="download-%d-" % os.getpid())
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1631
diff changeset
   559
                                self.dl_cache_incoming = os.path.normpath(
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1631
diff changeset
   560
                                    os.path.join(self.dl_cache_dir,
3a71439a03f3 13021 file manager exceptions should be api exceptions
Shawn Walker <srw@sun.com>
parents: 1631
diff changeset
   561
                                    "incoming-%d" % os.getpid()))
1503
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   562
                else:
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   563
                        os.removedirs(self.dl_cache_incoming)
78d56b8ee320 12698 download directory must be accessible to non-privileged users
johansen <johansen@sun.com>
parents: 1463
diff changeset
   564
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
   565
                # Forcibly discard image catalogs so they can be re-loaded
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
   566
                # from the new location if they are already loaded.  This
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
   567
                # also prevents scribbling on image state information in
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
   568
                # the wrong location.
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
   569
                self.__init_catalogs()
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
   570
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   571
                if not os.path.exists(os.path.join(self.imgdir,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   572
                    imageconfig.CFG_FILE)):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   573
                        # New images inherently use the newest image format.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   574
                        # This must be set *before* creating the Publisher
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   575
                        # object so that the correct meta_root is set.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   576
                        self.__upgraded = True
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   577
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   578
                        self.__upgraded = not os.path.exists(os.path.join(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   579
                            self.imgdir, "catalog"))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   580
                        self.__load_config()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   581
                        self.__check_image(progtrack=progtrack)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   582
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   583
        def __check_image(self, progtrack=None):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   584
                """This does some basic sanity checks on the image structure
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   585
                and attempts to correct any errors it finds."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   586
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   587
                if not self.__upgraded:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   588
                        with self.locked_op("upgrade-image",
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   589
                            allow_unprivileged=True):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   590
                                return self.__upgrade_image(progtrack=progtrack)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   591
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   592
                # If the image has already been upgraded, first ensure that its
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   593
                # structure is valid.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   594
                self.mkdirs()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   595
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   596
                # Ensure structure for publishers is valid.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   597
                for pub in self.gen_publishers():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   598
                        pub.create_meta_root()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   599
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   600
                # Once its structure is valid, then ensure state information
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   601
                # is intact.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   602
                kdir = os.path.join(self.imgdir, "state",
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   603
                    self.IMG_CATALOG_KNOWN)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   604
                kcattrs = os.path.join(kdir, "catalog.attrs")
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   605
                idir = os.path.join(self.imgdir, "state",
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   606
                    self.IMG_CATALOG_INSTALLED)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   607
                icattrs = os.path.join(idir, "catalog.attrs")
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   608
                if not os.path.isfile(kcattrs) and os.path.isfile(icattrs):
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   609
                        # If the known catalog doesn't exist, but the installed
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   610
                        # catalog does, then copy the installed catalog to the
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   611
                        # known catalog directory so that state information can
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   612
                        # be preserved during the rebuild.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   613
                        for fname in os.listdir(idir):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   614
                                portable.copyfile(os.path.join(idir, fname),
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   615
                                    os.path.join(kdir, fname))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   616
                        self.__rebuild_image_catalogs(progtrack=progtrack)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   617
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   618
        def set_attrs(self, is_zone, prefix, mirrors=EmptyI, origins=EmptyI,
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   619
            ssl_key=None, ssl_cert=None, refresh_allowed=True, progtrack=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
   620
            variants=EmptyDict, facets=EmptyDict):
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   621
                """Creates a new image with the given attributes if it does not
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   622
                exist or sets the attributes of an already existing image."""
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   623
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   624
                if not os.path.exists(os.path.join(self.imgdir,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   625
                    imageconfig.CFG_FILE)):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   626
                        op = "image-create"
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   627
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   628
                        op = "image-set-attributes"
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   629
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   630
                # Create the publisher object before creating the image
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   631
                # so that if creation of the Publisher object fails, an
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   632
                # empty, useless image won't be left behind.
1086
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   633
                repo = publisher.Repository()
1504
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   634
                for o in origins:
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   635
                        repo.add_origin(o, ssl_cert=ssl_cert, ssl_key=ssl_key)
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   636
                for m in mirrors:
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   637
                        repo.add_mirror(m, ssl_cert=ssl_cert, ssl_key=ssl_key)
265a1d6b86bd 9969 client support for multiple origins desired
Shawn Walker <srw@sun.com>
parents: 1503
diff changeset
   638
1086
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   639
                newpub = publisher.Publisher(prefix,
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   640
                    meta_root=self._get_publisher_meta_root(prefix),
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   641
                    repositories=[repo], transport=self.transport)
1086
16500d7bf1ca 8321 image_create should not validate publisher uri
Shawn Walker <srw@sun.com>
parents: 1085
diff changeset
   642
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   643
                # Initialize and store the configuration object.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   644
                self.cfg_cache = imageconfig.ImageConfig(self.root,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   645
                    self._get_publisher_meta_dir())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   646
                self.history.log_operation_start(op)
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   647
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   648
                # Determine and add the default variants for the image.
111
647c91609117 Client-side filtering.
Danek Duvall <danek.duvall@sun.com>
parents: 107
diff changeset
   649
                if is_zone:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   650
                        self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   651
                            "variant.opensolaris.zone"] = "nonglobal"
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   652
                else:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   653
                        self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   654
                            "variant.opensolaris.zone"] = "global"
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   655
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   656
                self.cfg_cache.variants["variant.arch"] = \
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   657
                    variants.get("variant.arch", platform.processor())
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   658
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   659
                # After setting up the default variants, add any overrides or
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   660
                # additional variants or facets specified.
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   661
                self.cfg_cache.variants.update(variants)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   662
                self.cfg_cache.facets.update(facets)
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   663
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   664
                # Now everything is ready for publisher configuration.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   665
                self.add_publisher(newpub, refresh_allowed=refresh_allowed,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   666
                    progtrack=progtrack)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   667
                self.cfg_cache.preferred_publisher = newpub.prefix
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   668
1143
71becfca5cfd 8777 image-create traceback with --no-refresh
Shawn Walker <srw@sun.com>
parents: 1141
diff changeset
   669
                # No need to save configuration as add_publisher will do that
71becfca5cfd 8777 image-create traceback with --no-refresh
Shawn Walker <srw@sun.com>
parents: 1141
diff changeset
   670
                # if successful.
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   671
                self.history.log_operation_end()
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   672
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
   673
        def is_liveroot(self):
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   674
                return bool(self.root == "/" or
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
   675
                    DebugValues.get_value("simulate_live_root"))
281
81a0bb7f7d63 217 packages need to be able to [un]install users (groups, roles, etc)
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 271
diff changeset
   676
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   677
        def is_zone(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   678
                return self.cfg_cache.variants[
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   679
                    "variant.opensolaris.zone"] == "nonglobal"
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   680
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
   681
        def get_arch(self):
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   682
                return self.cfg_cache.variants["variant.arch"]
344
4c887185d780 528 pkg list -u gives confusing output
Dan Price <dp@eng.sun.com>
parents: 342
diff changeset
   683
29
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   684
        def get_root(self):
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   685
                return self.root
f621f1df0849 fix install target; correct imports for module renames
"Stephen Hahn <sch@sun.com>"
parents: 26
diff changeset
   686
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   687
        def get_last_modified(self):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   688
                """Returns a UTC datetime object representing the time the
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   689
                image's state last changed or None if unknown."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   690
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   691
                # Always get last_modified time from known catalog.  It's
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   692
                # retrieved from the catalog itself since that is accurate
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   693
                # down to the micrsecond (as opposed to the filesystem which
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   694
                # has an OS-specific resolution).
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   695
                return self.__get_catalog(self.IMG_CATALOG_KNOWN).last_modified
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   696
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   697
        def gen_publishers(self, inc_disabled=False):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
   698
                if not self.cfg_cache:
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
   699
                        raise CfgCacheError, "empty ImageConfig"
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   700
                for p in self.cfg_cache.publishers:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   701
                        pub = self.cfg_cache.publishers[p]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   702
                        if inc_disabled or not pub.disabled:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   703
                                yield self.cfg_cache.publishers[p]
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   704
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   705
        def get_publisher_ranks(self):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   706
                """Returns dictionary of publishers by name; each
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   707
                entry contains a tuple of search order index starting
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   708
                at 0, and a boolean indicating whether or not
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   709
                this publisher is "sticky"."""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   710
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   711
                # automatically make disabled publishers not sticky
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   712
                so = self.cfg_cache.publisher_search_order
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   713
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   714
                ret = dict([
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   715
                    (p.prefix, (so.index(p.prefix), p.sticky))
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   716
                    for p in self.gen_publishers()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   717
                ])
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   718
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   719
                # add any publishers for pkgs that are installed,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   720
                # but have been deleted... so they're not sticky.
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   721
                for pub in self.get_installed_pubs():
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   722
                        ret.setdefault(pub, (len(ret) + 1, False))
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   723
                return ret
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   724
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   725
        def check_cert_validity(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   726
                """Look through the publishers defined for the image.  Print
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   727
                a message and exit with an error if one of the certificates
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   728
                has expired.  If certificates are getting close to expiration,
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   729
                print a warning instead."""
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   730
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   731
                for p in self.gen_publishers():
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   732
                        for r in p.repositories:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   733
                                for uri in r.origins:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   734
                                        if uri.ssl_cert:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   735
                                                misc.validate_ssl_cert(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   736
                                                    uri.ssl_cert,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   737
                                                    prefix=p.prefix, uri=uri)
479
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   738
                return True
de75c17238ff 2951 Client should check if its SSL certificates have expired
johansen <johansen@sun.com>
parents: 462
diff changeset
   739
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   740
        def has_publisher(self, prefix=None, alias=None):
1252
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1237
diff changeset
   741
                """Returns a boolean value indicating whether a publisher
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1237
diff changeset
   742
                exists in the image configuration that matches the given
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1237
diff changeset
   743
                prefix or alias."""
3b1b69011fcf 8709 ImageInterface.has_publisher has incorrect docstring
Shawn Walker <srw@sun.com>
parents: 1237
diff changeset
   744
                for pub in self.gen_publishers(inc_disabled=True):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   745
                        if prefix == pub.prefix or (alias and
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   746
                            alias == pub.alias):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   747
                                return True
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   748
                return False
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   749
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   750
        def remove_publisher(self, prefix=None, alias=None, progtrack=None):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   751
                """Removes the publisher with the matching identity from the
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   752
                image."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   753
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   754
                if not progtrack:
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   755
                        progtrack = progress.QuietProgressTracker()
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
   756
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   757
                with self.locked_op("remove-publisher"):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   758
                        pub = self.get_publisher(prefix=prefix,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   759
                            alias=alias)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   760
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   761
                        if pub.prefix == self.cfg_cache.preferred_publisher:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   762
                                raise api_errors.RemovePreferredPublisher()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   763
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   764
                        self.cfg_cache.remove_publisher(pub.prefix)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   765
                        self.remove_publisher_metadata(pub, progtrack=progtrack)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   766
                        self.save_config()
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   767
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   768
        def get_publishers(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   769
                return self.cfg_cache.publishers
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   770
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   771
        def get_publisher(self, prefix=None, alias=None, origin=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
   772
                publishers = [p for p in self.cfg_cache.publishers.values()]
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   773
                for pub in publishers:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   774
                        if prefix and prefix == pub.prefix:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   775
                                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   776
                        elif alias and alias == pub.alias:
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   777
                                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   778
                        elif origin and \
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   779
                            pub.selected_repository.has_origin(origin):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   780
                                return pub
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   781
                raise api_errors.UnknownPublisher(max(prefix, alias, origin))
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   782
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   783
        def pub_search_before(self, being_moved, staying_put):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   784
                """Moves publisher "being_moved" to before "staying_put"
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   785
                in search order."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   786
                with self.locked_op("search-before"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   787
                        self.__pub_search_common(being_moved, staying_put,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   788
                            after=False)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   789
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   790
        def pub_search_after(self, being_moved, staying_put):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   791
                """Moves publisher "being_moved" to after "staying_put"
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   792
                in search order."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   793
                with self.locked_op("search-after"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   794
                        self.__pub_search_common(being_moved, staying_put,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   795
                            after=True)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   796
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   797
        def __pub_search_common(self, being_moved, staying_put, after=True):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   798
                """Shared logic for altering publisher search order."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   799
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   800
                bm = self.get_publisher(being_moved).prefix
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   801
                sp = self.get_publisher(staying_put).prefix
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   802
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   803
                if bm == sp:
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   804
                        raise api_errors.MoveRelativeToSelf()
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   805
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   806
                # compute new order and set it
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   807
                so = self.cfg_cache.publisher_search_order
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   808
                so.remove(bm)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   809
                if after:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   810
                        so.insert(so.index(sp) + 1, bm)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   811
                else:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   812
                        so.insert(so.index(sp), bm)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   813
                self.cfg_cache.change_publisher_search_order(so)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   814
                self.save_config()
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   815
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   816
        def get_preferred_publisher(self):
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   817
                """Returns the prefix of the preferred publisher."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   818
                return self.cfg_cache.preferred_publisher
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   819
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   820
        def set_preferred_publisher(self, prefix=None, alias=None, pub=None):
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   821
                """Sets the preferred publisher for packaging operations.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   822
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   823
                'prefix' is an optional string value specifying the name of
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   824
                a publisher; ignored if 'pub' is provided.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   825
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   826
                'alias' is an optional string value specifying the alias of
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   827
                a publisher; ignored if 'pub' is provided.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   828
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   829
                'pub' is an optional Publisher object identifying the
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   830
                publisher to set as the preferred publisher.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   831
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   832
                One of the above parameters must be provided."""
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   833
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   834
                with self.locked_op("set-preferred-publisher"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   835
                        if not pub:
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   836
                                pub = self.get_publisher(prefix=prefix,
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   837
                                    alias=alias)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   838
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   839
                                if pub.disabled:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   840
                                        raise api_errors.SetDisabledPublisherPreferred(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   841
                                            pub)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   842
                                self.cfg_cache.preferred_publisher = pub.prefix
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   843
                                self.save_config()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   844
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   845
        def set_property(self, prop_name, prop_value):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   846
                assert prop_name != "preferred-publisher"
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   847
                with self.locked_op("set-property"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   848
                        self.cfg_cache.properties[prop_name] = prop_value
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   849
                        self.save_config()
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   850
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   851
        def get_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   852
                return self.cfg_cache.properties[prop_name]
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   853
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   854
        def has_property(self, prop_name):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   855
                return prop_name in self.cfg_cache.properties
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   856
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   857
        def delete_property(self, prop_name):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   858
                assert prop_name != "preferred-publisher"
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   859
                with self.locked_op("unset-property"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   860
                        del self.cfg_cache.properties[prop_name]
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   861
                        self.save_config()
551
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   862
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   863
        def properties(self):
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   864
                for p in self.cfg_cache.properties:
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   865
                        yield p
233f0eeddd02 856 Image properties
Tom Mueller <Tom.Mueller@sun.com>
parents: 548
diff changeset
   866
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
   867
        def add_publisher(self, pub, refresh_allowed=True, progtrack=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   868
                """Adds the provided publisher object to the image
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   869
                configuration.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   870
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   871
                'refresh_allowed' is an optional, boolean value indicating
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   872
                whether the publisher's metadata should be retrieved when adding
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   873
                it to the image's configuration.
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   874
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
   875
                'progtrack' is an optional ProgressTracker object."""
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
   876
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   877
                # API consumer error.
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   878
                repo = pub.selected_repository
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   879
                assert repo and repo.origins
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   880
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   881
                with self.locked_op("add-publisher"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   882
                        for p in self.cfg_cache.publishers.values():
1733
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   883
                                if pub.prefix == p.prefix or \
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   884
                                    pub.prefix == p.alias or \
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   885
                                    pub.alias and (pub.alias == p.alias or
7ffa6f902aa0 9218 pkg.client.api should check for cross-alias/prefix duplicates
Shawn Walker <srw@sun.com>
parents: 1710
diff changeset
   886
                                    pub.alias == p.prefix):
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   887
                                        raise api_errors.DuplicatePublisher(pub)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   888
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   889
                        if not progtrack:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   890
                                progtrack = progress.QuietProgressTracker()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   891
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   892
                        # Must assign this first before performing any more
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   893
                        # operations.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   894
                        pub.meta_root = self._get_publisher_meta_root(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   895
                            pub.prefix)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   896
                        pub.transport = self.transport
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   897
                        self.cfg_cache.publishers[pub.prefix] = pub
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   898
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   899
                        # Ensure that if the publisher's meta directory already
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   900
                        # exists for some reason that the data within is not
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   901
                        # used.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   902
                        pub.remove_meta_root()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   903
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   904
                        if refresh_allowed:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   905
                                try:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   906
                                        # First, verify that the publisher has a
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   907
                                        # valid pkg(5) repository.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   908
                                        self.transport.valid_publisher_test(pub)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   909
                                        self.refresh_publishers(pubs=[pub],
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   910
                                            progtrack=progtrack)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   911
                                except:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   912
                                        # Remove the newly added publisher since
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   913
                                        # the retrieval failed.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   914
                                        self.cfg_cache.remove_publisher(
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   915
                                            pub.prefix)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   916
                                        raise
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   917
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   918
                        # Only after success should the configuration be saved.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   919
                        self.save_config()
539
7486304966c5 1449 pkg requires operational history
Shawn Walker <shawn.walker@sun.com>
parents: 537
diff changeset
   920
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   921
        def verify(self, fmri, progresstracker, **args):
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   922
                """Generator that returns a tuple of the form (action, errors,
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   923
                warnings, info) if there are any error, warning, or other
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   924
                messages about an action contained within the specified
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   925
                package.  Where the returned messages are lists of strings
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   926
                indicating fatal problems, potential issues (that can be
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   927
                ignored), or extra information to be displayed respectively.
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   928
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   929
                'fmri' is the fmri of the package to verify.
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   930
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   931
                'progresstracker' is a ProgressTracker object.
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   932
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   933
                'args' is a dicti of additional keyword arguments to be passed
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   934
                to each action verification routine."""
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
   935
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   936
                for act in self.get_manifest(fmri).gen_actions(
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
   937
                    self.list_excludes()):
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   938
                        errors, warnings, info = act.verify(self, pkg_fmri=fmri,
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   939
                            **args)
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   940
                        progresstracker.verify_add_progress(fmri)
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   941
                        actname = act.distinguished_name()
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   942
                        if errors:
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   943
                                progresstracker.verify_yield_error(actname,
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
   944
                                    errors)
1685
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   945
                        if warnings:
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   946
                                progresstracker.verify_yield_warning(actname,
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   947
                                    warnings)
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   948
                        if info:
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   949
                                progresstracker.verify_yield_info(actname,
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   950
                                    info)
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   951
                        if errors or warnings or info:
51f832187af7 3005 some pkg verify errors should be warnings or informational messages
Shawn Walker <srw@sun.com>
parents: 1678
diff changeset
   952
                                yield act, errors, warnings, info
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
   953
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   954
        def __call_imageplan_evaluate(self, ip, verbose=False):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   955
                # A plan can be requested without actually performing an
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   956
                # operation on the image.
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   957
                if self.history.operation_name:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   958
                        self.history.operation_start_state = ip.get_plan()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   959
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   960
                ip.evaluate(verbose)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
   961
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   962
                self.imageplan = ip
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   963
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   964
                if self.history.operation_name:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   965
                        self.history.operation_end_state = \
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   966
                            ip.get_plan(full=False)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   967
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   968
                if verbose:
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   969
                        ip.display()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   970
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   971
        def image_change_varcets(self, variants, facets, progtrack, check_cancelation,
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   972
            noexecute, verbose=False):
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   973
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   974
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   975
                ip = imageplan.ImagePlan(self, progtrack, check_cancelation,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   976
                    noexecute=noexecute)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   977
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   978
                progtrack.evaluate_start()
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   979
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   980
                # Always start with most current (on-disk) state information.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   981
                self.__init_catalogs()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
   982
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   983
                # compute dict of changing variants
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   984
                if variants:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   985
                        variants = dict(set(variants.iteritems()) - \
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   986
                           set(self.cfg_cache.variants.iteritems()))
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   987
                # facets are always the entire set
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   988
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   989
                ip.plan_change_varcets(variants, facets)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   990
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   991
                self.__call_imageplan_evaluate(ip, verbose)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   992
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   993
        def image_config_update(self, new_variants, new_facets):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   994
                """update variants in image config"""
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
   995
                ic = self.cfg_cache
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   996
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   997
                if new_variants is not None:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   998
                        ic.variants.update(new_variants)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
   999
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1000
                if new_facets is not None:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1001
                        ic.facets = new_facets
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1002
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  1003
                ic.write(self.imgdir)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1004
                ic = imageconfig.ImageConfig(self.root,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1005
                    self._get_publisher_meta_dir())
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  1006
                ic.read(self.imgdir)
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  1007
                self.cfg_cache = ic
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  1008
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1009
        def repair(self, *args, **kwargs):
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1010
                """Repair any actions in the fmri that failed a verify."""
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1011
                with self.locked_op("fix"):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1012
                        return self.__repair(*args, **kwargs)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1013
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1014
        def __repair(self, repairs, progtrack, accept=False,
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1015
            show_licenses=False):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1016
                """Private repair method; caller is responsible for locking."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1017
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1018
                ilm = self.get_last_modified()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1019
687
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1020
                # XXX: This (lambda x: False) is temporary until we move pkg fix
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1021
                # into the api and can actually use the
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1022
                # api::__check_cancelation() function.
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1023
                pps = []
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1024
                for fmri, actions in repairs:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1025
                        logger.info("Repairing: %-50s" % fmri.get_pkg_stem())
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1026
                        m = self.get_manifest(fmri)
692
ccf4f4e9da34 4818 pkg fix traceback
Brad Hall <bhall@eng.sun.com>
parents: 687
diff changeset
  1027
                        pp = pkgplan.PkgPlan(self, progtrack, lambda: False)
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1028
                        pp.propose_repair(fmri, m, actions)
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1029
                        pp.evaluate(self.list_excludes(), self.list_excludes())
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1030
                        pps.append(pp)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1031
                ip = imageplan.ImagePlan(self, progtrack, lambda: False)
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1032
                ip._image_lm = ilm
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1033
                self.imageplan = ip
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1034
1195
cd29e45e4023 9384 pkg fix unexpectedly indexes packages
Brock Pytlik <bpytlik@sun.com>
parents: 1191
diff changeset
  1035
                ip.update_index = False
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1036
                ip.state = imageplan.EVALUATED_PKGS
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  1037
                progtrack.evaluate_start()
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1038
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1039
                # Always start with most current (on-disk) state information.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1040
                self.__init_catalogs()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1041
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1042
                ip.pkg_plans = pps
687
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1043
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1044
                ip.evaluate()
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1045
                if ip.reboot_needed() and self.is_liveroot():
1328
5c3747a4fe0a 9387 pkg fix should honor reboot-needed flag
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1288
diff changeset
  1046
                        raise api_errors.RebootNeededOnLiveImageException()
1618
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1047
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1048
                logger.info("\n")
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1049
                for pp in ip.pkg_plans:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1050
                        for lic, entry in pp.get_licenses():
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1051
                                dest = entry["dest"]
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1052
                                lic = dest.attrs["license"]
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1053
                                if show_licenses or dest.must_display:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1054
                                        # Display license if required.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1055
                                        logger.info("-" * 60)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1056
                                        logger.info(_("Package: %s") % \
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1057
                                            pp.destination_fmri)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1058
                                        logger.info(_("License: %s\n") % lic)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1059
                                        logger.info(dest.get_text(self,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1060
                                            pp.destination_fmri))
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1061
                                        logger.info("\n")
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1062
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1063
                                # Mark license as having been displayed.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1064
                                pp.set_license_status(lic, displayed=True)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1065
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1066
                                if dest.must_accept and accept:
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1067
                                        # Mark license as accepted if
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1068
                                        # required and requested.
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1069
                                        pp.set_license_status(lic,
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1070
                                            accepted=accept)
04f7471c9e72 5943 add 'must-accept' attribute to license actions
Shawn Walker <srw@sun.com>
parents: 1603
diff changeset
  1071
687
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1072
                ip.preexecute()
3d7060f40501 4450 pkg fix passes bogus cancellation point to pkgplan/imageplan
Brad Hall <bhall@eng.sun.com>
parents: 685
diff changeset
  1073
                ip.execute()
583
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1074
fc856572d86e 388 pkg command needs a "fix" subcommand or similar
Brad Hall <bhall@eng.sun.com>
parents: 582
diff changeset
  1075
                return True
222
12006bf2a260 4 We need to be able to verify that package(s) is/are correctly installed
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 221
diff changeset
  1076
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1077
        def has_manifest(self, fmri):
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1078
                mpath = fmri.get_dir_path()
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1079
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1080
                local_mpath = "%s/pkg/%s/manifest" % (self.imgdir, mpath)
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1081
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1082
                if (os.path.exists(local_mpath)):
50
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1083
                        return True
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1084
bfcb1661f019 basic image and package plans
Stephen Hahn <sch@sun.com>
parents: 45
diff changeset
  1085
                return False
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  1086
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1087
        def get_manifest_path(self, fmri):
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1088
                """Return path to on-disk manifest"""
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1089
                mpath = os.path.join(self.imgdir, "pkg",
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1090
                    fmri.get_dir_path(), "manifest")
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1091
                return mpath
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  1092
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1093
        def __get_manifest(self, fmri, excludes=EmptyI, intent=None):
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1094
                """Find on-disk manifest and create in-memory Manifest
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1095
                object.... grab from server if needed"""
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1096
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1097
                try:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1098
                        ret = manifest.CachedManifest(fmri, self.pkgdir,
1037
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
  1099
                            self.cfg_cache.preferred_publisher,
56ff5f4fab83 8050 image-update fails from b110 to b111 at SUNWgnome-system-monitor manifest
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 999
diff changeset
  1100
                            excludes)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1101
                        # if we have a intent string, let depot
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1102
                        # know for what we're using the cached manifest
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1103
                        if intent:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1104
                                try:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1105
                                        self.transport.touch_manifest(fmri, intent)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1106
                                except (api_errors.UnknownPublisher,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1107
                                    api_errors.TransportError):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1108
                                        # It's not fatal if we can't find
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1109
                                        # or reach the publisher.
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1110
                                        pass
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1111
                except KeyError:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1112
                        ret = self.transport.get_manifest(fmri, excludes,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1113
                                                    intent)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1114
                return ret
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1115
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1116
        def get_manifest(self, fmri, all_variants=False, intent=None):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1117
                """return manifest; uses cached version if available.
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1118
                all_variants controls whether manifest contains actions
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1119
                for all variants"""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1120
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1121
                # Normally elide other arch variants, facets
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1122
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1123
                if all_variants:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1124
                        excludes = EmptyI
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1125
                else:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1126
                        excludes = [ self.cfg_cache.variants.allow_action ]
877
b23f809e8abd 6653 we should elide alternate architectures from in-memory manifests
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 855
diff changeset
  1127
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1128
                m = self.__get_manifest(fmri, excludes=excludes, intent=intent)
567
ea1d96e269a4 3505 client action and manifest creation are wasteful
johansen <johansen@sun.com>
parents: 565
diff changeset
  1129
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1130
                return m
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1131
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1132
        def set_pkg_state(self, pfmri, state):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1133
                """Sets the recorded image state of the specified package.
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1134
                The caller is responsible for also calling save_pkg_state
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1135
                after they are finished updating package state information.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1136
                'state' must be one of the following image constants:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1137
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1138
                    PKG_STATE_INSTALLED
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1139
                        Indicates that the package is installed.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1140
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1141
                    PKG_STATE_KNOWN
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1142
                        Indicates that the package is currently present in
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1143
                        a repository catalog.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1144
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1145
                    PKG_STATE_UNINSTALLED
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1146
                        Clears the INSTALLED state of the package.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1147
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1148
                    PKG_STATE_UNKNOWN
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1149
                        Clears the KNOWN state of the package."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1150
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1151
                kcat = self.get_catalog(self.IMG_CATALOG_KNOWN)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1152
                entry = kcat.get_entry(pfmri)
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1153
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1154
                mdata = entry.get("metadata", {})
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1155
                states = set(mdata.get("states", set()))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1156
                if state == self.PKG_STATE_UNKNOWN:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1157
                        states.discard(self.PKG_STATE_KNOWN)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1158
                elif state == self.PKG_STATE_UNINSTALLED:
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1159
                        icat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1160
                        icat.remove_package(pfmri)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1161
                        states.discard(self.PKG_STATE_INSTALLED)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1162
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1163
                        # All other states should simply be added to the
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1164
                        # existing set of states.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1165
                        states.add(state)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1166
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1167
                if self.PKG_STATE_KNOWN not in states and \
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1168
                    self.PKG_STATE_INSTALLED not in states:
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1169
                        # This entry is no longer available and has no
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1170
                        # meaningful state information, so should be
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1171
                        # discarded.
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1172
                        kcat.remove_package(pfmri)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1173
                        return
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1174
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1175
                if (self.PKG_STATE_INSTALLED in states and
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1176
                    self.PKG_STATE_UNINSTALLED in states) or (
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1177
                    self.PKG_STATE_KNOWN in states and
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1178
                    self.PKG_STATE_UNKNOWN in states):
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1179
                        raise api_errors.ImagePkgStateError(pfmri, states)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1180
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1181
                # Catalog format only supports lists.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1182
                mdata["states"] = list(states)
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1183
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1184
                # Now record the package state.
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1185
                kcat.update_entry(pfmri, metadata=mdata)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1186
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1187
                if state == self.PKG_STATE_INSTALLED:
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1188
                        # If the package is being marked as installed, then
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1189
                        # it shouldn't already exist in the installed catalog
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1190
                        # and should be added.
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1191
                        icat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1192
                        icat.append(kcat, pfmri=pfmri)
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1193
                        self.__catalog_new_installs.add(pfmri)
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1194
                elif self.PKG_STATE_INSTALLED in states:
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1195
                        # If some other state has been changed and the package
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1196
                        # is still marked as installed, then simply update the
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1197
                        # existing entry (which should already exist).
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1198
                        icat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1199
                        icat.update_entry(pfmri, metadata=mdata)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1200
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1201
        def save_pkg_state(self):
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1202
                """Saves current package state information."""
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1203
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1204
                # Temporarily redirect the catalogs to a different location,
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1205
                # so that if the save is interrupted, the image won't be left
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1206
                # with invalid state, and then save them.
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1207
                tmp_state_root = self.temporary_dir()
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1208
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1209
                try:
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1210
                        for name in (self.IMG_CATALOG_KNOWN,
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1211
                            self.IMG_CATALOG_INSTALLED):
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1212
                                cpath = os.path.join(tmp_state_root, name)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1213
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1214
                                # Must copy the old catalog data to the new
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1215
                                # destination as only changed files will be
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1216
                                # written.
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1217
                                cat = self.get_catalog(name)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1218
                                shutil.copytree(cat.meta_root, cpath)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1219
                                cat.meta_root = cpath
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1220
                                cat.finalize(pfmris=self.__catalog_new_installs)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1221
                                cat.save()
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1222
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1223
                        # Next, preserve the old installed state dir, rename the
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1224
                        # new one into place, and then remove the old one.
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1225
                        state_root = os.path.join(self.imgdir, "state")
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1226
                        orig_state_root = self.__salvagedir(state_root)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1227
                        portable.rename(tmp_state_root, state_root)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1228
                        shutil.rmtree(orig_state_root, True)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1229
                finally:
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1230
                        # Regardless of success, the following must happen.
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1231
                        for name in (self.IMG_CATALOG_KNOWN,
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1232
                            self.IMG_CATALOG_INSTALLED):
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1233
                                cat = self.get_catalog(name)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1234
                                cat.meta_root = os.path.join(self.imgdir,
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1235
                                    "state", name)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1236
                        if os.path.exists(tmp_state_root):
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1237
                                shutil.rmtree(tmp_state_root, True)
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1238
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1239
        def get_catalog(self, name):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1240
                """Returns the requested image catalog.
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1241
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1242
                'name' must be one of the following image constants:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1243
                    IMG_CATALOG_KNOWN
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1244
                        The known catalog contains all of packages that are
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1245
                        installed or available from a publisher's repository.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1246
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1247
                    IMG_CATALOG_INSTALLED
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1248
                        The installed catalog is a subset of the 'known'
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1249
                        catalog that only contains installed packages."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1250
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1251
                if not self.imgdir:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1252
                        raise RuntimeError("self.imgdir must be set")
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1253
717
c40259b4ce98 4569 pkg uninstall tracesback when lacking permissions
Brock Pytlik <bpytlik@sun.com>
parents: 715
diff changeset
  1254
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1255
                        return self.__catalogs[name]
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1256
                except KeyError:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1257
                        pass
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1258
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1259
                return self.__get_catalog(name)
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1260
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1261
        def __get_catalog(self, name):
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1262
                """Private method to retrieve catalog; this bypasses the
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1263
                normal automatic caching."""
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1264
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1265
                croot = os.path.join(self.imgdir, "state", name)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1266
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1267
                        os.makedirs(croot)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1268
                except EnvironmentError, e:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1269
                        if e.errno in (errno.EACCES, errno.EROFS):
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1270
                                # Allow operations to work for
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1271
                                # unprivileged users.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1272
                                croot = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1273
                        elif e.errno != errno.EEXIST:
658
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1274
                                raise
e470d4688084 4412 pkg refresh can strand one w/o packages after upgrade from 86
Danek Duvall <danek.duvall@sun.com>
parents: 655
diff changeset
  1275
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1276
                def manifest_cb(cat, f):
1449
a721d9b0aad2 12273 client catalog can mis-merge state information / lazy-load can fail
Shawn Walker <srw@sun.com>
parents: 1435
diff changeset
  1277
                        # Only allow lazy-load for packages from non-v1 sources.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1278
                        # Assume entries for other sources have all data
1449
a721d9b0aad2 12273 client catalog can mis-merge state information / lazy-load can fail
Shawn Walker <srw@sun.com>
parents: 1435
diff changeset
  1279
                        # required in catalog.  This prevents manifest retrieval
a721d9b0aad2 12273 client catalog can mis-merge state information / lazy-load can fail
Shawn Walker <srw@sun.com>
parents: 1435
diff changeset
  1280
                        # for packages that don't have any related action data
a721d9b0aad2 12273 client catalog can mis-merge state information / lazy-load can fail
Shawn Walker <srw@sun.com>
parents: 1435
diff changeset
  1281
                        # in the catalog because they don't have any related
a721d9b0aad2 12273 client catalog can mis-merge state information / lazy-load can fail
Shawn Walker <srw@sun.com>
parents: 1435
diff changeset
  1282
                        # action data in their manifest.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1283
                        entry = cat.get_entry(f)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1284
                        states = entry["metadata"]["states"]
1449
a721d9b0aad2 12273 client catalog can mis-merge state information / lazy-load can fail
Shawn Walker <srw@sun.com>
parents: 1435
diff changeset
  1285
                        if self.PKG_STATE_V1 not in states:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1286
                                return self.get_manifest(f, all_variants=True)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1287
                        return None
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1288
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1289
                # batch_mode is set to True here as any operations that modify
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1290
                # the catalogs (add or remove entries) are only done during an
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1291
                # image upgrade or metadata refresh.  In both cases, the catalog
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1292
                # is resorted and finalized so this is always safe to use.
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1293
                cat = pkg.catalog.Catalog(batch_mode=True,
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1294
                    manifest_cb=manifest_cb, meta_root=croot, sign=False)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1295
                self.__catalogs[name] = cat
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1296
                return cat
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1297
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1298
        def __remove_catalogs(self):
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1299
                """Removes all image catalogs and their directories."""
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1300
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1301
                self.__init_catalogs()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1302
                for name in (self.IMG_CATALOG_KNOWN,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1303
                    self.IMG_CATALOG_INSTALLED):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1304
                        shutil.rmtree(os.path.join(self.imgdir, "state", name))
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  1305
556
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1306
        def get_version_installed(self, pfmri):
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1307
                """Returns an fmri of the installed package matching the
1c3526ca7b9e 2022 client should provide operational intent to server
Shawn Walker <shawn.walker@sun.com>
parents: 554
diff changeset
  1308
                package stem of the given fmri or None if no match is found."""
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1309
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1310
                cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1311
                for ver, fmris in cat.fmris_by_version(pfmri.pkg_name):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1312
                        return fmris[0]
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1313
                return None
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  1314
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1315
        def fmri_set_default_publisher(self, fmri):
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1316
                """If the FMRI supplied as an argument does not have
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1317
                a publisher, set it to the image's preferred publisher."""
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1318
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1319
                if fmri.has_publisher():
195
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1320
                        return
b23d0425f0f7 11 use FMRIs with fully specified authorities internally
johansen <johansen@sun.com>
parents: 192
diff changeset
  1321
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1322
                fmri.set_publisher(self.get_preferred_publisher(), True)
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  1323
135
a1e20e9a9845 add CLI test suite, correct bugs found by test suite, ration out CLI options
Stephen Hahn <sch@Sun.COM>
parents: 116
diff changeset
  1324
        def has_version_installed(self, fmri):
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1325
                """Check that the version given in the FMRI or a successor is
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  1326
                installed in the current image."""
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1327
560
4c8d82d58131 3569 pkg state code obviates use of _get_version_installed
Shawn Walker <shawn.walker@sun.com>
parents: 556
diff changeset
  1328
                v = self.get_version_installed(fmri)
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1329
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1330
                if v and not fmri.publisher:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1331
                        fmri.set_publisher(v.get_publisher_str())
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1332
                elif not fmri.publisher:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1333
                        fmri.set_publisher(self.get_preferred_publisher(), True)
266
5e5bff6fedce 582 Importing packages seemingly misrecords dependencies
johansen <johansen@sun.com>
parents: 260
diff changeset
  1334
1288
4248f27af42a 10417 rename v0 support should be removed everywhere
Shawn Walker <srw@sun.com>
parents: 1271
diff changeset
  1335
                if v and v.is_successor(fmri):
258
b3b7592412ec 270 Need ability to rename packages
johansen <johansen@sun.com>
parents: 251
diff changeset
  1336
                        return True
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1337
                return False
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  1338
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1339
        def get_pkg_state(self, pfmri):
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1340
                """Returns the list of states a package is in for this image."""
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1341
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1342
                cat = self.get_catalog(self.IMG_CATALOG_KNOWN)
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1343
                entry = cat.get_entry(pfmri)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1344
                if entry is None:
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1345
                        return []
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1346
                return entry["metadata"]["states"]
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  1347
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1348
        def is_pkg_installed(self, pfmri):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1349
                """Returns a boolean value indicating whether the specified
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1350
                package is installed."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1351
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1352
                # Avoid loading the installed catalog if the known catalog
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1353
                # is already loaded.  This is safe since the installed
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1354
                # catalog is a subset of the known, and a specific entry
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1355
                # is being retrieved.
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1356
                if not self.__catalog_loaded(self.IMG_CATALOG_KNOWN):
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1357
                        cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1358
                else:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1359
                        cat = self.get_catalog(self.IMG_CATALOG_KNOWN)
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1360
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1361
                entry = cat.get_entry(pfmri)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1362
                if entry is None:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1363
                        return False
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1364
                states = entry["metadata"]["states"]
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1365
                return self.PKG_STATE_INSTALLED in states
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1366
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1367
        def list_excludes(self, new_variants=None, new_facets=None):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1368
                """Generate a list of callables that each return True if an
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1369
                action is to be included in the image using the currently
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1370
                defined variants & facets for the image, or an updated set if
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1371
                new_variants or new_facets are specified."""
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1372
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1373
                if new_variants:
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1374
                        new_vars = self.cfg_cache.variants.copy()
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1375
                        new_vars.update(new_variants)
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1376
                        var_call = new_vars.allow_action
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1377
                else:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1378
                        var_call = self.cfg_cache.variants.allow_action
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1379
                if new_facets:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1380
                        fac_call = new_facets.allow_action
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1381
                else:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1382
                        fac_call = self.cfg_cache.facets.allow_action
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1383
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1384
                return [var_call, fac_call]
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1385
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1386
        def get_variants(self):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1387
                """ return a copy of the current image variants"""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1388
                return self.cfg_cache.variants.copy()
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1389
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1390
        def get_facets(self):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1391
                """ Return a copy of the current image facets"""
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1392
                return self.cfg_cache.facets.copy()
838
aafbe4737188 3245 need to support creation of multi-architecture (fat) packages
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 835
diff changeset
  1393
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1394
        def __build_dependents(self, progtrack):
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1395
                """Build a dictionary mapping packages to the list of packages
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1396
                that have required dependencies on them."""
956
adf6bdfdb3b5 6904 image.installed_file_authority always tries to open installed file r+
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 941
diff changeset
  1397
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1398
                self.__req_dependents = {}
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1399
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1400
                cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1401
                for f, actions in cat.actions([cat.DEPENDENCY],
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1402
                    excludes=self.list_excludes()):
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1403
                        progtrack.evaluate_progress(f)
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1404
                        for a in actions:
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1405
                                if a.name != "depend" or \
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1406
                                    a.attrs["type"] != "require":
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1407
                                        continue
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1408
                                name = self.strtofmri(a.attrs["fmri"]).pkg_name
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1409
                                self.__req_dependents.setdefault(name, []).append(f)
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1410
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1411
        def get_dependents(self, pfmri, progtrack):
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1412
                """Return a list of the packages directly dependent on the given
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  1413
                FMRI."""
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1414
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1415
                if self.__req_dependents is None:
432
578875da6e04 48 Removing a dependency is not flagged, and recovery is not obvious
Danek Duvall <danek.duvall@sun.com>
parents: 429
diff changeset
  1416
                        self.__build_dependents(progtrack)
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1417
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  1418
                return self.__req_dependents.get(pfmri.pkg_name, [])
67
62c897652bbc Handle dependencies when removing a package.
Danek Duvall <danek.duvall@sun.com>
parents: 63
diff changeset
  1419
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1420
        def __rebuild_image_catalogs(self, progtrack=None):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1421
                """Rebuilds the image catalogs based on the available publisher
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1422
                catalogs."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1423
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1424
                if not progtrack:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1425
                        progtrack = progress.QuietProgressTracker()
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1505
diff changeset
  1426
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1427
                progtrack.cache_catalogs_start()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1428
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1429
                publist = list(self.gen_publishers())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1430
                if not publist:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1431
                        # No publishers, so nothing can be known or installed.
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1432
                        self.__remove_catalogs()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1433
                        progtrack.cache_catalogs_done()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1434
                        return
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1435
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1436
                self.history.log_operation_start("rebuild-image-catalogs")
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1437
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1438
                # Mark all operations as occurring at this time.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1439
                op_time = datetime.datetime.utcnow()
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1440
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1441
                # The image catalogs need to be updated, but this is a bit
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1442
                # tricky as previously known packages must remain known even
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1443
                # if PKG_STATE_KNOWN is no longer true if any other state
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1444
                # information is present.  This is to allow freezing, etc. of
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1445
                # package states on a permanent basis even if the package is
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1446
                # no longer available from a publisher repository.  However,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1447
                # this is only True of installed packages.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1448
                old_icat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1449
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1450
                # batch_mode is set to True here since without it, catalog
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1451
                # population time is almost doubled (since the catalog is
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1452
                # re-sorted and stats are generated for every operation).
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1453
                # In addition, the new catalog is first created in a new
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1454
                # temporary directory so that it can be moved into place
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1455
                # at the very end of this process (to minimize the chance
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1456
                # that failure or interruption will cause the image to be
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1457
                # left in an inconsistent state).
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1458
                tmp_state_root = self.temporary_dir()
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1459
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1460
                kcat = pkg.catalog.Catalog(batch_mode=True,
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1461
                    meta_root=os.path.join(tmp_state_root,
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1462
                    self.IMG_CATALOG_KNOWN), sign=False)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1463
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1464
                # XXX if any of the below fails for any reason, the old 'known'
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1465
                # catalog needs to be re-loaded so the client is in a consistent
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1466
                # state.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1467
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1468
                # All enabled publisher catalogs must be processed.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1469
                pub_cats = [(pub.prefix, pub.catalog) for pub in publist]
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1470
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1471
                # XXX For backwards compatibility, 'upgradability' of packages
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1472
                # is calculated and stored based on whether a given pkg stem
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1473
                # matches the newest version in the catalog.  This is quite
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1474
                # expensive (due to overhead), but at least the cost is
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1475
                # consolidated here.  This comparison is also cross-publisher,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1476
                # as it used to be.  In the future, it could likely be improved
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1477
                # by usage of the SAT solver.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1478
                newest = {}
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1479
                for pfx, cat in [(None, old_icat)] + pub_cats:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1480
                        for f in cat.fmris(last=True, pubs=[pfx]):
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1481
                                nver, snver = newest.get(f.pkg_name, (None,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1482
                                    None))
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1483
                                if f.version > nver:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1484
                                        newest[f.pkg_name] = (f.version,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1485
                                            str(f.version))
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1486
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1487
                # Next, copy all of the entries for the catalog parts that
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1488
                # currently exist into the image 'known' catalog.
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1489
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1490
                # Iterator for source parts.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1491
                sparts = (
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1492
                   (pfx, cat, name, cat.get_part(name, must_exist=True))
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1493
                   for pfx, cat in pub_cats
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1494
                   for name in cat.parts
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1495
                )
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1496
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1497
                # Build list of installed packages based on actual state
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1498
                # information just in case there is a state issue from an
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1499
                # older client.
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1500
                inst_stems = {}
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1501
                for t, entry in old_icat.tuple_entries():
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1502
                        states = entry["metadata"]["states"]
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1503
                        if self.PKG_STATE_INSTALLED not in states:
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1504
                                continue
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1505
                        pub, stem, ver = t
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1506
                        inst_stems.setdefault(pub, {})
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1507
                        inst_stems[pub].setdefault(stem, {})
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1508
                        inst_stems[pub][stem][ver] = False
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1509
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1510
                # Create the new installed catalog in a temporary location.
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1511
                icat = pkg.catalog.Catalog(batch_mode=True,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1512
                    meta_root=os.path.join(tmp_state_root,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1513
                    self.IMG_CATALOG_INSTALLED), sign=False)
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1514
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1515
                for pfx, cat, name, spart in sparts:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1516
                        # 'spart' is the source part.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1517
                        if spart is None:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1518
                                # Client hasn't retrieved this part.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1519
                                continue
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1520
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1521
                        # New known part.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1522
                        nkpart = kcat.get_part(name)
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1523
                        nipart = icat.get_part(name)
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1524
                        base = name.startswith("catalog.base.")
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1525
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1526
                        # Avoid accessor overhead since this will be
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1527
                        # used for every entry.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1528
                        cat_ver = cat.version
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1529
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1530
                        for t, sentry in spart.tuple_entries(pubs=[pfx]):
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1531
                                pub, stem, ver = t
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1532
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1533
                                installed = False
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1534
                                if pub in inst_stems and \
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1535
                                    stem in inst_stems[pub] and \
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1536
                                    ver in inst_stems[pub][stem]:
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1537
                                        installed = True
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1538
                                        inst_stems[pub][stem][ver] = True
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1539
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1540
                                # copy() is too slow here and catalog entries
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1541
                                # are shallow so this should be sufficient.
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1542
                                entry = dict(sentry.iteritems())
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1543
                                if not base:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1544
                                        # Nothing else to do except add the
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1545
                                        # entry for non-base catalog parts.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1546
                                        nkpart.add(metadata=entry,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1547
                                            op_time=op_time, pub=pub, stem=stem,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1548
                                            ver=ver)
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1549
                                        if installed:
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1550
                                                nipart.add(metadata=entry,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1551
                                                    op_time=op_time, pub=pub,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1552
                                                    stem=stem, ver=ver)
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1553
                                        continue
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1554
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1555
                                # Only the base catalog part stores package
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1556
                                # state information and/or other metadata.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1557
                                mdata = entry["metadata"] = {}
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1558
                                states = [self.PKG_STATE_KNOWN]
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1559
                                if cat_ver == 0:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1560
                                        states.append(self.PKG_STATE_V0)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1561
                                else:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1562
                                        # Assume V1 catalog source.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1563
                                        states.append(self.PKG_STATE_V1)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1564
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1565
                                if installed:
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1566
                                        states.append(self.PKG_STATE_INSTALLED)
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1567
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1568
                                nver, snver = newest.get(stem, (None, None))
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1569
                                if snver is not None and ver != snver:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1570
                                        states.append(self.PKG_STATE_UPGRADABLE)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1571
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1572
                                # Determine if package is obsolete or has been
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1573
                                # renamed and mark with appropriate state.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1574
                                dp = cat.get_part("catalog.dependency.C",
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1575
                                    must_exist=True)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1576
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1577
                                dpent = None
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1578
                                if dp is not None:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1579
                                        dpent = dp.get_entry(pub=pub, stem=stem,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1580
                                            ver=ver)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1581
                                if dpent is not None:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1582
                                        for a in dpent["actions"]:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1583
                                                if not a.startswith("set"):
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1584
                                                        continue
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1585
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1586
                                                if a.find("pkg.obsolete") != -1:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1587
                                                        if a.find("true") == -1:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1588
                                                                continue
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1589
                                                        states.append(
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1590
                                                            self.PKG_STATE_OBSOLETE)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1591
                                                elif a.find("pkg.renamed") != -1:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1592
                                                        if a.find("true") == -1:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1593
                                                                continue
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1594
                                                        states.append(
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1595
                                                            self.PKG_STATE_RENAMED)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1596
                                mdata["states"] = states
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1597
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1598
                                # Add base entries.
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1599
                                nkpart.add(metadata=entry, op_time=op_time,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1600
                                    pub=pub, stem=stem, ver=ver)
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1601
                                if installed:
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1602
                                        nipart.add(metadata=entry,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1603
                                            op_time=op_time, pub=pub, stem=stem,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1604
                                            ver=ver)
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1605
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1606
                # Now add installed packages to list of known packages using
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1607
                # previous state information.  While doing so, track any
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1608
                # new entries as the versions for the stem of the entry will
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1609
                # need to be passed to finalize() for sorting.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1610
                final_fmris = []
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1611
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1612
                for name in old_icat.parts:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1613
                        # Old installed part.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1614
                        ipart = old_icat.get_part(name, must_exist=True)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1615
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1616
                        # New known part.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1617
                        nkpart = kcat.get_part(name)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1618
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1619
                        # New installed part.
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1620
                        nipart = icat.get_part(name)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1621
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1622
                        base = name.startswith("catalog.base.")
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1623
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1624
                        mdata = None
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1625
                        for t, entry in ipart.tuple_entries():
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1626
                                pub, stem, ver = t
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1627
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1628
                                if pub not in inst_stems or \
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1629
                                    stem not in inst_stems[pub] or \
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1630
                                    ver not in inst_stems[pub][stem] or \
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1631
                                    inst_stems[pub][stem][ver]:
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1632
                                        # Entry is no longer valid or is already
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1633
                                        # known.
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1634
                                        continue
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1635
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1636
                                if base:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1637
                                        mdata = entry["metadata"]
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1638
                                        states = set(mdata["states"])
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1639
                                        states.discard(self.PKG_STATE_KNOWN)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1640
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1641
                                        nver, snver = newest.get(stem, (None,
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1642
                                            None))
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1643
                                        if snver is not None and ver == snver:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1644
                                                states.discard(
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1645
                                                    self.PKG_STATE_UPGRADABLE)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1646
                                        elif snver is not None:
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1647
                                                states.add(
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1648
                                                    self.PKG_STATE_UPGRADABLE)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1649
                                        mdata["states"] = list(states)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1650
1678
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1651
                                # Add entries.
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1652
                                nkpart.add(metadata=entry, op_time=op_time,
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1653
                                    pub=pub, stem=stem, ver=ver)
825ec1d3702e 14013 image catalog rebuild can stumble on v0 to v1 repo transition
Shawn Walker <srw@sun.com>
parents: 1672
diff changeset
  1654
                                nipart.add(metadata=entry, op_time=op_time,
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1655
                                    pub=pub, stem=stem, ver=ver)
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1656
                                final_fmris.append(pkg.fmri.PkgFmri(
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1657
                                    "%s@%s" % (stem, ver), publisher=pub))
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1658
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1659
                # Save the new catalogs.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1660
                for cat in kcat, icat:
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1505
diff changeset
  1661
                        os.makedirs(cat.meta_root, mode=misc.PKG_DIR_MODE)
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  1662
                        cat.finalize(pfmris=final_fmris)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1663
                        cat.save()
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1664
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1665
                # Next, preserve the old installed state dir, rename the
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1666
                # new one into place, and then remove the old one.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1667
                state_root = os.path.join(self.imgdir, "state")
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1668
                orig_state_root = self.__salvagedir(state_root)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1669
                portable.rename(tmp_state_root, state_root)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1670
                shutil.rmtree(orig_state_root, True)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1671
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1672
                # Ensure in-memory catalogs get reloaded.
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  1673
                self.__init_catalogs()
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1674
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1675
                progtrack.cache_catalogs_done()
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1676
                self.history.log_operation_end()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1677
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1678
        def refresh_publishers(self, full_refresh=False, immediate=False,
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1679
            pubs=None, progtrack=None):
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1680
                """Refreshes the metadata (e.g. catalog) for one or more
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  1681
                publishers.  Callers are responsible for locking the image.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1682
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1683
                '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: 993
diff changeset
  1684
                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: 993
diff changeset
  1685
                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: 993
diff changeset
  1686
                True, 'immediate' is also set to True.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1687
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1688
                'immediate' is an optional boolean value indicating whether the
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1689
                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: 993
diff changeset
  1690
                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: 993
diff changeset
  1691
                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: 1328
diff changeset
  1692
                exceeded.
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1693
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1694
                '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: 993
diff changeset
  1695
                to refresh.  Passing an empty list or using the default value
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1696
                implies all publishers."""
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1697
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1698
                if not progtrack:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1699
                        progtrack = progress.QuietProgressTracker()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1700
1102
5ea5cdb4360d 5014 api sets successful result for image-create with failed catalog refresh
Shawn Walker <srw@sun.com>
parents: 1087
diff changeset
  1701
                self.history.log_operation_start("refresh-publishers")
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1702
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1703
                # Verify validity of certificates before attempting network
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1704
                # operations.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1705
                try:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1706
                        self.check_cert_validity()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1707
                except api_errors.ExpiringCertificate, e:
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  1708
                        logger.error(str(e))
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1709
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1710
                pubs_to_refresh = []
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1711
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1712
                if not pubs:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1713
                        # Omit disabled publishers.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1714
                        pubs = [p for p in self.gen_publishers()]
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1715
                for pub in pubs:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1716
                        p = pub
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1717
                        if not isinstance(p, publisher.Publisher):
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1718
                                p = self.get_publisher(prefix=p)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1719
                        if p.disabled:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1720
                                e = api_errors.DisabledPublisher(p)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1721
                                self.history.log_operation_end(error=e)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1722
                                raise e
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1723
                        pubs_to_refresh.append(p)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1724
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1725
                if not pubs_to_refresh:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1726
                        self.history.log_operation_end()
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1727
                        return
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1728
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1729
                try:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1730
                        # Ensure Image directory structure is valid.
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1731
                        self.mkdirs()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1732
                except Exception, e:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1733
                        self.history.log_operation_end(error=e)
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1734
                        raise
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1735
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1736
                progtrack.refresh_start(len(pubs_to_refresh))
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1737
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1738
                failed = []
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1739
                total = 0
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1740
                succeeded = set()
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1741
                updated = 0
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1742
                for pub in pubs_to_refresh:
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1743
                        total += 1
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1744
                        progtrack.refresh_progress(pub.prefix)
235
61994d15c39b 373 design a nice default output for install/update/remove
Dan Price <dp@eng.sun.com>
parents: 226
diff changeset
  1745
                        try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1746
                                if pub.refresh(full_refresh=full_refresh,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1747
                                    immediate=immediate):
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1748
                                        updated += 1
1538
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
  1749
                        except api_errors.PermissionsException, e:
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
  1750
                                failed.append((pub, e))
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
  1751
                                # No point in continuing since no data can
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
  1752
                                # be written.
78ac66abc186 12130 install/update operations should always refresh publisher metadata (when allowed)
Shawn Walker <srw@sun.com>
parents: 1537
diff changeset
  1753
                                break
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1754
                        except api_errors.ApiException, e:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1755
                                failed.append((pub, e))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1756
                                continue
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1757
                        succeeded.add(pub.prefix)
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1758
                progtrack.refresh_done()
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  1759
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1760
                if updated:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1761
                        self.__rebuild_image_catalogs(progtrack=progtrack)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1762
201
63e78f600aa7 185 traceback on pkg refresh when hostname lookup fails
Danek Duvall <danek.duvall@sun.com>
parents: 195
diff changeset
  1763
                if failed:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1764
                        e = api_errors.CatalogRefreshException(failed, total,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1765
                            len(succeeded))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1766
                        self.history.log_operation_end(error=e)
1435
f65591874aef 12221 client traceback if refresh fails due to exception
Shawn Walker <srw@sun.com>
parents: 1431
diff changeset
  1767
                        raise e
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1768
                self.history.log_operation_end()
116
9c9942a52984 (image flag day) remove pkg catalog, improve pkg status, localize pkg(1), use
Stephen Hahn <sch@Sun.COM>
parents: 111
diff changeset
  1769
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1770
        def _get_publisher_meta_dir(self):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1771
                if self.__upgraded:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1772
                        return IMG_PUB_DIR
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1773
                return "catalog"
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  1774
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1775
        def _get_publisher_meta_root(self, prefix):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1776
                return os.path.join(self.imgdir, self._get_publisher_meta_dir(),
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1777
                    prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1778
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1779
        def remove_publisher_metadata(self, pub, progtrack=None):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1780
                """Removes the metadata for the specified publisher object."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1781
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1782
                pub.remove_meta_root()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1783
                self.__rebuild_image_catalogs(progtrack=progtrack)
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  1784
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1785
        def gen_installed_pkg_names(self, anarchy=True):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1786
                """A generator function that produces FMRI strings as it
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1787
                iterates over the list of installed packages.  This is
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1788
                faster than gen_installed_pkgs when only the FMRI string
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1789
                is needed."""
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1790
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1791
                cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1792
                for f in cat.fmris(objects=False):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1793
                        if anarchy:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1794
                                # Catalog entries always have publisher prefix.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1795
                                yield "pkg:/%s" % f[6:].split("/", 1)[-1]
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1796
                                continue
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1797
                        yield f
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1798
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1799
        def gen_installed_pkgs(self):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1800
                """Return an iteration through the installed packages."""
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1801
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1802
                cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1803
                for f in cat.fmris():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1804
                        yield f
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1805
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1806
        def get_installed_pubs(self):
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1807
                """Returns a set containing the prefixes of all publishers with
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1808
                installed packages."""
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1809
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1810
                cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1811
                return cat.publishers()
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  1812
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1813
        def __upgrade_image(self, progtrack=None):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1814
                """Transform the existing image structure and its data to
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1815
                the newest format."""
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1816
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1817
                if self.__upgraded:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1818
                        return
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1819
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1820
                assert self.imgdir
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1821
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1822
                def installed_file_publisher(filepath):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1823
                        """Find the pkg's installed file named by filepath.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1824
                        Return the publisher that installed this package."""
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1825
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1826
                        f = file(filepath)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1827
                        try:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1828
                                flines = f.readlines()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1829
                                version, pub = flines
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1830
                                version = version.strip()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1831
                                pub = pub.strip()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1832
                                f.close()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1833
                        except ValueError:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1834
                                # If ValueError occurs, the installed file is of
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1835
                                # a previous format.  For upgrades to work, it's
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1836
                                # necessary to assume that the package was
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1837
                                # installed from the preferred publisher.  Here,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1838
                                # the publisher is setup to record that.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1839
                                if flines:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1840
                                        pub = flines[0]
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1841
                                        pub = pub.strip()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1842
                                        newpub = "%s_%s" % (
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1843
                                            pkg.fmri.PREF_PUB_PFX, pub)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1844
                                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1845
                                        newpub = "%s_%s" % (
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1846
                                            pkg.fmri.PREF_PUB_PFX,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1847
                                            self.get_preferred_publisher())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1848
                                pub = newpub
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1849
                        assert pub
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1850
                        return pub
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1851
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1852
                if not progtrack:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1853
                        progtrack = progress.QuietProgressTracker()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1854
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1855
                # Not technically 'caching', but close enough ...
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1856
                progtrack.cache_catalogs_start()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1857
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1858
                # First, load the old package state information.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1859
                installed_state_dir = "%s/state/installed" % self.imgdir
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1860
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1861
                # If the state directory structure has already been created,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1862
                # loading information from it is fast.  The directory is
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1863
                # populated with files, named by their (url-encoded) FMRI,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1864
                # which point to the "installed" file in the corresponding
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1865
                # directory under /var/pkg.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1866
                installed = {}
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1867
                def add_installed_entry(f):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1868
                        path = "%s/pkg/%s/installed" % \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1869
                            (self.imgdir, f.get_dir_path())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1870
                        pub = installed_file_publisher(path)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1871
                        f.set_publisher(pub)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1872
                        installed[f.pkg_name] = f
835
34ec4401dc48 686 Client needs a way to tell that a response is actually from an IPS server
johansen <johansen@sun.com>
parents: 834
diff changeset
  1873
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1874
                if os.path.isdir(installed_state_dir):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1875
                        for pl in sorted(os.listdir(installed_state_dir)):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1876
                                fmristr = "%s" % urllib.unquote(pl)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1877
                                f = pkg.fmri.PkgFmri(fmristr)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1878
                                add_installed_entry(f)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1879
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1880
                        # Otherwise, we must iterate through the earlier
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1881
                        # installed state.  One day, this can be removed.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1882
                        proot = "%s/pkg" % self.imgdir
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1883
                        for pd in sorted(os.listdir(proot)):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1884
                                for vd in sorted(os.listdir("%s/%s" % \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1885
                                    (proot, pd))):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1886
                                        path = "%s/pkg/%s/installed" % \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1887
                                            (self.imgdir, pd, vd)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1888
                                        if not os.path.exists(path):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1889
                                                continue
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1890
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1891
                                        fmristr = urllib.unquote("%s@%s" % (pd,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1892
                                            vd))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1893
                                        f = pkg.fmri.PkgFmri(fmristr)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1894
                                        add_installed_entry(f)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1895
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1896
                # Create the new image catalogs.
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1897
                kcat = pkg.catalog.Catalog(batch_mode=True, sign=False)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1898
                icat = pkg.catalog.Catalog(batch_mode=True, sign=False)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1899
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1900
                # XXX For backwards compatibility, 'upgradability' of packages
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1901
                # is calculated and stored based on whether a given pkg stem
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1902
                # matches the newest version in the catalog.  This is quite
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1903
                # expensive (due to overhead), but at least the cost is
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1904
                # consolidated here.  This comparison is also cross-publisher,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1905
                # as it used to be.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1906
                newest = {}
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1907
                old_pub_cats = []
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1908
                for pub in self.gen_publishers():
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1909
                        try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1910
                                old_cat = pkg.server.catalog.ServerCatalog(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1911
                                    pub.meta_root, read_only=True,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1912
                                    publisher=pub.prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1913
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1914
                                old_pub_cats.append((pub, old_cat))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1915
                                for f in old_cat.fmris():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1916
                                        nver = newest.get(f.pkg_name, None)
1353
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1917
                                        newest[f.pkg_name] = max(nver,
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1918
                                            f.version)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1919
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1920
                        except EnvironmentError, e:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1921
                                # If a catalog file is just missing, ignore it.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1922
                                # If there's a worse error, make sure the user
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1923
                                # knows about it.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1924
                                if e.errno != errno.ENOENT:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1925
                                        raise
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1926
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1927
                # Next, load the existing catalog data and convert it.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1928
                pub_cats = []
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1929
                for pub, old_cat in old_pub_cats:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1930
                        new_cat = pub.catalog
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1931
                        new_cat.batch_mode = True
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1932
                        new_cat.sign = False
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1933
                        if new_cat.exists:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  1934
                                new_cat.destroy()
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  1935
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1936
                        # First convert the old publisher catalog to
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1937
                        # the new format.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1938
                        for f in old_cat.fmris():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1939
                                new_cat.add_package(f)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1940
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1941
                                # Now populate the image catalogs.
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1942
                                states = [self.PKG_STATE_KNOWN,
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1943
                                    self.PKG_STATE_V0]
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1944
                                mdata = { "states": states }
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1945
                                if f.version != newest[f.pkg_name]:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1946
                                        states.append(self.PKG_STATE_UPGRADABLE)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1947
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1948
                                inst_fmri = installed.get(f.pkg_name, None)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1949
                                if inst_fmri and \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1950
                                    inst_fmri.version == f.version and \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1951
                                    pkg.fmri.is_same_publisher(f.publisher,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1952
                                    inst_fmri.publisher):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1953
                                        states.append(self.PKG_STATE_INSTALLED)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1954
                                        if inst_fmri.preferred_publisher():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1955
                                                # Strip the PREF_PUB_PFX.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1956
                                                inst_fmri.set_publisher(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1957
                                                    inst_fmri.get_publisher())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1958
                                        icat.add_package(f, metadata=mdata)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1959
                                        del installed[f.pkg_name]
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1960
                                kcat.add_package(f, metadata=mdata)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1961
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1962
                        # Normally, the Catalog's attributes are automatically
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1963
                        # populated as a result of catalog operations.  But in
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1964
                        # this case, the new Catalog's attributes should match
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1965
                        # those of the old catalog.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1966
                        old_lm = old_cat.last_modified()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1967
                        if old_lm:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1968
                                # Can be None for empty v0 catalogs.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1969
                                old_lm = pkg.catalog.ts_to_datetime(old_lm)
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1970
                        new_cat.last_modified = old_lm
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1971
                        new_cat.version = 0
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1972
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1973
                        # Add to the list of catalogs to save.
1358
6fec8fbc15a6 11324 package state written to parent boot environment during image-update
Shawn Walker <srw@sun.com>
parents: 1353
diff changeset
  1974
                        new_cat.batch_mode = False
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1975
                        pub_cats.append(new_cat)
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1976
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1977
                # Discard the old catalog objects.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1978
                old_pub_cats = None
1068
9400aa8afd32 2557 catalog cache pickle file dependent on fmri and version object definitions
Shawn Walker <srw@sun.com>
parents: 1045
diff changeset
  1979
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1980
                for f in installed.values():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1981
                        # Any remaining FMRIs need to be added to all of the
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1982
                        # image catalogs.
1369
e86145680c34 11359 catalog should offer lazy-load mechanism for action metadata
Shawn Walker <srw@sun.com>
parents: 1358
diff changeset
  1983
                        states = [self.PKG_STATE_INSTALLED, self.PKG_STATE_V0]
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1984
                        mdata = { "states": states }
1353
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1985
                        # This package may be installed from a publisher that
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1986
                        # is no longer known or has been disabled.
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1987
                        if f.pkg_name in newest and \
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1988
                            f.version != newest[f.pkg_name]:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1989
                                states.append(self.PKG_STATE_UPGRADABLE)
1353
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1990
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1991
                        if f.preferred_publisher():
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1992
                                # Strip the PREF_PUB_PFX.
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1993
                                f.set_publisher(f.get_publisher())
b9535ddac1c6 11319 image format upgrade can traceback on installed packages from disabled publisher
Shawn Walker <srw@sun.com>
parents: 1352
diff changeset
  1994
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1995
                        icat.add_package(f, metadata=mdata)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1996
                        kcat.add_package(f, metadata=mdata)
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  1997
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1998
                for cat in pub_cats + [kcat, icat]:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  1999
                        cat.finalize()
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2000
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2001
                # Data conversion finished.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2002
                self.__upgraded = True
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2003
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2004
                try:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2005
                        # Ensure Image directory structure is valid.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2006
                        self.mkdirs()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2007
                except api_errors.PermissionsException, e:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2008
                        progtrack.cache_catalogs_done()
1087
293c0aa5f32e 8214 load_catalogs should only load catalog data when needed
Shawn Walker <srw@sun.com>
parents: 1086
diff changeset
  2009
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2010
                        # An unprivileged user is attempting to use the
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2011
                        # new client with an old image.  Since none of
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2012
                        # the changes can be saved, warn the user and
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2013
                        # then return.
715
5620652f5927 4886 api.info shouldn't be reloading the catalog from disk needlessly
Brock Pytlik <bpytlik@sun.com>
parents: 703
diff changeset
  2014
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2015
                        # Because the new image catalogs couldn't be saved,
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2016
                        # store them in the image's internal cache so that
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2017
                        # operations can function as expected.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2018
                        self.__catalogs[self.IMG_CATALOG_KNOWN] = kcat
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2019
                        self.__catalogs[self.IMG_CATALOG_INSTALLED] = icat
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2020
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2021
                        # Raising an exception here would be a decidedly
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2022
                        # bad thing as it would disrupt find_root, etc.
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2023
                        logger.warning("Package operation performance is "
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2024
                            "currently degraded.\nThis can be resolved by "
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2025
                            "executing 'pkg refresh' as a privileged user.\n")
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2026
                        return
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2027
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2028
                # This has to be done after the permissions check above.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2029
                tmp_state_root = self.temporary_dir()
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2030
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2031
                # Create new image catalogs.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2032
                kcat.meta_root = os.path.join(tmp_state_root,
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2033
                    self.IMG_CATALOG_KNOWN)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2034
                icat.meta_root = os.path.join(tmp_state_root,
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2035
                    self.IMG_CATALOG_INSTALLED)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2036
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2037
                # Assume that since mkdirs succeeded that the remaining data
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2038
                # can be saved and the image structure can be upgraded.  But
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2039
                # first, attempt to save the image catalogs before changing
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2040
                # structure.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2041
                for cat in icat, kcat:
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1505
diff changeset
  2042
                        os.makedirs(cat.meta_root, mode=misc.PKG_DIR_MODE)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2043
                        cat.save()
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2044
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2045
                # Next, reset the publisher meta_roots to reflect the new
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2046
                # directory structure and move each publisher's catalog files
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2047
                # to the new catalog root.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2048
                for pub in self.gen_publishers():
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2049
                        old_root = pub.meta_root
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2050
                        pub.meta_root = self._get_publisher_meta_root(
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2051
                            pub.prefix)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2052
                        pub.create_meta_root()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2053
                        for fname in os.listdir(old_root):
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2054
                                src = os.path.join(old_root, fname)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2055
                                if fname == "last_refreshed":
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2056
                                        dest = os.path.join(pub.meta_root,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2057
                                            fname)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2058
                                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2059
                                        dest = os.path.join(pub.catalog_root,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2060
                                            fname)
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2061
                                portable.rename(src, dest)
418
21621fd99956 2543 eliminate unnecessary stat() calls from gen_installed_pkgs()
Danek Duvall <danek.duvall@sun.com>
parents: 409
diff changeset
  2062
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2063
                # Next, save all of the new publisher catalogs.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2064
                for cat in pub_cats:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2065
                        cat.save()
226
8939051a496c 376 image must use default authority when none specified
johansen <johansen@sun.com>
parents: 222
diff changeset
  2066
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2067
                # Next, preserve the old catalog and state directories.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2068
                # Then, rename the new state directory into place, and then
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2069
                # remove the old catalog and state directories.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2070
                cat_root = os.path.join(self.imgdir, "catalog")
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2071
                orig_cat_root = self.__salvagedir(cat_root)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2072
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2073
                state_root = os.path.join(self.imgdir, "state")
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2074
                orig_state_root = self.__salvagedir(state_root)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2075
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2076
                portable.rename(tmp_state_root, state_root)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2077
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2078
                # Ensure in-memory catalogs get reloaded.
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  2079
                self.__init_catalogs()
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2080
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2081
                # Finally, dump the old, unused dirs and mark complete.
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2082
                shutil.rmtree(orig_cat_root, True)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2083
                shutil.rmtree(orig_state_root, True)
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2084
                progtrack.cache_catalogs_done()
516
53da6297fb65 3039 Install and Image-update should check index consistency with installed packages
Brock Pytlik <bpytlik@sun.com>
parents: 499
diff changeset
  2085
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2086
        def strtofmri(self, myfmri):
423
5c756997bf67 2253 With the latest build of the pkg repo, can't install packages from additional authorities
Danek Duvall <danek.duvall@sun.com>
parents: 419
diff changeset
  2087
                return pkg.fmri.PkgFmri(myfmri, self.attrs["Build-Release"])
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2088
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2089
        def strtomatchingfmri(self, myfmri):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2090
                return pkg.fmri.MatchingPkgFmri(myfmri,
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2091
                    self.attrs["Build-Release"])
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2092
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2093
        def get_user_by_name(self, name):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2094
                return portable.get_user_by_name(name, self.root,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2095
                    self.type != IMG_USER)
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  2096
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2097
        def get_name_by_uid(self, uid, returnuid = False):
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  2098
                # XXX What to do about IMG_PARTIAL?
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2099
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2100
                        return portable.get_name_by_uid(uid, self.root,
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2101
                            self.type != IMG_USER)
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2102
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2103
                        if returnuid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2104
                                return uid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2105
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2106
                                raise
243
ca57127811b8 399 pkg list on explicit packages fails with no output, exit status of 1
Stephen Hahn <sch@Sun.COM>
parents: 239
diff changeset
  2107
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2108
        def get_group_by_name(self, name):
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2109
                return portable.get_group_by_name(name, self.root,
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2110
                    self.type != IMG_USER)
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  2111
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2112
        def get_name_by_gid(self, gid, returngid = False):
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2113
                try:
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2114
                        return portable.get_name_by_gid(gid, self.root,
339
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2115
                            self.type != IMG_USER)
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2116
                except KeyError:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2117
                        if returngid:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2118
                                return gid
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2119
                        else:
d8e57580599b 1271 pkg verify tracebacks on files owned by my uid...
Danek Duvall <danek.duvall@sun.com>
parents: 331
diff changeset
  2120
                                raise
173
da329417a206 18 Actions should use passwd and group databases from image, if possible
Danek Duvall <danek.duvall@sun.com>
parents: 172
diff changeset
  2121
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2122
        @staticmethod
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2123
        def __multimatch(name, patterns):
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2124
                """Applies a matcher to a name across a list of patterns.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2125
                Returns all tuples of patterns which match the name.  Each tuple
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2126
                contains the index into the original list, the pattern itself,
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2127
                the package version, the publisher, and the raw publisher
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2128
                string."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2129
                return [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2130
                    (i, pat, pat.tuple()[2],
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2131
                        pat.publisher, pat.publisher)
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2132
                    for i, (pat, m) in enumerate(patterns)
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2133
                    if m(name, pat.tuple()[1])
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2134
                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2135
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2136
        def __inventory(self, patterns=None, all_known=False, matcher=None,
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2137
            constraint=pkg.version.CONSTRAINT_AUTO, ordered=True):
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2138
                """Private method providing the back-end for inventory()."""
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2139
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2140
                if not matcher:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2141
                        matcher = pkg.fmri.fmri_match
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2142
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2143
                if not patterns:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2144
                        patterns = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2145
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2146
                # Store the original patterns before we possibly turn them into
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2147
                # PkgFmri objects, so we can give them back to the user in error
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2148
                # messages.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2149
                opatterns = patterns[:]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2150
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2151
                # Match the matching function with the pattern so that we can
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2152
                # change it per-pattern, depending on whether it has glob
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2153
                # characters or nails down the pattern with a leading pkg:/.
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2154
                patterns = [ (i, matcher) for i in patterns ]
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2155
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2156
                illegals = []
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2157
                for i, (pat, m) in enumerate(patterns):
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2158
                        if not isinstance(pat, pkg.fmri.PkgFmri):
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2159
                                try:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2160
                                        if "*" in pat or "?" in pat:
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2161
                                                patterns[i] = (
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2162
                                                    pkg.fmri.MatchingPkgFmri(
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2163
                                                        pat, "5.11"),
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2164
                                                    pkg.fmri.glob_match)
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2165
                                        elif pat.startswith("pkg:/"):
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2166
                                                patterns[i] = (
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2167
                                                    pkg.fmri.PkgFmri(pat,
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2168
                                                        "5.11"),
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2169
                                                    pkg.fmri.exact_name_match)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2170
                                        else:
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2171
                                                patterns[i] = (
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2172
                                                    pkg.fmri.PkgFmri(pat,
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2173
                                                        "5.11"),
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2174
                                                    pkg.fmri.fmri_match)
526
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2175
                                except pkg.fmri.IllegalFmri, e:
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2176
                                        illegals.append(e)
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2177
8c243883ae41 822 Depot traceback on "pkgsend -s <server> open foo"
Dan Price <dp@eng.sun.com>
parents: 518
diff changeset
  2178
                if illegals:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2179
                        raise api_errors.InventoryException(illegal=illegals)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2180
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2181
                # matchingpats is the set of all the patterns which matched a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2182
                # package in the catalog.  This allows us to return partial
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2183
                # failure if some patterns match and some don't.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2184
                # XXX It would be nice to keep track of why some patterns failed
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2185
                # to match -- based on name, version, or publisher.
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2186
                matchingpats = set()
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2187
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2188
                if all_known:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2189
                        cat = self.get_catalog(self.IMG_CATALOG_KNOWN)
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2190
                else:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2191
                        cat = self.get_catalog(self.IMG_CATALOG_INSTALLED)
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2192
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2193
                if ordered:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2194
                        names = sorted(cat.names())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2195
                else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2196
                        names = cat.names()
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2197
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2198
                for name in names:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2199
                        # Eliminate all patterns not matching "name".  If there
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2200
                        # are no patterns left, go on to the next name, but only
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2201
                        # if there were any to start with.
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2202
                        matches = self.__multimatch(name, patterns)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2203
                        if patterns and not matches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2204
                                continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2205
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2206
                        rversions = reversed(list(cat.entries_by_version(name)))
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2207
                        for ver, entries in rversions:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2208
                                # If a pattern specified a version and that
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2209
                                # version isn't succeeded by "ver", then record
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2210
                                # the pattern for removal from consideration.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2211
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2212
                                for i, match in enumerate(matches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2213
                                        if match[2] and \
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2214
                                            not ver.is_successor(match[2],
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2215
                                                constraint):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2216
                                                nomatch.append(i)
221
e1dbb27a23b5 52 catalog can leave inventory behind, making pkg(1) blind
Stephen Hahn <sch@Sun.COM>
parents: 219
diff changeset
  2217
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2218
                                # Eliminate the name matches that didn't match
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2219
                                # on versions.  We need to create a new list
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2220
                                # because we need to reuse the original
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2221
                                # "matches" for each new version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2222
                                vmatches = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2223
                                    matches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2224
                                    for i, match in enumerate(matches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2225
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2226
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2227
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2228
                                # If we deleted all contenders (if we had any to
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2229
                                # begin with), go on to the next version.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2230
                                if matches and not vmatches:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2231
                                        continue
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2232
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2233
                                # Like the version skipping above, do the same
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2234
                                # for publishers.
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2235
                                publist = set([f[0].publisher for f in entries])
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2236
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2237
                                nomatch = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2238
                                for i, match in enumerate(vmatches):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2239
                                        if match[3] and \
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2240
                                            match[3] not in publist:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2241
                                                nomatch.append(i)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2242
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2243
                                pmatches = [
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2244
                                    vmatches[i]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2245
                                    for i, match in enumerate(vmatches)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2246
                                    if i not in nomatch
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2247
                                ]
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2248
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2249
                                if vmatches and not pmatches:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2250
                                        continue
104
ecfc64baf22e add naive configuration, naive global/preferred authorities, delete content
Stephen Hahn <sch@sun.com>
parents: 87
diff changeset
  2251
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2252
                                # If no patterns were specified or any still-
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2253
                                # matching pattern specified no publisher, we
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2254
                                # use the entire list of publishers for this
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2255
                                # version.  Otherwise, we use the intersection
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2256
                                # of the list of publishers in pubstate, and
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2257
                                # the publishers in the patterns.
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2258
                                aset = set(i[3] for i in pmatches)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2259
                                if aset and None not in aset:
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2260
                                        publist = set(
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2261
                                            m[3]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2262
                                            for m in pmatches
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2263
                                            if m[3] in publist
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2264
                                        )
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2265
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2266
                                matchingpats |= set(i[:2] for i in vmatches)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2267
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2268
                                for f, entry in entries:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2269
                                        if f.publisher not in publist:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2270
                                                continue
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2271
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2272
                                        states = entry["metadata"]["states"]
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2273
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2274
                                        known = self.PKG_STATE_KNOWN in states
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2275
                                        st = {
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2276
                                            "frozen": False,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2277
                                            "in_catalog": known,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2278
                                            "incorporated": False,
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2279
                                            "excludes": False,
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2280
                                            "upgradable": self.PKG_STATE_UPGRADABLE in states,
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2281
                                            "obsolete": self.PKG_STATE_OBSOLETE in states,
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2282
                                            "renamed": self.PKG_STATE_RENAMED in states
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2283
                                        }
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2284
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2285
                                        if self.PKG_STATE_INSTALLED in states:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2286
                                                st["state"] = \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2287
                                                    self.PKG_STATE_INSTALLED
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2288
                                        elif known:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2289
                                                # XXX long-term, a package could
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2290
                                                # be 'frozen' or something else
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2291
                                                # and no longer available (in a
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2292
                                                # catalog).
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2293
                                                st["state"] = \
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2294
                                                    self.PKG_STATE_KNOWN
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2295
                                        else:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2296
                                                # Must be in some other state;
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2297
                                                # see comment above.
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2298
                                                st["state"] = None
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2299
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2300
                                        yield f, st
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2301
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2302
                nonmatchingpats = [
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2303
                    opatterns[i]
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2304
                    for i, f in set(enumerate((p[0] for p in patterns))) - matchingpats
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2305
                ]
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2306
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2307
                if nonmatchingpats:
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2308
                        raise api_errors.InventoryException(
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2309
                            notfound=nonmatchingpats)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2310
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2311
        def inventory(self, *args, **kwargs):
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2312
                """Enumerate the package FMRIs in the image's catalog, yielding
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2313
                a list of tuples of the format (fmri, pkg state dict).
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2314
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2315
                If "patterns" is None (the default) or an empty sequence, all
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2316
                package names will match.  Otherwise, it is a list of patterns
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2317
                to match against FMRIs in the catalog.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2318
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2319
                If "all_known" is False (the default), only installed packages
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2320
                will be enumerated.  If True, all known packages will be
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2321
                enumerated.
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2322
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2323
                The "matcher" parameter should specify a function taking two
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2324
                string arguments: a name and a pattern, returning True if the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2325
                pattern matches the name, and False otherwise.  By default, the
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2326
                matcher will be pkg.fmri.fmri_match().
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2327
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2328
                The "constraint" parameter defines how a version specified in a
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2329
                pattern matches a version in the catalog.  By default, a natural
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2330
                "subsetting" constraint is used.
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2331
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2332
                The "ordered" parameter is a boolean value that indicates
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2333
                whether the returned list should first be sorted by name before
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2334
                being sorted by version (descending).  By default, this is True.
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2335
                """
161
e0322fe7842c Simplify and correct the package matching code.
Danek Duvall <danek.duvall@sun.com>
parents: 157
diff changeset
  2336
1158
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2337
                # "preferred" is a private argument that is currently only used
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2338
                # in evaluate_fmri(), but could be made more generally useful.
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2339
                # "preferred" ensures that all potential matches from the
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2340
                # preferred publisher are generated before those from
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2341
                # non-preferred publishers.  In the current implementation, this
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2342
                # consumes more memory.
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2343
                preferred = kwargs.pop("preferred", False)
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2344
                if not preferred:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2345
                        for f in self.__inventory(*args, **kwargs):
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2346
                                yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2347
                else:
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2348
                        ppub = self.get_preferred_publisher()
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2349
                        nplist = []
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2350
                        for f in self.__inventory(*args, **kwargs):
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2351
                                if f[0].publisher == ppub:
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2352
                                        yield f
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2353
                                else:
1158
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2354
                                        nplist.append(f)
419
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2355
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2356
                        for f in nplist:
a38f1ed7cf76 1867 'pkg list' takes *WAY* too long
Danek Duvall <danek.duvall@sun.com>
parents: 418
diff changeset
  2357
                                yield f
59
eef94b0c0694 require dependencies; dependency following; pkg status; timestamp change
Stephen Hahn <sch@sun.com>
parents: 51
diff changeset
  2358
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2359
        def update_index_dir(self, postfix="index"):
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2360
                """Since the index directory will not reliably be updated when
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2361
                the image root is, this should be called prior to using the
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2362
                index directory.
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2363
                """
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2364
                self.index_dir = os.path.join(self.imgdir, postfix)
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2365
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2366
        def incoming_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2367
                """Return the directory path for incoming downloads
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2368
                that have yet to be completed.  Once a file has been
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2369
                successfully downloaded, it is moved to the cached download
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2370
                directory."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2371
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2372
                return self.dl_cache_incoming
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2373
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2374
        def cached_download_dir(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2375
                """Return the directory path for cached content.
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2376
                Files that have been successfully downloaded live here."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2377
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2378
                return self.dl_cache_dir
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2379
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2380
        def cleanup_downloads(self):
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2381
                """Clean up any downloads that were in progress but that
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2382
                did not successfully finish."""
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2383
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2384
                shutil.rmtree(self.dl_cache_incoming, True)
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2385
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2386
        def cleanup_cached_content(self):
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2387
                """Delete the directory that stores all of our cached
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2388
                downloaded content.  This may take a while for a large
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2389
                directory hierarchy.  Don't clean up caches if the
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2390
                user overrode the underlying setting using PKG_CACHEDIR. """
388
5a08791fb814 2188 Client must fail gracefully when network timeout occurs
johansen <johansen@sun.com>
parents: 384
diff changeset
  2391
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2392
                if not self.is_user_cache_dir and \
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2393
                    self.cfg_cache.get_policy(imageconfig.FLUSH_CONTENT_CACHE):
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2394
                        logger.info("Deleting content cache")
554
fe196874250d 3508 zone install should utilize/populate global zone d/l cache
Dan Price <dp@eng.sun.com>
parents: 552
diff changeset
  2395
                        shutil.rmtree(self.dl_cache_dir, True)
289
c2e63370fb2b 160 Make IPS cross-platform for use across other supported OS's
Tom Mueller <Tom.Mueller@Sun.COM>
parents: 285
diff changeset
  2396
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2397
        def __salvagedir(self, path):
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2398
                sdir = os.path.normpath(
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2399
                    os.path.join(self.imgdir, "lost+found",
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2400
                    path + "-" + time.strftime("%Y%m%dT%H%M%SZ")))
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2401
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2402
                parent = os.path.dirname(sdir)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2403
                if not os.path.exists(parent):
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2404
                        os.makedirs(parent)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2405
                shutil.move(os.path.normpath(os.path.join(self.root, path)),
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2406
                    sdir)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2407
                return sdir
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2408
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2409
        def salvagedir(self, path):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2410
                """Called when directory contains something and it's not
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2411
                supposed to because it's being deleted. XXX Need to work out a
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2412
                better error passback mechanism. Path is rooted in /...."""
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2413
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2414
                sdir = self.__salvagedir(path)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2415
                logger.warning("\nWarning - directory %s not empty - contents "
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2416
                    "preserved in %s" % (path, sdir))
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2417
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2418
        def temporary_dir(self):
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2419
                """create a temp directory under image directory for various
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2420
                purposes"""
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2421
                tempdir = os.path.normpath(os.path.join(self.imgdir, "tmp"))
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2422
                try:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2423
                        if not os.path.exists(tempdir):
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2424
                                os.makedirs(tempdir)
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  2425
                        rval = tempfile.mkdtemp(dir=tempdir)
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  2426
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  2427
                        # Force standard mode.
1507
b956ea23d3a6 11735 pkg history data files should not be executable
Richard Lowe <richlowe@richlowe.net>
parents: 1505
diff changeset
  2428
                        os.chmod(rval, misc.PKG_DIR_MODE)
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  2429
                        return rval
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2430
                except EnvironmentError, e:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2431
                        if e.errno == errno.EACCES:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2432
                                raise api_errors.PermissionsException(
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2433
                                    e.filename)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2434
                        if e.errno == errno.EROFS:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2435
                                raise api_errors.ReadOnlyFileSystemException(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2436
                                    e.filename)
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2437
                        raise
251
6c3d70b74865 470 pkg image-update can fail under some conditions
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 243
diff changeset
  2438
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2439
        def temporary_file(self):
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2440
                """create a temp file under image directory for various
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2441
                purposes"""
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2442
                tempdir = os.path.normpath(os.path.join(self.imgdir, "tmp"))
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2443
                try:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2444
                        if not os.path.exists(tempdir):
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2445
                                os.makedirs(tempdir)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2446
                        fd, name = tempfile.mkstemp(dir=tempdir)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2447
                        os.close(fd)
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2448
                except EnvironmentError, e:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2449
                        if e.errno == errno.EACCES:
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2450
                                raise api_errors.PermissionsException(
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2451
                                    e.filename)
1431
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2452
                        if e.errno == errno.EROFS:
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2453
                                raise api_errors.ReadOnlyFileSystemException(
62b6033670e4 10416 server catalog v1 support desired
Shawn Walker <srw@sun.com>
parents: 1402
diff changeset
  2454
                                    e.filename)
1402
c0fb578f911a 11384 cascading failure hides exception during image creation
Shawn Walker <srw@sun.com>
parents: 1370
diff changeset
  2455
                        raise
462
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2456
                return name
910600c14093 45 "move" action for files that are renamed, but must be preserved
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 461
diff changeset
  2457
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2458
        def __filter_install_matches(self, matches):
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2459
                """Attempts to eliminate redundant matches found during
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2460
                packaging operations:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2461
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2462
                    * First, stems of installed packages for publishers that
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2463
                      are now unknown (no longer present in the image
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2464
                      configuration) are dropped.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2465
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2466
                    * Second, if multiple matches are still present, stems of
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2467
                      of installed packages, that are not presently in the
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2468
                      corresponding publisher's catalog, are dropped.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2469
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2470
                    * Finally, if multiple matches are still present, all
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2471
                      stems except for those in state PKG_STATE_INSTALLED are
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2472
                      dropped.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2473
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2474
                Returns a list of the filtered matches, along with a dict of
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2475
                their unique names."""
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2476
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2477
                olist = []
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2478
                onames = set()
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2479
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2480
                # First eliminate any duplicate matches that are for unknown
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2481
                # publishers (publishers which have been removed from the image
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2482
                # configuration).
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2483
                publist = set(p.prefix for p in self.get_publishers().values())
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2484
                for m, st in matches:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2485
                        if m.publisher in publist:
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2486
                                onames.add(m.get_pkg_stem())
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2487
                                olist.append((m, st))
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2488
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2489
                # Next, if there are still multiple matches, eliminate matches
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2490
                # belonging to publishers that no longer have the FMRI in their
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2491
                # catalog.
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2492
                found_state = False
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2493
                if len(onames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2494
                        mlist = []
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2495
                        mnames = set()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2496
                        for m, st in olist:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2497
                                if not st["in_catalog"]:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2498
                                        continue
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2499
                                if st["state"] == self.PKG_STATE_INSTALLED:
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2500
                                        found_state = True
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2501
                                mnames.add(m.get_pkg_stem())
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2502
                                mlist.append((m, st))
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2503
                        olist = mlist
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2504
                        onames = mnames
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2505
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2506
                # Finally, if there are still multiple matches, and a known
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2507
                # stem is installed, then eliminate any stems that do not
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2508
                # have an installed version.
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2509
                if found_state and len(onames) > 1:
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2510
                        mlist = []
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2511
                        mnames = set()
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2512
                        for m, st in olist:
1463
0ef25025d601 12340 catalog storage performance regression
Shawn Walker <srw@sun.com>
parents: 1461
diff changeset
  2513
                                if st["state"] == self.PKG_STATE_INSTALLED:
1461
fdf40c8c6765 820 Need a way to obsolete packages
Danek Duvall <danek.duvall@sun.com>
parents: 1449
diff changeset
  2514
                                        mnames.add(m.get_pkg_stem())
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2515
                                        mlist.append((m, st))
988
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2516
                        olist = mlist
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2517
                        onames = mnames
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2518
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2519
                return olist, onames
a851ba83a5aa 6654 pkg list state incorrect after publisher removal when another publisher has it
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 964
diff changeset
  2520
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2521
        def make_install_plan(self, pkg_list, progtrack, check_cancelation,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2522
            noexecute, verbose=False):
296
576858fb8376 398 disambiguate packages matching the default authority
johansen <johansen@sun.com>
parents: 289
diff changeset
  2523
                """Take a list of packages, specified in pkg_list, and attempt
329
f549eab0d7b7 735 install -n uninformative
Dan Price <dp@eng.sun.com>
parents: 327
diff changeset
  2524
                to assemble an appropriate image plan.  This is a helper
429
6c9cbb6e6600 983 pkg search returns just one action per package/token-type combo
Brock Pytlik <bpytlik@sun.com>
parents: 423
diff changeset
  2525
                routine for some common operations in the client.
1158
78582c4403a9 8616 operations should use same publisher when only non-preferred has package
Shawn Walker <srw@sun.com>
parents: 1143
diff changeset
  2526
                """
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2527
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2528
                ip = imageplan.ImagePlan(self, progtrack, check_cancelation,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2529
                    noexecute=noexecute)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2530
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2531
                progtrack.evaluate_start()
307
3a857fd8b787 787 optional dependencies are required
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 302
diff changeset
  2532
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2533
                # Always start with most current (on-disk) state information.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2534
                self.__init_catalogs()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2535
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2536
                try:
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2537
                        ip.plan_install(pkg_list)
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2538
1549
cc81f5023603 13110 image catalog rebuild could be faster
Shawn Walker <srw@sun.com>
parents: 1538
diff changeset
  2539
                except api_errors.ApiException:
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2540
                        ip.show_failure(verbose)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2541
                        raise
172
e3b310617b04 6 pkg image-update subcommand
Stephen Hahn <sch@Sun.COM>
parents: 163
diff changeset
  2542
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  2543
                self.__call_imageplan_evaluate(ip, verbose)
45
8a3f00dea14f catalog refresh; basic catalog listing; precise manifest pulls
Stephen Hahn <sch@sun.com>
parents: 39
diff changeset
  2544
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2545
        def make_update_plan(self, progtrack, check_cancelation,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2546
            noexecute, verbose=False):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2547
                """Create a plan to update all packages as far as
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2548
                possible."""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2549
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2550
                progtrack.evaluate_start()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2551
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2552
                ip = imageplan.ImagePlan(self, progtrack, check_cancelation,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2553
                    noexecute=noexecute)
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2554
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2555
                # Always start with most current (on-disk) state information.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2556
                self.__init_catalogs()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2557
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2558
                ip.plan_update()
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2559
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2560
                self.__call_imageplan_evaluate(ip, verbose)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2561
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2562
        def make_uninstall_plan(self, fmri_list, recursive_removal,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2563
            progtrack, check_cancelation, noexecute, verbose=False):
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2564
                """Create uninstall plan to remove the specified packages;
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2565
                do so recursively iff recursive_removal is set"""
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2566
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2567
                progtrack.evaluate_start()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2568
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2569
                ip = imageplan.ImagePlan(self, progtrack,
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2570
                    check_cancelation, noexecute=noexecute)
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2571
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2572
                # Always start with most current (on-disk) state information.
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2573
                self.__init_catalogs()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2574
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2575
                ip.plan_uninstall(fmri_list, recursive_removal)
1271
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  2576
036d87b0bd44 6831 need 'pkg change-variant' command
Edward Pilatowicz <Edward.Pilatowicz@Sun.COM>
parents: 1256
diff changeset
  2577
                self.__call_imageplan_evaluate(ip, verbose)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2578
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2579
        def ipkg_is_up_to_date(self, actual_cmd, check_cancelation, noexecute,
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2580
            refresh_allowed=True, progtrack=None):
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2581
                """ Test whether SUNWipkg is updated to the latest version
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2582
                    known to be available for this image """
1352
5c92c9d342ef 11065 client v1 catalog support for v0 catalogs
Shawn Walker <srw@sun.com>
parents: 1328
diff changeset
  2583
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2584
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2585
                # This routine makes the distinction between the "target image",
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2586
                # which will be altered, and the "running image", which is
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2587
                # to say whatever image appears to contain the version of the
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2588
                # pkg command we're running.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2589
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2590
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2591
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2592
                # There are two relevant cases here:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2593
                #     1) Packaging code and image we're updating are the same
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2594
                #        image.  (i.e. 'pkg image-update')
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2595
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2596
                #     2) Packaging code's image and the image we're updating are
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2597
                #        different (i.e. 'pkg image-update -R')
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2598
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2599
                # In general, we care about getting the user to run the
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2600
                # most recent packaging code available for their build.  So,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2601
                # if we're not in the liveroot case, we create a new image
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2602
                # which represents "/" on the system.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2603
                #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2604
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2605
                if not progtrack:
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2606
                        progtrack = progress.QuietProgressTracker()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2607
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2608
                img = self
926
6ee411c9026a 5871 publisher apis desired
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 922
diff changeset
  2609
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2610
                if not img.is_liveroot():
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2611
                        cmdpath = os.path.join(os.getcwd(), actual_cmd)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2612
                        cmdpath = os.path.realpath(cmdpath)
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2613
                        cmddir = os.path.dirname(os.path.realpath(cmdpath))
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2614
                        #
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2615
                        # Find the path to ourselves, and use that
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2616
                        # as a way to locate the image we're in.  It's
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2617
                        # not perfect-- we could be in a developer's
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2618
                        # workspace, for example.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2619
                        #
1370
face1fe579ab 11400 image objects should always have a root
Brock Pytlik <bpytlik@sun.com>
parents: 1369
diff changeset
  2620
                        newimg = Image(cmddir, progtrack=progtrack)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2621
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2622
                        if refresh_allowed:
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2623
                                # If refreshing publisher metadata is allowed,
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2624
                                # then perform a refresh so that a new SUNWipkg
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2625
                                # can be discovered.
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2626
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2627
                                newimg.lock()
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2628
                                try:
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2629
                                        newimg.refresh_publishers(
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2630
                                            progtrack=progtrack)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2631
                                except api_errors.CatalogRefreshException, cre:
1603
84bd53597209 13019 DeprecationWarnings seen after python 2.6 migration
Dan Price <dp@eng.sun.com>
parents: 1586
diff changeset
  2632
                                        cre.errmessage = \
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2633
                                            _("SUNWipkg update check failed.")
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2634
                                        raise
1710
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2635
                                finally:
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2636
                                        newimg.unlock()
139720e2e756 1668 image locking needed to prevent race conditions
Shawn Walker <srw@sun.com>
parents: 1688
diff changeset
  2637
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2638
                        img = newimg
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2639
996
31d152a5212b 7582 pkg set-publisher --no-refresh will delete catalogs
Shawn Walker <Shawn.Walker@Sun.COM>
parents: 993
diff changeset
  2640
                # XXX call to progress tracker that SUNWipkg is being refreshed
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2641
625
e46b345645d6 3799 need to start progress tracker going early on
Brock Pytlik <bpytlik@sun.com>
parents: 621
diff changeset
  2642
                img.make_install_plan(["SUNWipkg"], progtrack,
1505
cc598d70bbbe 4425 pkg install should deal w/ complex dependency changes in one install
Bart Smaalders <Bart.Smaalders@Sun.COM>
parents: 1504
diff changeset
  2643
                    check_cancelation, noexecute)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2644
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2645
                return img.imageplan.nothingtodo()
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2646
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2647
        def installed_fmris_from_args(self, args):
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2648
                """Helper function to translate client command line arguments
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2649
                into a list of installed fmris.  Used by info, contents,
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2650
                verify.
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2651
                """
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2652
                found = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2653
                notfound = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2654
                illegals = []
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2655
                try:
1045
62656c214151 8135 plan creation could be faster for install and uninstall
Shawn Walker <srw@sun.com>
parents: 1037
diff changeset
  2656
                        for m in self.inventory(args, ordered=False):
1537
00a5b4d54eb8 5872 List APIs required
Shawn Walker <srw@sun.com>
parents: 1516
diff changeset
  2657
                                found.append(m)
565
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2658
                except api_errors.InventoryException, e:
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2659
                        illegals = e.illegal
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2660
                        notfound = e.notfound
1fb4f05220b9 3443 An api needs to be provided for safe interaction of front-ends
Brock Pytlik <bpytlik@sun.com>
parents: 562
diff changeset
  2661
                return found, notfound, illegals