components/ruby/puppet/files/update_smf.py
author John Beck <John.Beck@Oracle.COM>
Tue, 10 Feb 2015 14:10:51 -0800
branchs11-update
changeset 3979 46744fa00de4
parent 3458 4912663e9858
permissions -rw-r--r--
20440888 Userland python tools should migrate to 2.7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3979
46744fa00de4 20440888 Userland python tools should migrate to 2.7
John Beck <John.Beck@Oracle.COM>
parents: 3458
diff changeset
     1
#!/usr/bin/python2.7
3458
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     2
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     3
# CDDL HEADER START
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     4
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     8
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    12
# and limitations under the License.
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    13
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    19
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    20
# CDDL HEADER END
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    21
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    22
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    23
#
3979
46744fa00de4 20440888 Userland python tools should migrate to 2.7
John Beck <John.Beck@Oracle.COM>
parents: 3458
diff changeset
    24
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
3458
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    25
#
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    26
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    27
'''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    28
Utility program for helping with the upgrade of puppet to a newer
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    29
version.  This program will take a puppet configuration file that
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    30
has been generated via the command sequence
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    31
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    32
puppet agent --genconfig > puppet.conf
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    33
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    34
and use the data in that configuration file to replace the
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    35
associated Puppet SMF user configuratable properties with the
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    36
properties that are allowed in the new version of puppet
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    37
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    38
NOTE: This file should not be included with the puppet release
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    39
'''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    40
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    41
import os
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    42
import re
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    43
import sys
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    44
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    45
from lxml import etree
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    46
from optparse import OptionParser
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    47
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    48
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    49
COMMENT_PATTERN = re.compile(".*# ?(.*)")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    50
CONFIG_VALUE_PATTERN = re.compile("([\S]+)\s*=\s*(\S*)")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    51
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    52
DEFAULT_VALUE_STR = "The default value is "
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    53
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    54
# SMF defined property types.  For a list of
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    55
# all available types see
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    56
# /usr/share/lib/xml/dtd/service_bundle.dtd.1
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    57
TYPE_ASTRING = "astring"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    58
TYPE_BOOLEAN = "boolean"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    59
TYPE_INTEGER = "integer"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    60
TYPE_HOST = "host"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    61
TYPE_HOSTNAME = "hostname"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    62
TYPE_NETADDRESS = "net_address"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    63
TYPE_URI = "uri"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    64
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    65
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    66
# Dictionary of currently defined property types to associate
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    67
# with a specified property.  Any property not defined here
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    68
# is assumed to have a property type of astring, integer,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    69
# or boolean
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    70
PROP_TYPE = {
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    71
    'server': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    72
    'archive_file_server': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    73
    'bindaddress': TYPE_NETADDRESS,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    74
    'ca_server': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    75
    'certname': TYPE_HOSTNAME,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    76
    'couchdb_url': TYPE_URI,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    77
    'dbserver': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    78
    'dns_alt_names': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    79
    'http_proxy_host': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    80
    'inventory_server': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    81
    'ldapserver': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    82
    'ldapuser': TYPE_HOSTNAME,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    83
    'module_repository': TYPE_URI,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    84
    'queue_source': TYPE_URI,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    85
    'report_server': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    86
    'reporturl': TYPE_URI,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    87
    'smtpserver': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    88
    'srv_domain': TYPE_HOST,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    89
}
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    90
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    91
# Dictionary used to hold properites and the resulting xml code
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    92
PUPPET_CONFIG_DICT = dict()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    93
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    94
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    95
def err(msg):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    96
    '''Output standard error message'''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    97
    # Duplicate the syntax of the parser.error
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    98
    sys.stderr.write("%(prog)s: error: %(msg)s\n" %
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
    99
                     {"prog": os.path.basename(sys.argv[0]), "msg": msg})
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   100
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   101
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   102
def create_config_element(key, key_type, desc_text):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   103
    '''Create a basic xml entry following the basic pattern of
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   104
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   105
        <prop_pattern name='${key}' type='${key_type}'
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   106
                required='false'>
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   107
                    <description> <loctext xml:lang='C'>
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   108
                         ${desc_text}
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   109
                    </loctext> </description>
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   110
        </prop_pattern>
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   111
    '''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   112
    prop_pattern = etree.Element(
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   113
        "prop_pattern",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   114
        name=key,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   115
        type=key_type,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   116
        required="false")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   117
    desc = etree.SubElement(prop_pattern, "description")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   118
    loctext = etree.SubElement(desc, "loctext")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   119
    loctext.text = "\n%s\n\t    " % desc_text
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   120
    loctext.set('{http://www.w3.org/XML/1998/namespace}lang', 'C')
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   121
    return prop_pattern
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   122
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   123
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   124
def determine_type(key, value):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   125
    '''Determine the xml property type to associate with the
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   126
       specified key
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   127
    '''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   128
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   129
    # Does the key have a specified xml property type
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   130
    # already defined?
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   131
    try:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   132
        return PROP_TYPE[key]
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   133
    except KeyError:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   134
        pass
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   135
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   136
    # Use the value to determine the xml property type
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   137
    if value.isdigit():
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   138
        return TYPE_INTEGER
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   139
    if value.lower() in ['false', 'true']:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   140
        return TYPE_BOOLEAN
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   141
    return TYPE_ASTRING
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   142
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   143
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   144
def process_grouping(lines):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   145
    '''Process the lines in the list.  The last entry should be
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   146
       a 'key=value' entry
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   147
    '''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   148
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   149
    # The last field should be a key = value pair
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   150
    # If it's not then the format of the file is not matching
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   151
    # the expected format of
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   152
    #
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   153
    # Description
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   154
    # The default value is "xxxx"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   155
    # key = value
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   156
    #
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   157
    key_value = lines.pop()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   158
    match = CONFIG_VALUE_PATTERN.match(key_value)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   159
    if not match:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   160
        raise TypeError("Last line in grouping is not in expected "
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   161
                        "format of 'key = value'\n%s" %
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   162
                        "\n".join(lines))
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   163
    key = match.group(1)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   164
    value = match.group(2)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   165
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   166
    default_value_line = lines.pop()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   167
    if not default_value_line.startswith(DEFAULT_VALUE_STR):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   168
        # Not a match.  Last line was still part of the description
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   169
        lines.append(default_value_line)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   170
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   171
    key_type = determine_type(key, value)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   172
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   173
    # remaining lines are the descriptor field
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   174
    desc = '\n'.join(lines)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   175
    PUPPET_CONFIG_DICT[key] = (key, key_type, desc)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   176
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   177
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   178
def parse_puppet_config(filename):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   179
    '''Parse the puppet configuration file that is generated by
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   180
       puppet agent --genconfig
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   181
    '''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   182
    parameter_list = []
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   183
    agent_check = True
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   184
    with open(filename, 'r') as f_handle:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   185
        for line in f_handle:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   186
            if agent_check:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   187
                if line.startswith("[agent]"):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   188
                    # Throw away the initial starting block code in the
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   189
                    del parameter_list[:]
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   190
                    agent_check = False
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   191
                    continue
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   192
            line = line.strip().replace("\n", "")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   193
            if not line:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   194
                # If parameter_list is not empty, process the data and
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   195
                # generate an xml structure
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   196
                process_grouping(parameter_list)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   197
                # Done processing, delete all the saved entries
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   198
                del parameter_list[:]
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   199
                continue
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   200
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   201
            match = COMMENT_PATTERN.match(line)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   202
            if match:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   203
                line = match.group(1)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   204
            parameter_list.append(line)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   205
    f_handle.close()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   206
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   207
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   208
def update_smf_file(smf_xml_file, output_file, version):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   209
    '''Replace the puppet property definitions in the specified SMF
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   210
       file with those that are stored in PUPPET_CONFIG_DICT
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   211
    '''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   212
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   213
    try:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   214
        parser = etree.XMLParser(remove_blank_text=True)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   215
        tree = etree.parse(smf_xml_file, parser)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   216
        root = tree.getroot()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   217
        template = root.find("service/template")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   218
        puppet_desc = template.find("common_name/loctext")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   219
        puppet_desc.text = "Puppet version %s" % version
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   220
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   221
        pg_pattern = template.find("pg_pattern")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   222
    except IOError as msg:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   223
        err(msg)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   224
        return -1
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   225
    except etree.XMLSyntaxError as msg:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   226
        err(msg)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   227
        return -1
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   228
    except NameError as msg:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   229
        err("XML file %s does not match expected formated" % smf_xml_file)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   230
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   231
    # Delete the pg_pattern nodes and it's children
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   232
    # This is the structure that will be rebuilt based
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   233
    # on the genconfig information that was read in
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   234
    if pg_pattern is not None:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   235
        template.remove(pg_pattern)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   236
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   237
    # <pg_pattern name='config' type='application' required='false'>
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   238
    pg_pattern = etree.SubElement(
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   239
        template,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   240
        "pg_pattern",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   241
        name="config",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   242
        type="application",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   243
        required="false")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   244
    for key in sorted(PUPPET_CONFIG_DICT.iterkeys()):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   245
        values = PUPPET_CONFIG_DICT[key]
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   246
        element = create_config_element(values[0], values[1], values[2])
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   247
        pg_pattern.append(element)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   248
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   249
    # Write out the contents of the updated puppet SMF config file
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   250
    print "Writting out contents of new SMF configuration file to: %s" % \
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   251
        output_file
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   252
    with open(output_file, "w") as f_handle:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   253
        f_handle.write(etree.tostring(tree, pretty_print=True))
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   254
    f_handle.close()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   255
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   256
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   257
def option_list():
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   258
    '''Build the option list for this utility'''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   259
    desc = "Utility for assisting in the upgrading of Solaris Puppet SMF file"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   260
    usage = "usage: %prog -c <puppet_config_file> -s <smf_confilg_file> " \
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   261
            "-v <puppet_version> [-o <output_file>]\n"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   262
    opt_list = OptionParser(description=desc, usage=usage)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   263
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   264
    opt_list.add_option("-c", "--config", dest="config", default=None,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   265
                        action="store", type="string", nargs=1,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   266
                        metavar="<puppet_config_file>",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   267
                        help="Puppet configuration file generated via"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   268
                             "genconfig option to puppet. i.e. "
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   269
                             "puppet agent --genconfig > puppet.conf")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   270
    opt_list.add_option("-s", "--smf", dest="smf_xml", default=None,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   271
                        action="store", type="string", nargs=1,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   272
                        metavar="<smf_config_file>",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   273
                        help="Current solaris Puppet SMF XML configuration"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   274
                             " file. This file is located in <userland_tree>"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   275
                             "/components/puppet/files/puppet.xml")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   276
    opt_list.add_option("-o", "--output", dest="output", default=None,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   277
                        action="store", type="string", nargs=1,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   278
                        metavar="<output_file>",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   279
                        help="The name of the new puppet.xml file ")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   280
    opt_list.add_option("-v", "--version", dest="version", default="None",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   281
                        action="store", type="string", nargs=1,
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   282
                        metavar="<puppet_version>",
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   283
                        help="Puppet Version of update")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   284
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   285
    return opt_list
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   286
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   287
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   288
def main():
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   289
    '''Execute this utility based on the options supplied by the user'''
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   290
    parser = option_list()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   291
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   292
    (options, _args) = parser.parse_args()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   293
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   294
    if not options.output and options.version:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   295
        options.output = "puppet.%s.xml" % options.version
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   296
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   297
    if not options.config or not options.smf_xml or \
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   298
            not options.output or not options.version:
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   299
        err("Required options not specified")
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   300
        parser.print_help()
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   301
        sys.exit(-1)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   302
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   303
    if not os.path.isfile(options.config):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   304
        err("%s does not exist or is not a regular file\n"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   305
            % options.config)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   306
        sys.exit(-1)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   307
    if not os.path.isfile(options.smf_xml):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   308
        err("%s does not exist or is not a regular file\n"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   309
            % options.smf_xml)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   310
        sys.exit(-1)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   311
    if os.path.exists(options.output):
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   312
        err("specified file %s already exist\n"
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   313
            % options.output)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   314
        sys.exit(-1)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   315
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   316
    parse_puppet_config(options.config)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   317
    update_smf_file(options.smf_xml, options.output, options.version)
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   318
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   319
if __name__ == '__main__':
4912663e9858 18960221 problem in UTILITY/PUPPET
Kristina Tripp <Kristina.Tripp@oracle.com>
parents:
diff changeset
   320
    main()