pkgplan.py revision 50
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#!/usr/bin/python
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# CDDL HEADER START
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# The contents of this file are subject to the terms of the
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# Common Development and Distribution License (the "License").
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# You may not use this file except in compliance with the License.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# or http://www.opensolaris.org/os/licensing.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# See the License for the specific language governing permissions
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# and limitations under the License.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# When distributing Covered Code, include this CDDL HEADER in each
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# If applicable, add the following below this CDDL HEADER, with the
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# fields enclosed by brackets "[]" replaced with your own identifying
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# information: Portions Copyright [yyyy] [name of copyright owner]
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# CDDL HEADER END
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#
d62bc4badc1c1f1549c961cfb8b420e650e1272byz
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc# Use is subject to license terms.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcimport os
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcimport re
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcimport urllib
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc
d62bc4badc1c1f1549c961cfb8b420e650e1272byzimport pkg.catalog as catalog
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcclass PkgPlan(object):
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh """A package plan takes two package FMRIs and an Image, and produces the
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh set of actions required to take the Image from the origin FMRI to the
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh destination FMRI."""
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh def __init__(self, image):
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh self.origin_fmri = None
f595a68a3b8953a12aa778c2abd7642df8da8c3ayz self.destination_fmri = None
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc self.origin_mfst = None
d62bc4badc1c1f1549c961cfb8b420e650e1272byz self.destination_mfst = None
f595a68a3b8953a12aa778c2abd7642df8da8c3ayz
d62bc4badc1c1f1549c961cfb8b420e650e1272byz self.image = image
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh self.actions = []
d62bc4badc1c1f1549c961cfb8b420e650e1272byz
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini def set_origin(self, fmri):
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini self.origin_fmri = fmri
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini self.origin_mfst = manifest.retrieve(fmri)
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan def propose_destination(self, fmri, manifest):
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan self.destination_fmri = fmri
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh self.destination_mfst = manifest
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems def is_valid(self):
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems if self.origin_fmri == None:
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return True
d62bc4badc1c1f1549c961cfb8b420e650e1272byz
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini if not self.origin_fmri.is_same_pkg(self.destination_fmri):
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return False
d62bc4badc1c1f1549c961cfb8b420e650e1272byz
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if self.origin_fmri > self.destination_fmri:
d62bc4badc1c1f1549c961cfb8b420e650e1272byz return False
d62bc4badc1c1f1549c961cfb8b420e650e1272byz
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini return True
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini def get_actions(self):
6b9e797c2ea518518cb2b57895991d8bdaa167fesowmini return []
afdda45f890ee5dfc86e5131a30b11b354d51633Vasumathi Sundaram - Sun Microsystems
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh def evaluate(self):
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # if origin unset, determine if we're dealing with an previously
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # installed version or if we're dealing with the null package
d62bc4badc1c1f1549c961cfb8b420e650e1272byz f = None
d62bc4badc1c1f1549c961cfb8b420e650e1272byz if self.origin_fmri == None:
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini try:
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini f = self.image.get_version_installed(self.destination_fmri)
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini except LookupError:
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini pass
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini # if null package, then our plan is the set of actions for the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # destination version
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini if f == None:
6b9e797c2ea518518cb2b57895991d8bdaa167fesowmini self.actions = self.destination_mfst.actions
6b9e797c2ea518518cb2b57895991d8bdaa167fesowmini else:
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh # if a previous package, then our plan is derived from the
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh # set differences between the previous manifest's actions and
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # the union of the destination manifest's actions with the
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # critical actions of the critical versions in the version
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # interval between origin and destination.
d62bc4badc1c1f1549c961cfb8b420e650e1272byz self.actions = self.destination_mfst.difference(
d62bc4badc1c1f1549c961cfb8b420e650e1272byz self.origin_mfst)
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini return
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini def preexecute(self):
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini # retrieval step
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini return
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini def execute(self):
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini # record that we are in an intermediate state
d62bc4badc1c1f1549c961cfb8b420e650e1272byz # mv step
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini # XXX
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini for a in self.actions:
6b9e797c2ea518518cb2b57895991d8bdaa167fesowmini print a
6b9e797c2ea518518cb2b57895991d8bdaa167fesowmini return
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan def postexecute(self):
3fd94f8c011031b38162a1db3b554de4371c167fam # record that package states are consistent
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini return
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini