author | Ethan Quach <Ethan.Quach@sun.com> |
Tue, 31 May 2011 14:21:09 -0700 | |
changeset 1160 | 6f7e708c38ec |
parent 1116 | 29e34d65ceef |
child 1221 | 31c6d2de5731 |
permissions | -rw-r--r-- |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
1 |
# |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
2 |
# CDDL HEADER START |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
3 |
# |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
4 |
# The contents of this file are subject to the terms of the |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
5 |
# Common Development and Distribution License (the "License"). |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
6 |
# You may not use this file except in compliance with the License. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
7 |
# |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
8 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
9 |
# or http://www.opensolaris.org/os/licensing. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
10 |
# See the License for the specific language governing permissions |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
11 |
# and limitations under the License. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
12 |
# |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
13 |
# When distributing Covered Code, include this CDDL HEADER in each |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
14 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
15 |
# If applicable, add the following below this CDDL HEADER, with the |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
16 |
# fields enclosed by brackets "[]" replaced with your own identifying |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
17 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
18 |
# |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
19 |
# CDDL HEADER END |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
20 |
# |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
21 |
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
22 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
23 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
24 |
Contains routines and definitions for any script involving profiles |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
25 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
26 |
import os |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
27 |
import sys |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
28 |
from string import Template |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
29 |
import tempfile |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
30 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
31 |
import osol_install.auto_install.AI_database as AIdb |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
32 |
import osol_install.auto_install.verifyXML as verifyXML |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
33 |
from osol_install.auto_install.installadm_common import _ |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
34 |
from solaris_install import Popen |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
35 |
|
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
36 |
INTERNAL_PROFILE_DIRECTORY = '/var/ai/profile' # work directory for profiles |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
37 |
AI_MANIFEST_ATTACHMENT_NAME = 'manifest.xml' # MIME attachment manifest name |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
38 |
WEBSERVD_UID = 80 # user ID of webserver daemon |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
39 |
WEBSERVD_GID = 80 # group ID of webserver daemon |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
40 |
TEMPLATE_VARIABLES = [ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
41 |
'AI_ARCH', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
42 |
'AI_CID', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
43 |
'AI_CPU', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
44 |
'AI_HOSTNAME', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
45 |
'AI_IPV4', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
46 |
'AI_MAC', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
47 |
'AI_MEM', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
48 |
'AI_NETWORK', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
49 |
'AI_PLATFORM', |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
50 |
'AI_SERVICE' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
51 |
] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
52 |
|
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
53 |
|
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
54 |
class AICriteriaTemplate(Template): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
55 |
''' Derived class for Python Template class, which provides template string |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
56 |
substitiution based on a dictionary. The format is: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
57 |
{{ <token> }} |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
58 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
59 |
delimiter = '{{' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
60 |
pattern = r''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
61 |
\{\{(?: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
62 |
(?P<escaped>\{\{)| |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
63 |
(?P<named>[_a-z][_a-z0-9]*)\}\}| |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
64 |
(?P<braced>[_a-z][_a-z0-9]*)\}\}| |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
65 |
(?P<invalid>) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
66 |
) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
67 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
68 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
69 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
70 |
def perform_templating(profile_str, validate_only=True): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
71 |
''' Given profile string, do all template substitutions for any criteria |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
72 |
found in the process environment |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
73 |
Args: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
74 |
profile_str - profile in a string |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
75 |
validate_only - boolean, set to True if doing validation only - |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
76 |
for cases where the client criteria is not available |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
77 |
If validate_only, do not generate exceptions for criteria missing |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
78 |
from environment |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
79 |
Returns: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
80 |
profile string with any templating substitution performed |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
81 |
Exceptions: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
82 |
KeyError when template variable missing when it is |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
83 |
absolutely needed; e.g. install time, installadm for static profile |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
84 |
ValueError when environment variable format is invalid |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
85 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
86 |
template_dict = dict() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
87 |
# look for all supported criteria in process environment |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
88 |
for replacement_tag in TEMPLATE_VARIABLES: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
89 |
if replacement_tag in os.environ: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
90 |
val = os.environ[replacement_tag] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
91 |
if replacement_tag == 'AI_MAC': |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
92 |
try: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
93 |
val = verifyXML.checkMAC(val).upper() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
94 |
except ValueError: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
95 |
print >> sys.stderr, _( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
96 |
"Warning: MAC address in enviroment is invalid " |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
97 |
"and will be ignored.") |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
98 |
continue |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
99 |
elif replacement_tag == 'AI_NETWORK' or \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
100 |
replacement_tag == 'AI_IPV4': |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
101 |
try: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
102 |
val = verifyXML.checkIPv4(val) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
103 |
except ValueError: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
104 |
print >> sys.stderr, _( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
105 |
"Warning: IP or network address in enviroment is " |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
106 |
"invalid and will be ignored.") |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
107 |
continue |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
108 |
template_dict[replacement_tag] = val |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
109 |
# if the MAC address is defined, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
110 |
# and the client ID not already defined in the environment, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
111 |
# then derive client ID from the MAC address |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
112 |
if replacement_tag == 'AI_MAC' and ('AI_CID' not in os.environ or |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
113 |
os.environ['AI_CID'] is None): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
114 |
client_mac_parts = val.split(":") |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
115 |
template_dict['AI_CID'] = "01%s%s%s%s%s%s" % \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
116 |
(client_mac_parts[0].zfill(2).lower(), |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
117 |
client_mac_parts[1].zfill(2).lower(), |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
118 |
client_mac_parts[2].zfill(2).lower(), |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
119 |
client_mac_parts[3].zfill(2).lower(), |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
120 |
client_mac_parts[4].zfill(2).lower(), |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
121 |
client_mac_parts[5].zfill(2).lower()) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
122 |
# instantiate our template object derived from string Template class |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
123 |
tmpl = AICriteriaTemplate(profile_str) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
124 |
if validate_only: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
125 |
# do not insist on all criteria being present in environment |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
126 |
profile_out = tmpl.safe_substitute(template_dict) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
127 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
128 |
# if template variable not in dict - exception KeyError |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
129 |
profile_out = tmpl.substitute(template_dict) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
130 |
return profile_out # profile string with substitutions |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
131 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
132 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
133 |
def sql_values_from_criteria(criteria, queue, table, gbl=False): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
134 |
''' Given a criteria dictionary, for the indicated DB table |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
135 |
and queue, return a tuple composed of lists whose elements can be used |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
136 |
to construct SQLite clauses. If gbl is true, build a clause that |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
137 |
will affect all database records if criteria is missing - a global effect. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
138 |
Args: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
139 |
criteria - criteria dictionary |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
140 |
queue - database queue |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
141 |
table - database table |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
142 |
gbl - if True, global |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
143 |
Returns: a tuple for SQLite clauses respectively: WHERE, INTO, VALUES |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
144 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
145 |
where = list() # for WHERE clause |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
146 |
intol = list() # for INTO clause |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
147 |
vals = list() # for VALUES clause |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
148 |
for crit in AIdb.getCriteria(queue, table, onlyUsed=False, strip=True): |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
149 |
|
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
150 |
# Determine if this crit is a range criteria or not. |
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
151 |
is_range_crit = AIdb.isRangeCriteria(queue, crit, table) |
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
152 |
|
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
153 |
# Get the value from the manifest |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
154 |
values = criteria[crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
155 |
# the critera manifest didn't specify this criteria |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
156 |
if values is None: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
157 |
# if the criteria we're processing is a range criteria, fill in |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
158 |
# NULL for two columns, MINcrit and MAXcrit |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
159 |
vals += ["NULL"] |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
160 |
if is_range_crit: |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
161 |
where += ["MIN" + crit + " IS NULL"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
162 |
where += ["MAX" + crit + " IS NULL"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
163 |
intol += ["MIN" + crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
164 |
intol += ["MAX" + crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
165 |
vals += ["NULL"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
166 |
# this is a single value |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
167 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
168 |
where += [crit + " IS NULL"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
169 |
intol += [crit] |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
170 |
# This is a value criteria (not a range). 'values' is a list |
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
171 |
# with one or more items. |
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
172 |
elif not is_range_crit: |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
173 |
intol += [crit] |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
174 |
val = AIdb.format_value(crit, " ".join(values)) |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
175 |
where += [crit + "=" + val] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
176 |
vals += [val] |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
177 |
# Else this is a range criteria. 'values' is a two-item list |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
178 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
179 |
# Set the MIN column for this range criteria |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
180 |
if values[0] == 'unbounded': |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
181 |
if not gbl: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
182 |
where += ["MIN" + crit + " IS NULL"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
183 |
intol += ["MIN" + crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
184 |
vals += ['NULL'] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
185 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
186 |
intol += ["MIN" + crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
187 |
if crit == 'mac': |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
188 |
val = AIdb.format_value(crit, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
189 |
verifyXML.checkMAC(values[0])).upper() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
190 |
where += ["HEX(MIN" + crit + ")<=HEX(" + val + ")"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
191 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
192 |
val = AIdb.format_value(crit, values[0]).lower() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
193 |
where += ["MIN" + crit + "<=" + val] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
194 |
vals += [val] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
195 |
# Set the MAX column for this range criteria |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
196 |
if values[1] == 'unbounded': |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
197 |
if not gbl: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
198 |
where += ["MAX" + crit + " IS NULL"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
199 |
intol += ["MAX" + crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
200 |
vals += ['NULL'] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
201 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
202 |
intol += ["MAX" + crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
203 |
if crit == 'mac': |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
204 |
val = AIdb.format_value(crit, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
205 |
verifyXML.checkMAC(values[1])).upper() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
206 |
where += ["HEX(MAX" + crit + ")>=HEX(" + val + ")"] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
207 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
208 |
val = AIdb.format_value(crit, values[1]).lower() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
209 |
where += ["MAX" + crit + ">=" + val] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
210 |
vals += [val] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
211 |
return where, intol, vals |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
212 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
213 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
214 |
def is_name_in_table(name, queue, table): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
215 |
''' Determine if profile already registered for service and same basename |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
216 |
Args: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
217 |
name - profile name |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
218 |
queue - database queue for profiles |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
219 |
table - profile table name |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
220 |
Returns True if any records are found, False if no records found |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
221 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
222 |
query_str = "SELECT * FROM %s WHERE name='%s'" % \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
223 |
(table, AIdb.sanitizeSQL(name)) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
224 |
query = AIdb.DBrequest(query_str) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
225 |
queue.put(query) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
226 |
query.waitAns() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
227 |
return len(query.getResponse()) > 0 |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
228 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
229 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
230 |
def get_columns(queue, table): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
231 |
''' From database queue and table, get database columns |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
232 |
Returns database columns as list |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
233 |
Args: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
234 |
queue - database queue object |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
235 |
table - database table name |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
236 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
237 |
query = AIdb.DBrequest("PRAGMA table_info(" + table + ")") |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
238 |
queue.put(query) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
239 |
query.waitAns() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
240 |
columns = list() |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
241 |
# build a query so we can determine which columns (criteria) are in use |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
242 |
# using the output from the PRAGMA statement |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
243 |
for col in iter(query.getResponse()): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
244 |
columns += [col['name']] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
245 |
return columns |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
246 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
247 |
|
1116
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
248 |
def validate_profile_string(profile_str, image_dir=None, resolve_entities=True, |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
249 |
dtd_validation=False, warn_if_dtd_missing=False): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
250 |
''' Given the profile contained in a string variable, validate |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
251 |
Args: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
252 |
profile_str - profile in string format |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
253 |
image_dir - path of service image, used to locate service_bundle |
1116
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
254 |
if None, only unit test against local service_bundle(4) |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
255 |
resolve_entities - if True, ask XML parser to resolve all entities |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
256 |
dtd_validation - if True, validate against a DTD in the profile |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
257 |
warn_if_dtd_missing - if True, raise an exception if the DTD not found |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
258 |
Returns: profile as string with any inclusions |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
259 |
Exceptions: etree.XMLSyntaxError |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
260 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
261 |
import lxml.etree as etree |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
262 |
from StringIO import StringIO |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
263 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
264 |
# create an XMLParser object with settings |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
265 |
parser = etree.XMLParser( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
266 |
# always read DTD for XInclude namespace xi in service_bundle(4) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
267 |
load_dtd=True, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
268 |
resolve_entities=resolve_entities, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
269 |
dtd_validation=False |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
270 |
) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
271 |
root = etree.parse(StringIO(profile_str), parser) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
272 |
if not resolve_entities: # just check basic XML, no inclusions |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
273 |
return profile_str |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
274 |
# validate against DTD if provided |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
275 |
if dtd_validation and \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
276 |
(root.docinfo.externalDTD is not None or |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
277 |
root.docinfo.internalDTD is not None): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
278 |
# check for service_bundle(4) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
279 |
if root.docinfo.system_url is not None and \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
280 |
root.docinfo.system_url.find('/service_bundle.dtd.') == -1: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
281 |
print >> sys.stderr, _( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
282 |
"Warning: DOCTYPE %s specified instead of service_bundle(4). " |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
283 |
"The file might not be a profile.") % root.docinfo.system_url |
1116
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
284 |
if image_dir is None: # unit testing only |
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
285 |
err = validate_profile_external_dtd(profile_str) |
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
286 |
if err: |
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
287 |
raise etree.XMLSyntaxError(err, '', '', '') |
29e34d65ceef
7040960 Missing usr/src/cmd/ai-webserver/export_profile.py in slim_source cause slim unit test failure.
William Schumann <william.schumann@sun.com>
parents:
1098
diff
changeset
|
288 |
return profile_str |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
289 |
dtd_file = os.path.join(image_dir, 'auto_install', 'service_bundle.dtd.1') |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
290 |
# if warning only on DTD missing, and DTD is indeed missing |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
291 |
if root.docinfo.system_url is not None and warn_if_dtd_missing and \ |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
292 |
not os.path.exists(dtd_file): |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
293 |
print >> sys.stderr, _( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
294 |
"Warning: DTD %s not found. Cannot validate completely.") % \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
295 |
dtd_file |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
296 |
return etree.tostring(root) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
297 |
# parse, validating against external DTD |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
298 |
err = validate_profile_external_dtd(profile_str, dtd_file) |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
299 |
if err: |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
300 |
raise etree.XMLSyntaxError(err, '', '', '') |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
301 |
return profile_str |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
302 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
303 |
|
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
304 |
def validate_criteria_from_user(criteria, dbo, table): |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
305 |
''' Validate profile criteria from dictionary containing command line input |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
306 |
Args: criteria - Criteria object holding the criteria that is to be |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
307 |
added/set for a manifest. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
308 |
dbo - AI_database object for the install service. |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
309 |
table - name of database table |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
310 |
Raises: SystemExit if: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
311 |
- criteria is not found in database |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
312 |
- value is not valid for type (integer and hexadecimal checks) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
313 |
- range is improper |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
314 |
Returns: nothing |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
315 |
''' |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
316 |
# find all possible profile criteria expressed as DB table columns |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
317 |
critlist = AIdb.getCriteria(dbo.getQueue(), table, onlyUsed=False, |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
318 |
strip=False) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
319 |
# verify each range criteria is well formed |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
320 |
for crit in criteria: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
321 |
# gather this criteria's values |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
322 |
man_criterion = criteria[crit] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
323 |
# check "value" criteria here (check the criteria exists in DB |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1116
diff
changeset
|
324 |
if not AIdb.isRangeCriteria(dbo.getQueue(), crit, table): |
1075
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
325 |
# only check criteria in use in the DB |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
326 |
if crit not in critlist: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
327 |
raise SystemExit(_( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
328 |
"Error:\tCriteria %s is not a valid criteria!") % crit) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
329 |
# This is a range criteria. (Check that ranges are valid, that |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
330 |
# "unbounded" gets set to 0/+inf, ensure the criteria exists |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
331 |
# in the DB |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
332 |
else: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
333 |
# check for a properly ordered range (with unbounded being 0 or |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
334 |
# Inf.) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
335 |
if man_criterion[0] != "unbounded" and \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
336 |
man_criterion[1] != "unbounded" and \ |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
337 |
man_criterion[0] > man_criterion[1]: # Check min > max |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
338 |
raise SystemExit(_( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
339 |
"Error:\tCriteria %s is not a valid range (MIN > MAX) ") |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
340 |
% crit) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
341 |
# Clean-up NULL's and changed "unbounded"s to 0 and |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
342 |
# the maximum integer value |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
343 |
# Note "unbounded"s are already converted to lower case during |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
344 |
# input processing |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
345 |
if man_criterion[0] == "unbounded": |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
346 |
man_criterion[0] = "0" |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
347 |
if man_criterion[1] == "unbounded": |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
348 |
man_criterion[1] = str(sys.maxint) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
349 |
if crit == "mac": |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
350 |
# convert hex mac address (w/o colons) to a number |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
351 |
try: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
352 |
man_criterion[0] = long(str(man_criterion[0]).upper(), 16) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
353 |
man_criterion[1] = long(str(man_criterion[1]).upper(), 16) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
354 |
except ValueError: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
355 |
raise SystemExit(_( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
356 |
"Error:\tCriteria %s is not a valid hexadecimal value") |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
357 |
% crit) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
358 |
else: # this is a decimal value |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
359 |
try: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
360 |
man_criterion = [long(str(man_criterion[0]).upper()), |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
361 |
long(str(man_criterion[1]).upper())] |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
362 |
except ValueError: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
363 |
raise SystemExit(_( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
364 |
"Error:\tCriteria %s is not a valid integer value") % |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
365 |
crit) |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
366 |
# check to see that this criteria exists in the database columns |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
367 |
if 'MIN' + crit not in critlist and 'MAX' + crit not in critlist: |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
368 |
raise SystemExit(_( |
df96871c232d
16045 SC manifest should not be required to be in an XML comment when using embedded form
William Schumann <william.schumann@sun.com>
parents:
diff
changeset
|
369 |
"Error:\tCriteria %s is not a valid criteria!") % crit) |
1098
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
370 |
|
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
371 |
|
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
372 |
def validate_profile_external_dtd(prof_str, |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
373 |
dtd='/usr/share/lib/xml/dtd/service_bundle.dtd.1'): |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
374 |
''' Given a profile in string format, a root directory and a DTD name, |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
375 |
validate the profile against the external DTD using svccfg |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
376 |
Args: |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
377 |
prof_str - profile as string |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
378 |
dtd - path to external DTD |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
379 |
Returns: stderr output from 'svccfg apply -n', empty if no error |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
380 |
''' |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
381 |
# specify DTD for external reference by svccfg |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
382 |
os.environ["SVCCFG_DTD"] = dtd |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
383 |
# string must be written to temporary file for svccfg |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
384 |
# non-root user cannot write to /system/volatile |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
385 |
if os.geteuid() == 0: |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
386 |
tmpdir = '/system/volatile' |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
387 |
else: |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
388 |
tmpdir = '/tmp' |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
389 |
prof_fo = tempfile.NamedTemporaryFile(dir=tmpdir, delete=False) |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
390 |
prof_fo.write(prof_str) |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
391 |
profname = prof_fo.name |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
392 |
prof_fo.close() |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
393 |
# validate against DTD using svccfg apply -n |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
394 |
pargs = ['/usr/sbin/svccfg', 'apply', '-n', profname] |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
395 |
# invoke command, save stderr, do not throw exception on failure |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
396 |
cmdpipe = Popen.check_call(pargs, stderr=Popen.STORE, |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
397 |
check_result=Popen.ANY) |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
398 |
os.unlink(profname) |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
399 |
if cmdpipe.returncode == 0: # success |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
400 |
return '' |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
401 |
# validation failure, return stderr |
c70e5a658299
7037229 Got hostname of "unknown" instead of "solaris" if I use the sc_sample.xml to do install
William Schumann <william.schumann@sun.com>
parents:
1075
diff
changeset
|
402 |
return cmdpipe.stderr |