#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
'''
Utility program for helping with the upgrade of puppet to a newer
version. This program will take a puppet configuration file that
has been generated via the command sequence
puppet agent --genconfig > puppet.conf
and use the data in that configuration file to replace the
associated Puppet SMF user configuratable properties with the
properties that are allowed in the new version of puppet
NOTE: This file should not be included with the puppet release
'''
import os
import re
import sys
# SMF defined property types. For a list of
# all available types see
# Dictionary of currently defined property types to associate
# with a specified property. Any property not defined here
# is assumed to have a property type of astring, integer,
# or boolean
PROP_TYPE = {
'server': TYPE_HOST,
'archive_file_server': TYPE_HOST,
'bindaddress': TYPE_NETADDRESS,
'ca_server': TYPE_HOST,
'certname': TYPE_HOSTNAME,
'couchdb_url': TYPE_URI,
'dbserver': TYPE_HOST,
'dns_alt_names': TYPE_HOST,
'http_proxy_host': TYPE_HOST,
'inventory_server': TYPE_HOST,
'ldapserver': TYPE_HOST,
'ldapuser': TYPE_HOSTNAME,
'module_repository': TYPE_URI,
'queue_source': TYPE_URI,
'report_server': TYPE_HOST,
'reporturl': TYPE_URI,
'smtpserver': TYPE_HOST,
'srv_domain': TYPE_HOST,
}
# Dictionary used to hold properites and the resulting xml code
'''Output standard error message'''
# Duplicate the syntax of the parser.error
'''Create a basic xml entry following the basic pattern of
<prop_pattern name='${key}' type='${key_type}'
required='false'>
<description> <loctext xml:lang='C'>
${desc_text}
</loctext> </description>
</prop_pattern>
'''
"prop_pattern",
required="false")
return prop_pattern
'''Determine the xml property type to associate with the
specified key
'''
# Does the key have a specified xml property type
# already defined?
try:
except KeyError:
pass
# Use the value to determine the xml property type
return TYPE_INTEGER
return TYPE_BOOLEAN
return TYPE_ASTRING
'''Process the lines in the list. The last entry should be
a 'key=value' entry
'''
# The last field should be a key = value pair
# If it's not then the format of the file is not matching
# the expected format of
#
# Description
# The default value is "xxxx"
# key = value
#
if not match:
raise TypeError("Last line in grouping is not in expected "
"format of 'key = value'\n%s" %
# Not a match. Last line was still part of the description
# remaining lines are the descriptor field
'''Parse the puppet configuration file that is generated by
puppet agent --genconfig
'''
parameter_list = []
if agent_check:
# Throw away the initial starting block code in the
del parameter_list[:]
continue
if not line:
# If parameter_list is not empty, process the data and
# generate an xml structure
# Done processing, delete all the saved entries
del parameter_list[:]
continue
if match:
'''Replace the puppet property definitions in the specified SMF
file with those that are stored in PUPPET_CONFIG_DICT
'''
try:
return -1
return -1
# Delete the pg_pattern nodes and it's children
# This is the structure that will be rebuilt based
# on the genconfig information that was read in
if pg_pattern is not None:
# <pg_pattern name='config' type='application' required='false'>
"pg_pattern",
name="config",
type="application",
required="false")
# Write out the contents of the updated puppet SMF config file
print "Writting out contents of new SMF configuration file to: %s" % \
def option_list():
'''Build the option list for this utility'''
desc = "Utility for assisting in the upgrading of Solaris Puppet SMF file"
usage = "usage: %prog -c <puppet_config_file> -s <smf_confilg_file> " \
"-v <puppet_version> [-o <output_file>]\n"
metavar="<puppet_config_file>",
help="Puppet configuration file generated via"
"genconfig option to puppet. i.e. "
"puppet agent --genconfig > puppet.conf")
metavar="<smf_config_file>",
help="Current solaris Puppet SMF XML configuration"
" file. This file is located in <userland_tree>"
metavar="<output_file>",
help="The name of the new puppet.xml file ")
metavar="<puppet_version>",
help="Puppet Version of update")
return opt_list
def main():
'''Execute this utility based on the options supplied by the user'''
parser = option_list()
err("Required options not specified")
err("%s does not exist or is not a regular file\n"
err("%s does not exist or is not a regular file\n"
err("specified file %s already exist\n"
if __name__ == '__main__':
main()