usr/src/lib/install_target/instantiation_zone.py
changeset 1160 6f7e708c38ec
child 1273 c4a56398929a
equal deleted inserted replaced
1159:fbde90ccfae9 1160:6f7e708c38ec
       
     1 #!/usr/bin/python
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 
       
    23 #
       
    24 # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
       
    25 #
       
    26 
       
    27 """ instantiation.py - target instantiation checkpoint.  Parses the Data Object
       
    28 Cache for physical and logical targets.
       
    29 """
       
    30 from solaris_install import ApplicationData
       
    31 from solaris_install.engine import InstallEngine
       
    32 from solaris_install.target import Target
       
    33 from solaris_install.target.instantiation import TargetInstantiation
       
    34 from solaris_install.target.logical import BE, DatasetOptions, Filesystem, Zpool
       
    35 
       
    36 ALT_POOL_DATASET = "alt_pool_dataset"
       
    37 
       
    38 class TargetInstantiationZone(TargetInstantiation):
       
    39     """ class to instantiate targets
       
    40     """
       
    41 
       
    42     def __init__(self, name):
       
    43         super(TargetInstantiation, self).__init__(name)
       
    44 
       
    45         # lists for specific elements in the DOC
       
    46         self.logical_list = list()
       
    47 
       
    48         self.pool_dataset = None
       
    49 
       
    50     def parse_doc(self):
       
    51         """ class method for parsing the data object cache (DOC) objects
       
    52         for use by this checkpoint
       
    53         """
       
    54 
       
    55         # doc and target nodes
       
    56         self.doc = InstallEngine.get_instance().data_object_cache
       
    57         self.target = self.doc.get_descendants(name=Target.DESIRED,
       
    58                                                class_type=Target)[0]
       
    59 
       
    60         # get the alternate "pool" dataset underwhich to instantiate the target
       
    61         app_data = self.doc.persistent.get_first_child( \
       
    62             class_type=ApplicationData)
       
    63         if app_data:
       
    64             self.pool_dataset = app_data.data_dict.get(ALT_POOL_DATASET)
       
    65 
       
    66         if not self.pool_dataset:
       
    67             raise RuntimeError("No alternate 'pool' dataset specified")
       
    68 
       
    69         self.logical_list = self.target.get_descendants(class_type=Zpool)
       
    70 
       
    71     def create_logicals(self):
       
    72         """ method used to parse the logical targets and create the objects
       
    73         with action of "create".
       
    74         """
       
    75 
       
    76         for zpool in self.logical_list:
       
    77             # For a zone root, we process the BE and filesystems.
       
    78             be_list = zpool.get_children(class_type=BE)
       
    79             fs_list = zpool.get_children(class_type=Filesystem)
       
    80 
       
    81             # Process filesystems.
       
    82             be_fs_list = list()
       
    83             shared_fs_list = list()
       
    84             for fs in fs_list:
       
    85                 if fs.action == "create":
       
    86                     # TODO: Parse options string and mountpoint and add
       
    87                     # to zfs properties list here...
       
    88 
       
    89                     if fs.in_be:
       
    90                         # Append filesystem name to BE filesystem list
       
    91                         be_fs_list.append(fs.name)
       
    92                     else:
       
    93                         # Append filesystem name to shared filesystem list
       
    94                         shared_fs_list.append(fs.name)
       
    95 
       
    96             # Initialize BE with the specified in_be filesystems.
       
    97             for be in be_list:
       
    98                 be.init(self.dry_run, self.pool_dataset, nested_be=True,
       
    99                         fs_list=be_fs_list, fs_zfs_properties=None,
       
   100                         shared_fs_list=shared_fs_list,
       
   101                         shared_fs_zfs_properties=None)
       
   102 
       
   103     def execute(self, dry_run=False):
       
   104         """ Primary execution method use by the Checkpoint parent class
       
   105         """
       
   106         self.logger.debug("Executing Target Instantiation Zone")
       
   107         self.dry_run = dry_run
       
   108 
       
   109         self.parse_doc()
       
   110 
       
   111         # set up logical devices (BE and filesystems)
       
   112         if self.logical_list:
       
   113             self.create_logicals()