1
2 """
3 This library helps in creating common classes and links
4 """
5
6 import logger
7 import netutils
8 import re
9 import string
10
11 from appilog.common.system.defines import AppilogTypes
12 from appilog.common.system.types import AttributeStateHolder, ObjectStateHolder
13 from appilog.common.system.types.vectors import ObjectStateHolderVector, StringVector
14 from appilog.common.utils.zip import ChecksumZipper
15 from appilog.common.utils import IPv4
16
17 from com.hp.ucmdb.discovery.common import CollectorsConstants
18 from com.hp.ucmdb.discovery.library.communication.downloader import ConfigFilesManagerImpl
19 from com.hp.ucmdb.discovery.library.communication.downloader.cfgfiles import GeneralSettingsConfigFile
20 from com.hp.ucmdb.discovery.library.communication.downloader.cfgfiles import PortInfo
21 from com.hp.ucmdb.discovery.library.scope import DomainScopeManager
22 from com.hp.ucmdb.discovery.library.clients import ClientsConsts
23 from com.hp.ucmdb.discovery.library.clients import ScriptsExecutionManager
24 from com.mercury.topaz.cmdb.shared.model.object.id import CmdbObjectID
25
26 from java.lang import String
27 from java.text import ParseException, SimpleDateFormat
28 from java.util import Date, Locale, SimpleTimeZone
29 from java.util.regex import Pattern
30
31
32 SERVICEADDRESS_TYPE_TCP = 1
33 SERVICEADDRESS_TYPE_UDP = 2
34 SERVICEADDRESS_TYPE_URL = 3
35
36
37 FIXED_DISK_STORAGE_TYPE = 'FixedDisk'
38 NETWORK_DISK_STORAGE_TYPE = 'NetworkDisk'
39 COMPACT_DISK_STORAGE_TYPE = 'CompactDisk'
40 REMOVABLE_DISK_STORAGE_TYPE = 'RemovableDisk'
41 FLOPPY_DISK_STORAGE_TYPE = 'FloppyDisk'
42 VIRTUAL_MEMORY_STORAGE_TYPE = 'VirtualMemory'
43 FLASH_MEMORY_STORAGE_TYPE = 'FlashMemory'
44 RAM_DISK_STORAGE_TYPE = 'RamDisk'
45 RAM_STORAGE_TYPE = 'Ram'
46 NO_ROOT_DIRECTORY_STORAGE_TYPE = 'No Root Directory'
47 OTHER_STORAGE_TYPE = 'Other'
48 UNKNOWN_STORAGE_TYPE = "UNKNOWN"
49 IGNORE_INTERFACE_PATTERN_FILTER = ['LoopBack', 'Wireless', 'Virtual', 'WAN',
50 'RAS Async', 'Bluetooth', 'FireWire', 'VPN',
51 'Tunnel adapter', 'Tunneling Pseudo',
52 'Hamachi', '1394', 'Miniport', 'TAP\-Win32',
53 'Teefer2', 'PPP\/SLIP']
54 IP_ADDRESS_PROPERTY_LOOPBACK = 'loopback'
55 IP_ADDRESS_PROPERTY_DHCP = 'dhcp'
56 IP_ADDRESS_PROPERTY_BROADCAST = 'broadcast'
57 IP_ADDRESS_PROPERTY_ANYCAST = 'anycast'
58
59 MIME_TEXT_PLAIN = "text/plain"
60 MIME_TEXT_XML = "text/xml"
61
62 OS_TYPE_AND_CLASS_TO_OS_FAMILY_MAP = {
63 'linux': 'unix',
64 'sunos': 'unix',
65 'freebsd': 'unix',
66 'aix': 'unix',
67 'unix': 'unix',
68 'nt': 'windows',
69 'windows': 'windows',
70 'vax': 'vax',
71 'hp-ux': 'unix',
72 'vmware_esx_server': 'baremetal_hypervisor',
73 'vmkernel': 'baremetal_hypervisor',
74 'ipar': 'mainframe',
75 'lpar': 'mainframe',
76 'mainframe': 'mainframe'
77 }
78
79 databaseDataNames = {
80 'oracle': 'Oracle DB',
81 'sqlserver': 'MSSQL DB',
82 'db2': 'IBM DB2',
83 'sybase': 'Sybase DB',
84 'maxdb': 'SAP MaxDB',
85 'hana_database': 'SAP HanaDB',
86 'mysql': 'MySQL DB'
87 }
88
89 STORAGE_ID_TO_STORAGE_TYPE = {
90 0: OTHER_STORAGE_TYPE,
91 1: NO_ROOT_DIRECTORY_STORAGE_TYPE,
92 2: REMOVABLE_DISK_STORAGE_TYPE,
93 3: FIXED_DISK_STORAGE_TYPE,
94 4: NETWORK_DISK_STORAGE_TYPE,
95 5: COMPACT_DISK_STORAGE_TYPE,
96 6: RAM_STORAGE_TYPE}
97
98 applicationNameToProductNameMap = {
99
100 'Oracle DB': 'oracle_database',
101 'SAP MaxDB': 'maxdb',
102 'SAP HanaDB': 'hana_database',
103 'MSSQL DB': 'sql_server_database',
104 'IBM DB2': 'db2_database',
105 'Sybase DB': 'sybase_database',
106 'MySQL DB': 'mysql_database',
107
108 'JBoss AS': 'jboss_application_server',
109 'Oracle iAS': 'oraclei_application_server',
110 'WebLogic AS': 'weblogic_application_server',
111 'WebSphere AS': 'websphere_application_server',
112 'Glassfish AS': 'glassfish_application_server',
113 'Jetty WebServer': 'jetty_application_server',
114
115 'Microsoft IIS WebServer': 'iis_web_server',
116 'Apache WebServer': 'apache_web_server',
117 'Apache Tomcat': 'tomcat_web_server',
118
119 'Microsoft Cluster SW': 'microsoft_cluster',
120 'HP Service Guard Cluster SW': 'service_guard_cluster',
121 'Veritas Cluster SW': 'veritas_cluster',
122
123 'SAP ABAP Central Services': 'abap_sap_central_services',
124 'SAP ABAP Application Server': 'sap_abap_application_server',
125 'SAP J2EE Central Services': 'j2ee_sap_central_services',
126 'SAP J2EE Application Server': 'sap_j2ee_application_server',
127 'SAP ITS Manager': 'sap_its_agate',
128
129 'Siebel Server': 'siebel_application_server',
130 'Siebel Gateway Name Server': 'siebel_gateway',
131
132 'Virtualization Layer Software': 'vmware_hypervisor',
133 'VMware VirtualCenter': 'vmware_virtual_center',
134 'Microsoft Hyper-V Hypervisor': 'microsoft_hypervisor',
135 'IBM HMC': 'ibm_hardware_management_console',
136
137 'Microsoft Exchange Server': 'microsoft_exchange_server',
138 'IBM WebSphere MQ': 'ibm_websphere_mq',
139 'Active Directory Application Mode': 'active_directory_application_mode',
140 'Citrix': 'citrix_xenapp_server',
141 'DomainController': 'domain_controller'}
142
143 applicationTypeToDiscoveredProductNameMap = {
144
145 'abap_sap_central_services': 'SAP ABAP Central Services',
146 'j2ee_sap_central_services': 'SAP J2EE Central Services',
147 'sap_r3_server': 'SAP ABAP Application Server',
148 'sap_j2ee_app_server': 'SAP J2EE Application Server',
149
150 'siebel_app_server': 'Siebel Server',
151 'siebel_gateway': 'Siebel Gateway Name Server'
152 }
153
154 CLASSES_80_TO_BDM = {'host': 'node',
155 'clusteredservice': 'cluster_resource_group',
156 'clustergroup': 'cluster_resource_group_config',
157 'clusterresource': 'cluster_resource_config',
158 'hostresource': 'node_element',
159 'service': 'windows_service',
160 'logicalvolume': 'logical_volume',
161 'disk': 'file_system',
162 'software': 'installed_software',
163 'ipserver': 'ip_service_endpoint',
164 'url': 'uri_endpoint',
165 'application': 'running_software',
166 'failoverclustersoftware': 'cluster_software',
167 'dnsserver': 'dns_server',
168 'webserver': 'web_server',
169 'networkresource': 'network_entity',
170 'network': 'ip_subnet',
171 'ip': 'ip_address',
172 'applicationsystem': 'application_system',
173 'document': 'configuration_document',
174 'configfile': 'configuration_document',
175 'failovercluster': 'failover_cluster',
176 'port': 'physical_port',
177 'networkshare': 'file_system_export',
178 'business': 'business_element',
179 'logical_service': 'service',
180 'business_service_for_catalog': 'business_service',
181 'logical_application': 'business_application',
182 'business_unit': 'organization',
183 'line_of_business': 'business_function',
184 'member': 'membership',
185 'depend': 'dependency',
186 'clientserver': 'client_server',
187 'depends_on': 'usage',
188 'use': 'usage',
189 'run': 'execution_environment',
190 'owner': 'ownership',
191 'potentially_run': 'ownership'}
192
193 MIME_TYPES = {'3dm': 'x-world/x-3dmf',
194 '3dmf': 'x-world/x-3dmf',
195 'a': 'application/octet-stream',
196 'aab': 'application/x-authorware-bin',
197 'aam': 'application/x-authorware-map',
198 'aas': 'application/x-authorware-seg',
199 'abc': 'text/vnd.abc',
200 'acgi': 'text/html',
201 'afl': 'video/animaflex',
202 'ai': 'application/postscript',
203 'aif': 'audio/x-aiff',
204 'aifc': 'audio/x-aiff',
205 'aiff': 'audio/x-aiff',
206 'aim': 'application/x-aim',
207 'aip': 'text/x-audiosoft-intra',
208 'ani': 'application/x-navi-animation',
209 'aps': 'application/mime',
210 'arc': 'application/octet-stream',
211 'arj': 'application/octet-stream',
212 'art': 'image/x-jg',
213 'asf': 'video/x-ms-asf',
214 'asm': 'text/x-asm',
215 'asp': 'text/asp',
216 'asx': 'video/x-ms-asf',
217 'au': 'audio/x-au',
218 'avi': 'video/avi',
219 'avs': 'video/avs-video',
220 'bcpio': 'application/x-bcpio',
221 'bin': 'application/octet-stream',
222 'bm': 'image/bmp',
223 'bmp': 'image/bmp',
224 'boo': 'application/book',
225 'book': 'application/book',
226 'boz': 'application/x-bzip2',
227 'bsh': 'application/x-bsh',
228 'bz': 'application/x-bzip',
229 'bz2': 'application/x-bzip2',
230 'c': 'text/plain',
231 'c++': 'text/plain',
232 'cat': 'application/vnd.ms-pki.seccat',
233 'cc': 'text/plain',
234 'ccad': 'application/clariscad',
235 'cco': 'application/x-cocoa',
236 'cdf': 'application/cdf',
237 'cer': 'application/x-x509-ca-cert',
238 'cha': 'application/x-chat',
239 'chat': 'application/x-chat',
240 'class': 'application/java',
241 'com': 'application/octet-stream',
242 'conf': 'text/plain',
243 'cpio': 'application/x-cpio',
244 'cpp': 'text/x-c',
245 'cpt': 'application/x-compactpro',
246 'crl': 'application/pkcs-crl',
247 'crt': 'application/x-x509-ca-cert',
248 'csh': 'text/x-script.csh',
249 'css': 'text/css',
250 'cxx': 'text/plain',
251 'dcr': 'application/x-director',
252 'deepv': 'application/x-deepv',
253 'def': 'text/plain',
254 'der': 'application/x-x509-ca-cert',
255 'dif': 'video/x-dv',
256 'dir': 'application/x-director',
257 'dl': 'video/x-dl',
258 'doc': 'application/msword',
259 'dot': 'application/msword',
260 'dp': 'application/commonground',
261 'drw': 'application/drafting',
262 'dump': 'application/octet-stream',
263 'dv': 'video/x-dv',
264 'dvi': 'application/x-dvi',
265 'dwf': 'model/vnd.dwf',
266 'dwg': 'image/x-dwg',
267 'dxf': 'image/x-dwg',
268 'dxr': 'application/x-director',
269 'el': 'text/x-script.elisp',
270 'elc': 'application/x-elc',
271 'env': 'application/x-envoy',
272 'eps': 'application/postscript',
273 'es': 'application/x-esrehber',
274 'etx': 'text/x-setext',
275 'evy': 'application/x-envoy',
276 'exe': 'application/octet-stream',
277 'f': 'text/plain',
278 'f77': 'text/x-fortran',
279 'f90': 'text/plain',
280 'fdf': 'application/vnd.fdf',
281 'fif': 'image/fif',
282 'fli': 'video/x-fli',
283 'flo': 'image/florian',
284 'flx': 'text/vnd.fmi.flexstor',
285 'fmf': 'video/x-atomic3d-feature',
286 'for': 'text/plain',
287 'fpx': 'image/vnd.net-fpx',
288 'frl': 'application/freeloader',
289 'funk': 'audio/make',
290 'g': 'text/plain',
291 'g3': 'image/g3fax',
292 'gif': 'image/gif',
293 'gl': 'video/x-gl',
294 'gsd': 'audio/x-gsm',
295 'gsm': 'audio/x-gsm',
296 'gsp': 'application/x-gsp',
297 'gss': 'application/x-gss',
298 'gtar': 'application/x-gtar',
299 'gz': 'application/x-compressed',
300 'gzip': 'application/x-gzip',
301 'h': 'text/plain',
302 'hdf': 'application/x-hdf',
303 'help': 'application/x-helpfile',
304 'hgl': 'application/vnd.hp-hpgl',
305 'hh': 'text/plain',
306 'hlb': 'text/x-script',
307 'hlp': 'application/x-helpfile',
308 'hpg': 'application/vnd.hp-hpgl',
309 'hpgl': 'application/vnd.hp-hpgl',
310 'hqx': 'application/binhex',
311 'hta': 'application/hta',
312 'htc': 'text/x-component',
313 'htm': 'text/html',
314 'html': 'text/html',
315 'htmls': 'text/html',
316 'htt': 'text/webviewhtml',
317 'htx': 'text/html',
318 'ice': 'x-conference/x-cooltalk',
319 'ico': 'image/x-icon',
320 'idc': 'text/plain',
321 'ief': 'image/ief',
322 'iefs': 'image/ief',
323 'iges': 'application/iges',
324 'igs': 'application/iges',
325 'ima': 'application/x-ima',
326 'imap': 'application/x-httpd-imap',
327 'inf': 'text/plain',
328 'inf': 'application/inf',
329 'ins': 'application/x-internett-signup',
330 'ip': 'application/x-ip2',
331 'isu': 'video/x-isvideo',
332 'it': 'audio/it',
333 'iv': 'application/x-inventor',
334 'ivr': 'i-world/i-vrml',
335 'ivy': 'application/x-livescreen',
336 'jam': 'audio/x-jam',
337 'jav': 'text/plain',
338 'java': 'text/plain',
339 'jcm': 'application/x-java-commerce',
340 'jfif': 'image/jpeg',
341 'jfif-tbnl': 'image/jpeg',
342 'jpe': 'image/jpeg',
343 'jpeg': 'image/jpeg',
344 'jpg': 'image/jpeg',
345 'jps': 'image/x-jps',
346 'js': 'application/x-javascript',
347 'jut': 'image/jutvision',
348 'kar': 'audio/midi',
349 'ksh': 'text/x-script.ksh',
350 'la': 'audio/x-nspaudio',
351 'lam': 'audio/x-liveaudio',
352 'latex': 'application/x-latex',
353 'lha': 'application/octet-stream',
354 'lhx': 'application/octet-stream',
355 'list': 'text/plain',
356 'lma': 'audio/x-nspaudio',
357 'log': 'text/plain',
358 'lsp': 'text/x-script.lisp',
359 'lst': 'text/plain',
360 'lsx': 'text/x-la-asf',
361 'ltx': 'application/x-latex',
362 'lzh': 'application/octet-stream',
363 'lzx': 'application/octet-stream',
364 'm': 'text/plain',
365 'm1v': 'video/mpeg',
366 'm2a': 'audio/mpeg',
367 'm2v': 'video/mpeg',
368 'm3u': 'audio/x-mpequrl',
369 'man': 'application/x-troff-man',
370 'map': 'application/x-navimap',
371 'mar': 'text/plain',
372 'mbd': 'application/mbedlet',
373 'mc$': 'application/x-magic-cap-package-1.0',
374 'mcd': 'application/x-mathcad',
375 'mcf': 'text/mcf',
376 'mcp': 'application/netmc',
377 'me': 'application/x-troff-me',
378 'mht': 'message/rfc822',
379 'mhtml': 'message/rfc822',
380 'mid': 'audio/midi',
381 'midi': 'audio/midi',
382 'mif': 'application/x-frame',
383 'mime': 'www/mime',
384 'mjf': 'audio/x-vnd.audioexplosion.mjuicemediafile',
385 'mjpg': 'video/x-motion-jpeg',
386 'mm': 'application/base64',
387 'mme': 'application/base64',
388 'mod': 'audio/x-mod',
389 'moov': 'video/quicktime',
390 'mov': 'video/quicktime',
391 'movie': 'video/x-sgi-movie',
392 'mp2': 'video/mpeg',
393 'mp3': 'audio/mpeg3',
394 'mpa': 'audio/mpeg',
395 'mpc': 'application/x-project',
396 'mpe': 'video/mpeg',
397 'mpeg': 'video/mpeg',
398 'mpg': 'video/mpeg',
399 'mpga': 'audio/mpeg',
400 'mpp': 'application/vnd.ms-project',
401 'mpt': 'application/x-project',
402 'mpv': 'application/x-project',
403 'mpx': 'application/x-project',
404 'mrc': 'application/marc',
405 'ms': 'application/x-troff-ms',
406 'mv': 'video/x-sgi-movie',
407 'my': 'audio/make',
408 'mzz': 'application/x-vnd.audioexplosion.mzz',
409 'nap': 'image/naplps',
410 'naplps': 'image/naplps',
411 'nc': 'application/x-netcdf',
412 'ncm': 'application/vnd.nokia.configuration-message',
413 'nif': 'image/x-niff',
414 'niff': 'image/x-niff',
415 'nix': 'application/x-mix-transfer',
416 'nsc': 'application/x-conference',
417 'nvd': 'application/x-navidoc',
418 'o': 'application/octet-stream',
419 'oda': 'application/oda',
420 'omc': 'application/x-omc',
421 'omcd': 'application/x-omcdatamaker',
422 'omcr': 'application/x-omcregerator',
423 'p': 'text/x-pascal',
424 'p10': 'application/x-pkcs10',
425 'p12': 'application/x-pkcs12',
426 'p7a': 'application/x-pkcs7-signature',
427 'p7c': 'application/x-pkcs7-mime',
428 'p7m': 'application/x-pkcs7-mime',
429 'p7r': 'application/x-pkcs7-certreqresp',
430 'p7s': 'application/pkcs7-signature',
431 'part': 'application/pro_eng',
432 'pas': 'text/pascal',
433 'pbm': 'image/x-portable-bitmap',
434 'pcl': 'application/vnd.hp-pcl',
435 'pct': 'image/x-pict',
436 'pcx': 'image/x-pcx',
437 'pdb': 'chemical/x-pdb',
438 'pdf': 'application/pdf',
439 'pfunk': 'audio/make',
440 'pgm': 'image/x-portable-graymap',
441 'pic': 'image/pict',
442 'pict': 'image/pict',
443 'pkg': 'application/x-newton-compatible-pkg',
444 'pko': 'application/vnd.ms-pki.pko',
445 'pl': 'text/plain',
446 'plx': 'application/x-pixclscript',
447 'pm': 'image/x-xpixmap',
448 'pm4': 'application/x-pagemaker',
449 'pm5': 'application/x-pagemaker',
450 'png': 'image/png',
451 'pnm': 'image/x-portable-anymap',
452 'pot': 'application/vnd.ms-powerpoint',
453 'pov': 'model/x-pov',
454 'ppa': 'application/vnd.ms-powerpoint',
455 'ppm': 'image/x-portable-pixmap',
456 'pps': 'application/vnd.ms-powerpoint',
457 'ppt': 'application/vnd.ms-powerpoint',
458 'ppz': 'application/mspowerpoint',
459 'pre': 'application/x-freelance',
460 'prt': 'application/pro_eng',
461 'ps': 'application/postscript',
462 'psd': 'application/octet-stream',
463 'pvu': 'paleovu/x-pv',
464 'pwz': 'application/vnd.ms-powerpoint',
465 'py': 'text/x-script.phyton',
466 'pyc': 'applicaiton/x-bytecode.python',
467 'qcp': 'audio/vnd.qcelp',
468 'qd3': 'x-world/x-3dmf',
469 'qd3d': 'x-world/x-3dmf',
470 'qif': 'image/x-quicktime',
471 'qt': 'video/quicktime',
472 'qtc': 'video/x-qtc',
473 'qti': 'image/x-quicktime',
474 'qtif': 'image/x-quicktime',
475 'ra': 'audio/x-realaudio',
476 'ram': 'audio/x-pn-realaudio',
477 'ras': 'image/x-cmu-raster',
478 'rast': 'image/cmu-raster',
479 'rexx': 'text/x-script.rexx',
480 'rf': 'image/vnd.rn-realflash',
481 'rgb': 'image/x-rgb',
482 'rm': 'audio/x-pn-realaudio',
483 'rmi': 'audio/mid',
484 'rmm': 'audio/x-pn-realaudio',
485 'rmp': 'audio/x-pn-realaudio',
486 'rng': 'application/ringing-tones',
487 'rnx': 'application/vnd.rn-realplayer',
488 'roff': 'application/x-troff',
489 'rp': 'image/vnd.rn-realpix',
490 'rpm': 'audio/x-pn-realaudio-plugin',
491 'rt': 'text/richtext',
492 'rtf': 'text/richtext',
493 'rtx': 'text/richtext',
494 'rv': 'video/vnd.rn-realvideo',
495 's': 'text/x-asm',
496 's3m': 'audio/s3m',
497 'saveme': 'application/octet-stream',
498 'sbk': 'application/x-tbook',
499 'scm': 'video/x-scm',
500 'sdml': 'text/plain',
501 'sdp': 'application/x-sdp',
502 'sdr': 'application/sounder',
503 'sea': 'application/x-sea',
504 'set': 'application/set',
505 'sgm': 'text/sgml',
506 'sgml': 'text/sgml',
507 'sh': 'text/x-script.sh',
508 'shar': 'application/x-bsh',
509 'shtml': 'text/html',
510 'sid': 'audio/x-psid',
511 'sit': 'application/x-stuffit',
512 'skd': 'application/x-koan',
513 'skm': 'application/x-koan',
514 'skp': 'application/x-koan',
515 'skt': 'application/x-koan',
516 'sl': 'application/x-seelogo',
517 'smi': 'application/smil',
518 'smil': 'application/smil',
519 'snd': 'audio/x-adpcm',
520 'sol': 'application/solids',
521 'spc': 'text/x-speech',
522 'spl': 'application/futuresplash',
523 'spr': 'application/x-sprite',
524 'sprite': 'application/x-sprite',
525 'src': 'application/x-wais-source',
526 'ssi': 'text/x-server-parsed-html',
527 'ssm': 'application/streamingmedia',
528 'sst': 'application/vnd.ms-pki.certstore',
529 'step': 'application/step',
530 'stl': 'application/x-navistyle',
531 'stp': 'application/step',
532 'sv4cpio': 'application/x-sv4cpio',
533 'sv4crc': 'application/x-sv4crc',
534 'svf': 'image/x-dwg',
535 'svr': 'application/x-world',
536 'swf': 'application/x-shockwave-flash',
537 't': 'application/x-troff',
538 'talk': 'text/x-speech',
539 'tar': 'application/x-tar',
540 'tbk': 'application/x-tbook',
541 'tcl': 'text/x-script.tcl',
542 'tcsh': 'text/x-script.tcsh',
543 'tex': 'application/x-tex',
544 'texi': 'application/x-texinfo',
545 'texinfo': 'application/x-texinfo',
546 'text': 'text/plain',
547 'tgz': 'application/x-compressed',
548 'tif': 'image/x-tiff',
549 'tiff': 'image/x-tiff',
550 'tr': 'application/x-troff',
551 'tsi': 'audio/tsp-audio',
552 'tsp': 'application/dsptype',
553 'tsv': 'text/tab-separated-values',
554 'turbot': 'image/florian',
555 'txt': 'text/plain',
556 'uil': 'text/x-uil',
557 'uni': 'text/uri-list',
558 'unis': 'text/uri-list',
559 'unv': 'application/i-deas',
560 'uri': 'text/uri-list',
561 'uris': 'text/uri-list',
562 'ustar': 'application/x-ustar',
563 'uu': 'text/x-uuencode',
564 'uue': 'text/x-uuencode',
565 'vbs': 'text/vbs',
566 'vcd': 'application/x-cdlink',
567 'vcs': 'text/x-vcalendar',
568 'vda': 'application/vda',
569 'vdo': 'video/vdo',
570 'vew': 'application/groupwise',
571 'viv': 'video/vivo',
572 'vivo': 'video/vivo',
573 'vmd': 'application/vocaltec-media-desc',
574 'vmf': 'application/vocaltec-media-file',
575 'voc': 'audio/x-voc',
576 'vos': 'video/vosaic',
577 'vox': 'audio/voxware',
578 'vqe': 'audio/x-twinvq-plugin',
579 'vqf': 'audio/x-twinvq',
580 'vql': 'audio/x-twinvq-plugin',
581 'vrml': 'application/x-vrml',
582 'vrt': 'x-world/x-vrt',
583 'vsd': 'application/x-visio',
584 'vst': 'application/x-visio',
585 'vsw': 'application/x-visio',
586 'w60': 'application/wordperfect6.0',
587 'w61': 'application/wordperfect6.1',
588 'w6w': 'application/msword',
589 'wav': 'audio/x-wav',
590 'wb1': 'application/x-qpro',
591 'wbmp': 'image/vnd.wap.wbmp',
592 'web': 'application/vnd.xara',
593 'wiz': 'application/msword',
594 'wk1': 'application/x-123',
595 'wmf': 'windows/metafile',
596 'wml': 'text/vnd.wap.wml',
597 'wmlc': 'application/vnd.wap.wmlc',
598 'wmls': 'text/vnd.wap.wmlscript',
599 'wmlsc': 'application/vnd.wap.wmlscriptc',
600 'word': 'application/msword',
601 'wp': 'application/wordperfect',
602 'wp5': 'application/wordperfect',
603 'wp6': 'application/wordperfect',
604 'wpd': 'application/wordperfect',
605 'wq1': 'application/x-lotus',
606 'wri': 'application/x-wri',
607 'wrl': 'application/x-world',
608 'wrz': 'model/vrml',
609 'wsc': 'text/scriplet',
610 'wsrc': 'application/x-wais-source',
611 'wtk': 'application/x-wintalk',
612 'xbm': 'image/x-xbitmap',
613 'xdr': 'video/x-amt-demorun',
614 'xgz': 'xgl/drawing',
615 'xif': 'image/vnd.xiff',
616 'xl': 'application/excel',
617 'xla': 'application/x-msexcel',
618 'xlb': 'application/x-excel',
619 'xlc': 'application/x-excel',
620 'xld': 'application/x-excel',
621 'xlk': 'application/x-excel',
622 'xll': 'application/x-excel',
623 'xlm': 'application/x-excel',
624 'xls': 'application/x-msexcel',
625 'xlt': 'application/x-excel',
626 'xlv': 'application/x-excel',
627 'xlw': 'application/x-msexcel',
628 'xm': 'audio/xm',
629 'xml': 'text/xml',
630 'xmz': 'xgl/movie',
631 'xpix': 'application/x-vnd.ls-xpix',
632 'xpm': 'image/x-xpixmap',
633 'x-png': 'image/png',
634 'xsr': 'video/x-amt-showrun',
635 'xwd': 'image/x-xwindowdump',
636 'xyz': 'chemical/x-pdb',
637 'z': 'application/x-compressed',
638 'zip': 'application/x-compressed',
639 'zoo': 'application/octet-stream',
640 'zsh': 'text/x-script.zsh'
641 }
642
643 TCP_PROTOCOL = PortInfo.TCP_PROTOCOL
644 UDP_PROTOCOL = PortInfo.UDP_PROTOCOL
645
646
648 """
649 This class represents Network interface
650 @deprecated: use networking.Interface instead
651 """
652 - def __init__(self, description, physicalAddress, ips=None, subnetMasks=None, interfaceIndex=None, dhcpEnabled=0, interfaceClass="interface"):
653 self.macAddress = physicalAddress
654 self.description = description
655 self.interfaceIndex = interfaceIndex
656 self.ips = ips
657 self.masks = subnetMasks
658 self.dhcpEnabled = dhcpEnabled
659 self.type = None
660 self.adminStatus = None
661 self.operStatus = None
662 self.speed = None
663 self.name = None
664 self.alias = None
665 self.className = interfaceClass
666 self.osh = None
667
669 '-> osh or None'
670 return self.osh
671
673 return "[MAC address: %s. Description: %s]" % (self.macAddress, self.description)
674
675
676 -def createDiskOSH(containerHost, dataName, type, size=None, failures=None, name=None):
677 """
678 Creates an C{ObjectStateHolder} class that represents a disk.
679 This method uses may return None in case type is not an allowed storage type.
680 @see: isAllowedStorageType
681 @param containerHost: the container node ObjectStateHolder
682 @type containerHost: ObjectStateHolder
683 @param dataName: name of a disk
684 @type dataName: string
685 @param type: storage type
686 @type type: string
687 @param size: size of a disk in Megabytes
688 @type size: double
689 @param failures: The number of requests for storage represented by this entry that
690 could not be honored due to not enough storage.
691 @type failures: integer
692 @param name: name
693 @type name: string
694 """
695 if type == UNKNOWN_STORAGE_TYPE:
696 type = None
697 elif not isAllowedStorageType(type):
698 return None
699
700 diskOSH = ObjectStateHolder('disk')
701 diskOSH.setContainer(containerHost)
702 diskOSH.setAttribute('data_name', dataName)
703 if type:
704 diskOSH.setAttribute('disk_type', type)
705
706 if size and size != '-':
707 diskOSH.setDoubleAttribute('disk_size', size)
708
709 if (failures):
710 diskOSH.setAttribute('disk_failures', failures)
711 if name and str(name).strip():
712 __setAttributeIfExists(diskOSH, 'name', name)
713 return diskOSH
714
715
717 """
718 This method returns true if storageType is included to the list of allowed storage types.
719 Allowed storage types are taken from discoveredStorageTypes property which resides inside globalSettings.xml configuration file.
720 """
721 globalSettings = GeneralSettingsConfigFile.getInstance()
722
723 discoveredStorageTypesString = globalSettings.getPropertyStringValue('discoveredStorageTypes', '')
724
725 return isIncludedToList(discoveredStorageTypesString, storageType)
726
727
729 """
730 Creates a vector of ObjectStateHolder of type C{interface}
731 @param networkInterfaces: - a list of interfaces from which we create the OSHV (Object State Holder Vector).
732 @type networkInterfaces: a list NetworkInterface
733 @param containerHostOSH: - the container node of the interfaces
734 @type containerHostOSH: ObjectStateHolder
735 @return: a vector that contains ObjectStateHolder classes that were created from the input
736 @rtype: ObjectStateHolderVector
737 """
738 oshv = ObjectStateHolderVector()
739 for interface in networkInterfaces:
740 osh = createInterfaceOSH(interface.macAddress, containerHostOSH, interface.description, interface.interfaceIndex, interface.type, interface.adminStatus, interface.adminStatus, interface.speed, interface.name, interface.alias, interface.className)
741 if osh is not None:
742 interface.osh = osh
743 oshv.add(osh)
744 else:
745 logger.debug('Mac is invalid and will be skipped: %s' % interface)
746 return oshv
747
748
750 """ Check whether interface is valid. Support for NNM pseudo interfaces that are prefixed with constant value.
751 str[, str, str] -> bool
752 For CMDB 8 check only mac (physical address or interface index)
753 For CMDB 9 if mac is not valid - name and description can be checked for existence too
754 @deprecated: Logic is not obvious
755 """
756 NNM_PSEUDO_INTERFACE_PREFIX = 'ZZZZ'
757 isValid = mac is not None and (netutils.isValidMac(mac) or str(mac).isdigit() or mac.startswith(NNM_PSEUDO_INTERFACE_PREFIX))
758 if not isValid:
759 if _CMDB_CLASS_MODEL.version() >= 9:
760 isValid = name or description
761 return isValid
762
763
764 -def createInterfaceOSH(mac, hostOSH=None, description=None, index=None, type=None, adminStatus=None, operStatus=None, speed=None, name=None, alias=None, interfaceClass="interface"):
765 """
766 Creates an C{ObjectStateHolder} based on the interface at the specified address. Throws
767 @param mac: the MAC address of the interface, or the interface index or the interface description
768 @type mac: string - either a MAC address or a MAC index
769 @param hostOSH: the container node ObjectStateHolder
770 @type hostOSH: ObjectStateHolder
771 @return: new interface or None
772 @rtype: ObjectStateHolder
773 """
774 interface = ObjectStateHolder(interfaceClass)
775
776 if not isValidInterface(mac, name, description):
777 return None
778 try:
779 mac = netutils.parseMac(mac)
780 except:
781
782 mac = None
783
784 if netutils.isValidMac(mac):
785 if mac and checkAttributeExists('interface', 'mac_address'):
786 interface.setAttribute('mac_address', mac)
787 interface.setStringAttribute('interface_macaddr', mac)
788 elif mac in netutils._IGNORED_INTERFACE_MACS:
789 return None
790 elif not name:
791
792
793 if description is None:
794
795 return None
796 else:
797 name = description
798 elif not name:
799 return None
800
801 if hostOSH:
802 interface.setContainer(hostOSH)
803
804 if description:
805 interface.setAttribute('interface_description', description)
806
807 if index is not None:
808 if checkAttributeExists('interface', 'interface_index'):
809 interface.setIntegerAttribute('interface_index', index)
810
811 if type:
812 if checkAttributeExists('interface', 'interface_type'):
813 intValue = None
814 try:
815 intValue = int(type)
816 except:
817 logger.warn("Failed to convert the interface type '%s'" % type)
818 else:
819 if intValue > 0:
820 interface.setEnumAttribute("interface_type", intValue)
821
822 if adminStatus:
823 if checkAttributeExists('interface', 'interface_admin_status'):
824 intValue = None
825 try:
826 intValue = int(adminStatus)
827 except:
828 logger.warn("Failed to convert the interface admin status '%s'" % adminStatus)
829 else:
830 if intValue > 0:
831 interface.setEnumAttribute("interface_admin_status", intValue)
832
833 if operStatus and checkAttributeExists('interface', 'interface_operational_status'):
834 intValue = None
835 try:
836 intValue = int(operStatus)
837 except:
838 logger.warn("Failed to convert the interface admin status '%s'" % operStatus)
839 else:
840 if intValue > 0:
841 interface.setEnumAttribute("interface_operational_status", intValue)
842
843 if speed is not None and checkAttributeExists('interface', 'interface_speed'):
844 longValue = None
845 try:
846 longValue = long(speed)
847 except:
848 logger.warn("Failed to convert the interface interface speed '%s'" % speed)
849 else:
850 if longValue > 0:
851 interface.setLongAttribute("interface_speed", longValue)
852
853 if name:
854 if checkAttributeExists('interface', 'interface_name'):
855 interface.setAttribute('interface_name', name)
856 else:
857 interface.setStringAttribute('data_name', name)
858
859 if alias:
860 if checkAttributeExists('interface', 'interface_alias'):
861 interface.setAttribute('interface_alias', alias)
862 if interfaceClass == 'interface_aggregation':
863 interface.setBoolAttribute('isvirtual', 1)
864 if checkAttributeExists('interface', 'interface_role'):
865 list_ = StringVector(('aggregate_interface',))
866 roleAttribute = AttributeStateHolder('interface_role', list_)
867 interface.addAttributeToList(roleAttribute)
868
869 return interface
870
871
873
874
875 """
876 Creates an C{ObjectStateHolder} class that represents a link.
877 The link must be a valid link according to the class model.
878 @param className: the name of the link to create
879 @type className: string
880 @param end1: the I{from} of the link
881 @type end1: CmdbObjectID
882 @param end2: the I{to} of the link
883 @type end2: CmdbObjectID
884
885 @return: a link from end1 to end2 of type className
886 @rtype: ObjectStateHolder
887 """
888 link = ObjectStateHolder(className)
889 if (end1.__class__ is ObjectStateHolder):
890 link.setAttribute("link_end1", end1)
891 else:
892 link.setObjectIDAttribute("link_end1", end1)
893
894 if (end2.__class__ is ObjectStateHolder):
895 link.setAttribute("link_end2", end2)
896 else:
897 link.setObjectIDAttribute("link_end2", end2)
898
899 return link
900
901
915
916
918 r'@types: -> com.hp.ucmdb.discovery.library.scope.DomainScopeManager'
919 return DomainScopeManager
920
921
922 -def createIpOSH(ipAddress, netmask=None, dnsname=None, ipProps=None):
923 """
924 Creates an C{ObjectStateHolder} that represents an IP.
925 @param ipAddress: a well formatted IP address
926 @type ipAddress: string
927 @param netmask: a well formatted net mask
928 @type netmask: string
929 @param dnsname: the given IP-related DNS name
930 @type dnsname: string
931
932 @return: an IP address OSH
933 @rtype: ObjectStateHolder
934 """
935
936 if not ipAddress:
937 raise ValueError("Receive IP Address that is invalid: %s" % ipAddress)
938
939 ipVersion = 4
940 ipAddressString = str(ipAddress)
941
942 if not (isinstance(ipAddress, type("")) or isinstance(ipAddress, type(u''))):
943 try:
944 ipVersion = ipAddress.version
945 except:
946 logger.debugException('')
947 else:
948 if not netutils.isValidIp(ipAddressString):
949 raise ValueError("Receive IP Address that is invalid: %s" % ipAddress)
950
951 domainName = _getDomainScopeManager().getDomainByIp(ipAddressString)
952 probeName = None
953 if not domainName:
954 domainName = '${DefaultDomain}'
955 else:
956 probeName = _getDomainScopeManager().getProbeName(ipAddressString, domainName)
957
958 ipOsh = ObjectStateHolder("ip")
959 ipOsh.setStringAttribute("ip_address", ipAddressString)
960 ipOsh.setStringAttribute("name", ipAddressString)
961 ipOsh.setStringAttribute("ip_domain", domainName)
962 if probeName:
963 ipOsh.setStringAttribute("ip_probename", probeName)
964
965 if dnsname:
966 ipOsh.setStringAttribute("ip_dnsname", dnsname)
967
968 if netmask and ipVersion != 6:
969 parsedIp = IPv4(ipAddressString, netmask)
970 networkAddress = parsedIp.getNetAddress().toString()
971 ipOsh.setAttribute("ip_netaddr", networkAddress)
972 ipOsh.setAttribute("ip_netmask", netmask)
973
974 netclass = netutils.getNetworkClassByNetworkMask(netmask)
975 if netclass:
976 ipOsh.setAttribute("ip_netclass", netclass)
977
978 if not netmask in ('255.255.255.255', '255.255.255.254'):
979 broadcastIp = parsedIp.getLastIp()
980 if parsedIp.equals(broadcastIp):
981 ipOsh.setBoolAttribute("ip_isbroadcast", 1)
982
983 if ipProps:
984 __setAttributeIfExists(ipOsh, 'ip_address_property', ipProps)
985 if ipProps == IP_ADDRESS_PROPERTY_DHCP:
986 ipOsh.setBoolAttribute('ip_isdhcp', 1)
987
988 return ipOsh
989
990
992 '@deprecated: Use setOsName of HostBuilder instead'
993 if hostOsh:
994 hostOsh = HostBuilder(hostOsh).setOsName(osName).build()
995
996
997 COMMA = ', '
998
999
1001 """
1002 Checks if some value part of value can be matched by at least one regexp.
1003 @param regexpListString: String represented by sequence of regexps separated by some delimiter
1004 @param value: Actual value which is checked by regexps
1005 @param delimiter: Delimiter used in regexpListString. By default is ', ' without quotes
1006 @deprecated: Please do not use this method. It won't be accessible in the public scope
1007 """
1008 regexps = regexpListString.split(delimiter)
1009 for regexp in regexps:
1010 if re.findall(regexp, value):
1011 return 1
1012 return 0
1013
1014
1016 """ Check value for existance in the string of elements delimited by <delimiter>
1017 str, str, str -> bool
1018 @deprecated: Please do not use this method. It won't be accessible in the public scope"""
1019 elements = listOfElementsString.split(delimiter)
1020 return elements.count(value) > 0
1021
1022
1024 """
1025 Sets the machine name and operation system attributes of a node.
1026 @param uh_obj: the node to update
1027 @type uh_obj: OSH
1028 @param osName: the operation system name, can be None
1029 @type osName: string
1030 @param machineName: the machine name, can be None
1031 @type machineName: string
1032 """
1033 setHostOsName(uh_obj, osName)
1034
1035 if machineName:
1036 uh_obj.setAttribute('host_hostname', machineName)
1037
1038 if machineBootDate:
1039 uh_obj.setDateAttribute('host_last_boot_time', machineBootDate)
1040
1041
1042 -def createHostOSH(ipAddress, hostClassName="node",osName=None, machineName=None, machineBootDate=None):
1043
1044 """
1045 Creates a node OSH with its associated IP Address, operation system name. and machine name.
1046 The created node is not complete>
1047 @param ipAddress: a well formated IP address
1048 @type ipAddress: string
1049 @param hostClassName: the default is I{node}
1050 @type hostClassName: string
1051 @param osName: the operation system name, can be None
1052 @type osName: string
1053 @param machineName: the MAC address, can be None
1054 @type machineName: string
1055 """
1056 domainName = _getDomainScopeManager().getDomainByIp(ipAddress.strip())
1057
1058 host = ObjectStateHolder(hostClassName);
1059 host.setAttribute("host_key", '%s %s' % (ipAddress, domainName))
1060 host.setBoolAttribute('host_iscomplete', 0)
1061 addHostAttributes(host, osName, machineName, machineBootDate)
1062 return host;
1063
1064
1066 """
1067 create a new OSH that represent a network
1068 @param ipAddress: a well formed IP address
1069 @type ipAddress: string
1070 @param netmask: a well formed new mask
1071 @type netmask: string
1072 @return: a new network OSH
1073 @rtype: ObjectStateHolder
1074 """
1075
1076 parsedIp = IPv4(ipAddress, netmask)
1077 netAddressStr = parsedIp.getNetAddress().toString()
1078
1079 domainName = _getDomainScopeManager().getDomainByNetwork(netAddressStr, netmask)
1080 probeName = _getDomainScopeManager().getProbeNameByNetwork(netAddressStr, netmask, domainName)
1081
1082 networkOsh = ObjectStateHolder("network")
1083 networkOsh.setStringAttribute("network_netaddr", netAddressStr)
1084 networkOsh.setStringAttribute("network_domain", domainName)
1085 networkOsh.setStringAttribute("network_probename", probeName)
1086 networkOsh.setStringAttribute("network_netmask", netmask)
1087
1088 if not netmask in ('255.255.255.255', '255.255.255.254'):
1089 broadcastAddress = parsedIp.getLastIp().toString()
1090 networkOsh.setStringAttribute("network_broadcastaddress", broadcastAddress)
1091
1092 netclass = netutils.getNetworkClassByNetworkMask(netmask)
1093 if netclass:
1094 networkOsh.setStringAttribute("network_netclass", netclass)
1095
1096 if netmask:
1097 __setAttributeIfExists(networkOsh, 'ip_prefix_length', netutils.getShortMask(netmask), AppilogTypes.INTEGER_DEF)
1098
1099 return networkOsh
1100
1101
1103 return re.search('VMware', interfaceDescription, re.I)
1104
1105
1107
1108
1109
1110
1111
1112
1113 if interfaceDescription is None:
1114 return 0
1115
1116 ignoreLocalizedIinterfacePatternFilter = []
1117 ignoreLocalizedString = GeneralSettingsConfigFile.getInstance().getPropertyStringValue('ignoreLocalizedVirtualInterfacesPatternList', '')
1118 ignoreLocalizedIinterfacePatternFilter.extend(IGNORE_INTERFACE_PATTERN_FILTER)
1119 if ignoreLocalizedString:
1120 ignoreLocalizedIinterfacePatternFilter.extend(ignoreLocalizedString.split(','))
1121 for pattern in ignoreLocalizedIinterfacePatternFilter:
1122 if re.search(pattern, interfaceDescription, re.I):
1123 return 0
1124
1125 if __isVMWareInterface(interfaceDescription):
1126 ignoreVmwareInterfaces = GeneralSettingsConfigFile.getInstance().getPropertyIntegerValue('ignoreVmwareInterfaces', 1)
1127 if ignoreVmwareInterfaces == 2:
1128 logger.debug('VMWare interface are configured to be ignored, based on ignoreVmwareInterfaces global parameter:', ignoreVmwareInterfaces)
1129 return 0
1130 return 1
1131
1132
1134
1135 if hostKey in discoveredMacs:
1136 return 1
1137
1138
1139 if existingMacs and existingMacs != "NA":
1140 for existingMac in existingMacs:
1141 if existingMac in discoveredMacs:
1142 return 1
1143
1144
1145 -def createCompleteHostOSHByInterfaceList(hostClass, interfaceList, osName = None, machineName = None, machineBootDate = None, host_cmdbid = None, host_key = None, host_macs = None, ucmdb_version = None):
1146 """
1147 Returns the minimal valid mac address to be used as key for the node.
1148 A valid mac is one that passed isValidMac() method.
1149 For some interfaces (like Wireless, VMware, Bluetooth etc), the
1150 MAC address cannot be used as the key.
1151 @param hostClass: the node type, for example I{nt}
1152 @type hostClass: string
1153 @param interfaceList: a list of C{NetworkInterface}
1154 @type interfaceList: list
1155 @param osName: operation system name, can be None
1156 @type osName: string
1157 @param machineName: can be None
1158 @type machineName: string
1159 """
1160
1161 macList = []
1162 allMacs = []
1163 listVMmacList = []
1164 for interface in interfaceList:
1165 macAddress = interface.macAddress
1166 description = interface.description
1167 isValid = netutils.isValidMac(macAddress)
1168 if isValid:
1169 macAddress = netutils.parseMac(macAddress)
1170 allMacs.append(macAddress)
1171
1172 if isValid and __isAllowedInterface(description):
1173 logger.debug('Appending MAC address: %s' % macAddress)
1174 if __isVMWareInterface(description):
1175 listVMmacList.append(macAddress)
1176 else:
1177 macList.append(macAddress)
1178 else:
1179 logger.debug('Ignoring interface: %s' % description)
1180
1181 if len(macList) > 0:
1182 if ucmdb_version < 9 and host_cmdbid and host_cmdbid != 'NA' and __isKnownHost(host_key, host_macs, allMacs):
1183
1184 hostOsh = createOshByCmdbIdString(hostClass, host_cmdbid)
1185 hostOsh.setBoolAttribute('host_iscomplete', 1)
1186 addHostAttributes(hostOsh, osName, machineName, machineBootDate)
1187 return hostOsh
1188
1189
1190 hostKey = min(macList)
1191 return createCompleteHostOSH(hostClass, hostKey, osName, machineName, machineBootDate)
1192 elif len(listVMmacList) > 0:
1193
1194 hostKey = min(listVMmacList)
1195 return createCompleteHostOSH(hostClass, hostKey, osName, machineName)
1196 elif len(allMacs) > 0:
1197 hostKey = min(allMacs)
1198 return createCompleteHostOSH(hostClass, hostKey, osName, machineName)
1199 else:
1200 logger.debug('Could not find valid host key. Interfaces list: %s' % interfaceList)
1201 raise Exception('Could not find valid host key')
1202
1203
1205 """
1206 Creates a OSH that represents a complete node.
1207 @param hostClass: the node type, for example I{nt}
1208 @type hostClass: string
1209 @param hostKey: the smallest MAC address of the machine
1210 @type hostKey: string
1211 @param osName: operation system name, can be None
1212 @type osName: string
1213 @param machineName: can be None
1214 @type machineName: string
1215 @rtype: ObjectStateHolder
1216 """
1217 uh_obj = ObjectStateHolder(hostClass)
1218 uh_obj.setAttribute('host_key', hostKey)
1219 uh_obj.setBoolAttribute('host_iscomplete', 1)
1220 addHostAttributes(uh_obj, osName, machineName, machineBootDate)
1221 return uh_obj
1222
1223
1225 """
1226 Creates an incomplete node and an IP connected with a C{contained} link.
1227 @param ip: a well formed IP address
1228 @type ip: string
1229 @return: return a OSHV that contains three OSH object, IP, node, and a link between them
1230 @rtype: ObjectStateHolderVector that contains three ObjectStateHolder classes
1231 """
1232 vec = ObjectStateHolderVector()
1233 hostOSH = createHostOSH(ip)
1234 ipOSH = createIpOSH(ip)
1235 link = createLinkOSH('contained', hostOSH, ipOSH)
1236
1237 vec.add(hostOSH)
1238 vec.add(ipOSH)
1239 vec.add(link)
1240
1241 return vec
1242
1243
1245 """
1246 Return data for bytes attribute - zips the data bytes encoded as UTF-8 and returns the
1247 following information set: (Zipped Bytes, CheckSum Value, String Length)
1248 """
1249 bytes = String(stringValue).getBytes('UTF-8')
1250 zipper = ChecksumZipper()
1251 zippedBytes = zipper.zip(bytes)
1252 checksumValue = zipper.getChecksumValue()
1253 return (zippedBytes, checksumValue, len(stringValue))
1254
1255
1256 -def createCFOSH(filename, extension, path, filecontent, containerOSH=None, description=None, charsetName=None):
1257 """
1258 Creates a ObjectStateHolder that contains a zipped configuration file.
1259 This method is deprecated
1260 """
1261 if extension:
1262 filename = filename + '.' + extension
1263 return createConfigurationDocumentOSH(filename, path, filecontent, containerOSH, None, None, description, None, charsetName)
1264
1265
1267 configFileOsh = createConfigurationDocumentOSH(file.getName(), file.path, file.content,
1268 containerOsh, contentType,
1269 file.lastModificationTime(), description,
1270 file.version, charsetName)
1271 if file.owner:
1272 configFileOsh.setAttribute('document_osowner', file.owner)
1273 if file.permissions():
1274 configFileOsh.setAttribute('document_permissions', file.permissions())
1275 return configFileOsh
1276
1277
1278 -def createConfigurationDocumentOSH(name, path, content, containerOSH=None, contentType=None,
1279 contentLastUpdate=None, description=None, version=None, charsetName=None):
1280 """
1281 Creates ObjectStateHolder that represents a configuration document.
1282 @param name: the name of the configuration document
1283 @type name: string
1284 @param path: full path to configuration file
1285 @type path: string
1286 @param content: contents of configuration file
1287 @type content: string
1288 @param containerOSH: the container of the configuration document
1289 @type containerOSH: ObjectStateHolder
1290 @param contentType: content type
1291 @type contentType: string
1292 @param contentLastUpdate: last time the content was updated
1293 @type contentLastUpdate: java.util.Date
1294 @param description: description of the document
1295 @type description: string
1296 @param version: version of configuration document
1297 @type version: string
1298 @param charsetName: charset name of the content
1299 @type charsetName: string
1300 @return: ObjectStateHolder for configuration document
1301 """
1302
1303 documentOsh = ObjectStateHolder("configfile")
1304 documentOsh.setAttribute('data_name', name)
1305 resolvedContentType = contentType
1306 if resolvedContentType == None:
1307 extensionRegex = ".+\.(\w+)$"
1308 extension = re.match(extensionRegex, name)
1309 if extension:
1310 extension = extension.group(1)
1311 if MIME_TYPES.has_key(extension):
1312 resolvedContentType = MIME_TYPES[extension]
1313 else:
1314 resolvedContentType = None
1315 logger.warn("Content type for file %s was not resolved" % name)
1316 else:
1317 logger.warn("Content type for file %s was not resolved" % name)
1318
1319 if content:
1320 bytes = None
1321 if charsetName:
1322 bytes = String(content).getBytes(charsetName)
1323 else:
1324 bytes = String(content).getBytes()
1325 zipper = ChecksumZipper()
1326 zippedBytes = zipper.zip(bytes)
1327 checksumValue = zipper.getChecksumValue()
1328 if len(zippedBytes) <= 512000:
1329 documentOsh.setBytesAttribute('document_data', zippedBytes)
1330 else:
1331 logger.debug('Configuration file %s size is too big' % name)
1332 documentOsh.setLongAttribute('document_checksum', checksumValue)
1333 documentOsh.setLongAttribute('document_size',len(bytes))
1334 if path:
1335 documentOsh.setAttribute('document_path', path)
1336 if resolvedContentType:
1337 __setAttributeIfExists(documentOsh, 'document_content_type', resolvedContentType)
1338 if contentLastUpdate:
1339 documentOsh.setAttribute('document_lastmodified', contentLastUpdate)
1340 if description:
1341 documentOsh.setAttribute('data_description', description)
1342 if version:
1343 __setAttributeIfExists(documentOsh, 'version', version)
1344 if containerOSH is not None:
1345 documentOsh.setContainer(containerOSH)
1346
1347 return documentOsh
1348
1349
1351 """Class represents Process Data Object - process with all its attributes"""
1352
1353 - def __init__(self, name, commandline, pid=None, path=None, parameters=None, user=None, startuptime=None, description=None):
1354 self.name = name
1355 self.commandline = commandline
1356 self.pid = pid
1357 self.path = path
1358 self.parameters = parameters
1359 self.user = user
1360 self.startuptime = startuptime
1361 self.description = description
1362
1363
1365 """Class represents process matcher, which decides whether particual process satisfies defined conditions"""
1366
1368 """Base class for process matching rule"""
1371
1374
1376 """
1377 Rule which verifies that perticular property of process matches the regex.
1378 Currently works for String properties or properties that can be converted to String.
1379 Will raise exception if defined property is not found.
1380 """
1381 - def __init__(self, targetProperty, pattern, flags=0):
1386
1388 if processDo:
1389 value = self._getProperty(processDo)
1390 if value and re.match(self.pattern, str(value), self.flags): return 1
1391
1393 return getattr(processDo, self.targetProperty)
1394
1397
1399 if self._rules:
1400 for rule in self._rules:
1401 if not rule.matches(processDo):
1402 return 0
1403 return 1
1404
1409
1410
1412 """Class represents a modifier of a process. Performs modification of process' properties by defined rules."""
1413
1415 """Base class for process modification rule."""
1418
1419 - def apply(self, processDo):
1421
1423 """
1424 Modifier that performs string substitution in process string proeprty.
1425 Will raise exception if target property is not found.
1426 """
1427 - def __init__(self, targetProperty, pattern, replacement):
1428 _ProcessModifier.Rule.__init__(self)
1429 self.targetProperty = targetProperty
1430 self.pattern = pattern
1431 self.replacement = replacement
1432
1433 - def apply(self, processDo):
1434 if processDo:
1435 value = self._getProperty(processDo)
1436 if value:
1437 value = re.sub(self.pattern, self.replacement, value)
1438 self._setProperty(processDo, value)
1439
1441 return getattr(processDo, self.targetProperty)
1442
1444 setattr(processDo, self.targetProperty, value)
1445
1448
1449 - def apply(self, processDo):
1450 if processDo:
1451 for rule in self._rules:
1452 rule.apply(processDo)
1453
1457
1458
1460 """Class sanitizes processes by defined rules - adjusts the data or prevents illegal values to enter CMDB"""
1461
1462 _EXCHANGE_MODIFIER = _ProcessModifier()
1463 _EXCHANGE_MODIFIER.replaceInCommandline(r"\s+-pipe:\d+", "")
1464 _EXCHANGE_MODIFIER.replaceInCommandline(r"\s+-stopkey:[\w\\-]+", "")
1465 _EXCHANGE_MODIFIER.replaceInCommandline(r"\s+-resetkey:[\w\\-]+", "")
1466 _EXCHANGE_MODIFIER.replaceInCommandline(r"\s+-readykey:[\w\\-]+", "")
1467 _EXCHANGE_MODIFIER.replaceInCommandline(r"\s+-hangkey:[\w\\-]+", "")
1468
1469 MATCHER_TO_MODIFIER_MAP = {
1470 _ProcessMatcher().byName(r"smcgui\.exe"): _ProcessModifier().replaceInCommandline(r"\s*\\\\\.\\pipe\\\w+", ""),
1471 _ProcessMatcher().byName(r"w3wp\.exe"): _ProcessModifier().replaceInCommandline(r"\s+-a\s+\\\\\.\\pipe\\[\w-]+", ""),
1472 _ProcessMatcher().byName(r"vmware-vmx(\.exe)?"): _ProcessModifier().replaceInCommandline(r"\s+-@\s+\"pipe=\\\\\.\\pipe\\.+?\"", ""),
1473 _ProcessMatcher().byName(r"AppleMobileDeviceHelper\.exe"): _ProcessModifier().replaceInCommandline(r"\s+--pipe\s+\\\\\.\\pipe\\[\w-]+", ""),
1474 _ProcessMatcher().byName(r"EdgeTransport\.exe"): _EXCHANGE_MODIFIER,
1475
1476 _ProcessMatcher().byName(r"Microsoft.Exchange\.\w+\.exe"): _EXCHANGE_MODIFIER,
1477 _ProcessMatcher().byName(r"CITRIX\.exe"): _ProcessModifier().replaceInCommandline(r"\s+--lmgrd_start\s+\w+", "")
1478 }
1479
1484
1485
1486 -def createProcessOSH(name, hostOSH, process_cmdline=None, process_pid=None,
1487 process_path=None, process_parameters=None, process_user=None, process_startuptime=None,
1488 procDescription=None):
1489 """
1490 Creates a new OSH that represent a process.
1491 @param name: the name of the process
1492 @type name: string
1493 @param hostOSH: the container node of the proccess
1494 @type hostOSH: ObjectStateHolderVector
1495 @param process_cmdline:
1496 @type process_cmdline: string
1497 @param process_path: the path of the process installation
1498 @type process_path: string
1499 @param process_parameters: process parameters
1500 @type process_parameters: string
1501 @param process_startuptime: time when process has been started in milliseconds
1502 @procDescription: short description of current process
1503 @type process_startuptime: long
1504 @return: a new ObjectStateHolder that represents a process
1505 @rtype: ObjectStateHolder
1506 """
1507 if process_cmdline or process_parameters:
1508 globalSettings = GeneralSettingsConfigFile.getInstance()
1509 clearCommandLineForProcesses = globalSettings.getPropertyStringValue('clearCommandLineForProcesses', '')
1510 for proc in clearCommandLineForProcesses.split(','):
1511 if name.lower() == proc.strip().lower():
1512 process_cmdline = None
1513 process_parameters = None
1514
1515 processDo = _ProcessDo(name, process_cmdline, process_pid, process_path, process_parameters, process_user, process_startuptime, procDescription)
1516
1517 _ProcessSanitizer().sanitize(processDo)
1518
1519 processOSH = ObjectStateHolder('process')
1520 processOSH.setStringAttribute('data_name', processDo.name)
1521 if processDo.commandline == '':
1522 processDo.commandline = None
1523 if processDo.commandline:
1524 processOSH.setStringAttribute('process_cmdline', processDo.commandline.strip())
1525 processOSH.setContainer(hostOSH)
1526
1527 if processDo.pid != None:
1528 processOSH.setIntegerAttribute('process_pid', int(processDo.pid))
1529 if processDo.path != None:
1530 processOSH.setStringAttribute('process_path', processDo.path)
1531 if processDo.parameters != None:
1532 processOSH.setStringAttribute('process_parameters', processDo.parameters)
1533 if processDo.user != None:
1534 processOSH.setStringAttribute('process_user', processDo.user)
1535 if processDo.startuptime != None and processDo.startuptime != 0:
1536 startupDate = Date(processDo.startuptime)
1537 processOSH.setDateAttribute('process_startuptime', startupDate)
1538 if processDo.description != None:
1539 processOSH.setStringAttribute('data_description', processDo.description)
1540 return processOSH
1541
1542
1544 """
1545 @deprecated: use modeling.createUrlOsh method instead
1546
1547 Creates a new OSH that repesents an ipserver.
1548 @param hostOSH: the container node of the process
1549 @type hostOSH: ObjectStateHolderVector
1550 @return: a new ObjectStateHolder that represents an ipserver
1551 @rtype: ObjectStateHolder
1552 """
1553 return createUrlOsh(hostOSH, url)
1554
1555
1557 """
1558 Creates a new OSH that represents an url
1559 @param hostOsh: the container node of the url
1560 @type hostOsh: ObjectStateHolder
1561 @param url: url connect string
1562 @type url: string
1563 @return: a new ObjectStateHolder instance
1564 @rtype: ObjectStateHolder
1565 """
1566
1567
1568
1569
1570
1571 urlOsh = ObjectStateHolder('url')
1572 urlOsh.setAttribute('data_name', url)
1573 setAdditionalKeyAttribute(urlOsh, 'url_connectstring', url)
1574 urlOsh.setContainer(hostOsh)
1575 return urlOsh
1576
1577
1579 """
1580 Creates a new OSH that repesents an ipserver.
1581 @param hostOSH: the container node of the process
1582 @type hostOSH: ObjectStateHolderVector
1583 @param portNumber: port number
1584 @type ip: string
1585 @type portNumber: int
1586 @param portType: port type
1587 @type portType: enum
1588 @param portName: name of the port
1589 @type portName: string
1590 @return: a new ObjectStateHolder that represents an ipserver
1591 @rtype: ObjectStateHolder
1592 """
1593 ipServerOSH = ObjectStateHolder('ipserver')
1594 ipServerOSH.setAttribute('ipserver_address', ip + ':' + str(portNumber))
1595 ipServerOSH.setEnumAttribute('ipport_type', portType)
1596 if portType == SERVICEADDRESS_TYPE_TCP:
1597 __setAttributeIfExists(ipServerOSH, 'port_type', 'tcp')
1598 elif portType == SERVICEADDRESS_TYPE_UDP:
1599 __setAttributeIfExists(ipServerOSH, 'port_type', 'udp')
1600 ipServerOSH.setAttribute('ipport_number', int(portNumber))
1601 if (ip != None):
1602 ipServerOSH.setAttribute('ip_address', ip)
1603 if (portName != None):
1604 ipServerOSH.setStringAttribute('data_name', portName)
1605 ipServerOSH.setContainer(hostOSH)
1606
1607 return ipServerOSH
1608
1609
1611 if databaseDataNames.has_key(dbType):
1612 data_name = databaseDataNames[dbType]
1613 return data_name
1614 else:
1615 raise Exception('Unsupported DB Type: ' + dbType)
1616
1617
1619 supportedDbType = []
1620 for dbType in databaseDataNames.keys():
1621 supportedDbType.append(dbType)
1622 return supportedDbType
1623
1624
1625
1626 -def createDatabaseOSH(dbType, dbName, dbPort, ip, hostOSH, credentialsID=None, userName=None, timeout=None, dbVersion=None, appVersion=None, applicationVersionNumber=None):
1627 '''
1628 @param dbType: this is a key attribute that defines db type
1629 @param dbName: this is a key attribute that represented in OSH as SID
1630 @raise Exception: if db type is not supported
1631 @raise ValueError: if key attribute is missing
1632 '''
1633 if dbName is None:
1634 raise ValueError("Key attribute SID is missing")
1635
1636 data_name = getDatabaseDataName(dbType)
1637 databaseCategory = 'Database'
1638 databaseDbType = dbType
1639 databaseVendor = None
1640 databaseName = dbName
1641 if dbType in ('oracle', 'mysql'):
1642 databaseVendor = 'oracle_corp'
1643 elif dbType == 'sqlserver':
1644 databaseDbType = "MicrosoftSQLServer"
1645 databaseVendor = 'microsoft_corp'
1646 elif dbType == 'db2':
1647 databaseVendor = 'ibm_corp'
1648 elif dbType == 'sybase':
1649 databaseDbType = 'Sybase'
1650 databaseVendor = 'sybase_inc'
1651 elif dbType in ('maxdb', 'MAXDB'):
1652 databaseDbType = 'maxdb'
1653 databaseVendor = 'SAP'
1654 elif dbType == 'HDB':
1655 databaseDbType = 'sap_hdb'
1656 databaseVendor = 'SAP'
1657
1658 databaseOSH = createApplicationOSH(dbType, data_name, hostOSH, databaseCategory, databaseVendor)
1659
1660 if dbPort:
1661 try:
1662 databaseOSH.setAttribute('application_port', int(dbPort))
1663 if _CMDB_CLASS_MODEL.version() < 9:
1664 databaseOSH.setAttribute('database_dbport', str(dbPort))
1665 except:
1666 logger.debugException('Port is not a valid integer -', dbPort)
1667
1668 databaseOSH.setAttribute('application_ip', ip)
1669
1670
1671
1672 setAdditionalKeyAttribute(databaseOSH, 'database_dbsid', databaseName.strip())
1673
1674 databaseOSH.setAttribute('database_dbtype', databaseDbType)
1675 if credentialsID != None:
1676 databaseOSH.setAttribute('credentials_id', credentialsID)
1677 if userName != None:
1678 databaseOSH.setAttribute('application_username', userName)
1679 if timeout!=None:
1680 databaseOSH.setAttribute('application_timeout', timeout)
1681 if dbVersion and dbVersion != 'NA':
1682 setDatabaseVersion(databaseOSH, dbVersion)
1683
1684 if appVersion != None and appVersion != 'NA':
1685 databaseOSH.setAttribute('application_version', appVersion)
1686 if applicationVersionNumber != None:
1687 databaseOSH.setAttribute('application_version_number', applicationVersionNumber)
1688
1689 return databaseOSH
1690
1691
1700
1701
1702 -def createWebServerOSH(serverType, port, configfile, hostOSH, isIHS, serverVersion=None):
1703 serverClass = 'application'
1704 data_name = serverType
1705 vendor = None
1706 webServerConfigFile = None
1707 if string.find(serverType, 'IBM_HTTP')>=0 or string.find(serverType, 'IBM HTTP')>= 0 or isIHS:
1708 if configfile != None and configfile != '' and configfile !='N/A':
1709 serverClass = 'ibmhttpserver'
1710 webServerConfigFile = configfile
1711 data_name = 'IBM HTTP WebServer'
1712 vendor = 'ibm_corp'
1713 elif string.find(serverType, 'Apache')>=0:
1714 if configfile != None and configfile != '' and configfile !='N/A':
1715 serverClass = 'apache'
1716 webServerConfigFile = configfile
1717 data_name = 'Apache WebServer'
1718 vendor = 'the_apache_software_foundation'
1719 elif string.find(serverType, 'Netscape-Enterprise') >= 0 or string.find(serverType, "Sun-ONE-Web-Server") >= 0:
1720 serverClass = 'sunoneserver'
1721 data_name = 'Sun One WebServer'
1722 vendor = 'oracle_corp'
1723 elif string.find(serverType, 'Microsoft-IIS') >= 0:
1724 serverClass = 'iis'
1725 data_name = 'Microsoft IIS WebServer'
1726 vendor = 'microsoft_corp'
1727 elif string.find(serverType, 'Jetty') >= 0:
1728 data_name = 'Jetty WebServer'
1729 else:
1730 logger.debug('server type [', serverType, '] is not supported')
1731
1732 webServerOSH = createApplicationOSH(serverClass, data_name, hostOSH, 'Web Server', vendor)
1733
1734 setWebServerVersion(webServerOSH, serverVersion)
1735
1736 if serverClass == 'application':
1737 if (port != None) and (_CMDB_CLASS_MODEL.version() >= 9):
1738 webServerOSH.setIntegerAttribute('application_port', port)
1739 return webServerOSH
1740
1741 logger.debug('Creating WebServer OSH', serverClass,' isIHS:', isIHS)
1742
1743 if webServerConfigFile != None:
1744 webServerOSH.setAttribute('webserver_configfile', webServerConfigFile.lower())
1745 webServerOSH.setAttribute('webserver_configfile_case_sensitive', webServerConfigFile)
1746
1747 if port != None:
1748 webServerOSH.setIntegerAttribute('application_port', port)
1749
1750 return webServerOSH
1751
1752
1762
1763
1765 exchangeServer = createApplicationOSH('ms_exchange_server', 'Microsoft Exchange Server', host, 'Mail', 'Microsoft')
1766
1767 if credentialsId:
1768 exchangeServer.setAttribute('credentials_id', credentialsId)
1769 if applicationIp:
1770 exchangeServer.setAttribute('application_ip', applicationIp)
1771 if exchangeVersion:
1772 exchangeServer.setAttribute('application_version', exchangeVersion)
1773
1774 return exchangeServer
1775
1776
1782
1783
1785 if applicationOsh:
1786 attributeName = 'product_name'
1787 applicationClass = applicationOsh.getObjectClass()
1788 if applicationName is None:
1789 applicationName = (applicationOsh.getAttributeValue('data_name')
1790 or applicationOsh.getAttributeValue('discovered_product_name'))
1791 if applicationClass and applicationName:
1792 try:
1793 productName = getProductNameByApplicationName(applicationName)
1794 __setAttributeIfExists(applicationOsh, attributeName, productName)
1795 except:
1796
1797 pass
1798
1799
1804
1805
1807 'ObjectStateHolder, str -> None'
1808 if applicationOsh:
1809 type = applicationOsh.getObjectClass()
1810 discoveredProductName = getDiscoveredProductNameByType(type) or productName
1811 if discoveredProductName:
1812 __setAttributeIfExists(applicationOsh, 'discovered_product_name', discoveredProductName)
1813
1814
1830
1831
1840
1841
1843 - def __init__(self, className, name, vendor):
1844 self.className = className
1845 self.name = name
1846 self.vendor = vendor
1847
1848 __J2EE_SERVERS = {
1849 'glassfish': __J2eeServerDefinition('glassfishas', 'Glassfish AS', 'oracle_corp'),
1850 'jboss': __J2eeServerDefinition('jbossas', 'JBoss AS', 'jboss_group_llc'),
1851 'weblogic': __J2eeServerDefinition('weblogicas', 'WebLogic AS', 'bea_systems_ltd'),
1852 'websphere': __J2eeServerDefinition('websphereas', 'WebSphere AS', 'ibm_corp'),
1853 'oracleias': __J2eeServerDefinition('oracleias', 'Oracle iAS', 'oracle_corp')
1854 }
1855
1856
1859 self.app_server_type = StringVector()
1860 for type in type_list:
1861 self.app_server_type.add(type)
1862
1863 __J2EE_APP_SERVER = __AppServerTypeDefinition(['j2ee'])
1864 __SAP_ABAP_APP_SERVER = __AppServerTypeDefinition(['sap'])
1865 __SAP_J2EE_APP_SERVER = __AppServerTypeDefinition(['j2ee, sap'])
1866 __SIEBEL_APP_SERVER = __AppServerTypeDefinition(['siebel'])
1867
1868 __APP_SERVER_TYPES = {
1869 'j2eeserver': __AppServerTypeDefinition(['j2ee']),
1870 'jbossas': __AppServerTypeDefinition(['j2ee']),
1871 'weblogicas': __AppServerTypeDefinition(['j2ee']),
1872 'websphereas': __AppServerTypeDefinition(['j2ee']),
1873 'siebel_app_server': __AppServerTypeDefinition(['siebel']),
1874 'sap_r3_server': __AppServerTypeDefinition(['sap']),
1875 'abap_sap_central_services': __AppServerTypeDefinition(['sap']),
1876 'sap_j2ee_app_server': __AppServerTypeDefinition(['j2ee', 'sap']),
1877 'j2ee_sap_central_services': __AppServerTypeDefinition(['j2ee', 'sap'])
1878 }
1879
1880
1886
1887
1888 __APP_SYSTEM_VENDORS = {
1889 'exchangesystem': 'microsoft_corp',
1890 'tomcatcluster': 'the_apache_software_foundation',
1891 'vmware_cluster': 'v_mware_inc',
1892 'siebel_site': 'oracle_corp',
1893 'veritascluster': 'symantec_corp',
1894 'serviceguardcluster': 'hewlett_packard_co',
1895 'mscluster': 'microsoft_corp',
1896 'rac': 'oracle_corp',
1897 'oraclesystem': 'oracle_corp',
1898 'sap_system': 'sap_ag',
1899 'hana': 'sap_ag',
1900 'bobj_system':'sap_ag'}
1901
1902
1903 -def createJ2eeDomain(domainName, Framework=None, vendor=None, adminServerInfo=None):
1904 r'''
1905 @types: str, Framework, str, str -> ObjectStateHolder
1906 @deprecated: use jee.Domain and jee.ServerTopologyBuilder.buildDomainOsh
1907 method instead
1908 '''
1909 domainOSH = ObjectStateHolder('j2eedomain')
1910 domainOSH.setAttribute('data_name', domainName)
1911 setAppSystemVendor(domainOSH, vendor)
1912 return domainOSH
1913
1914
1922
1923
1924 -def createJ2EEServer(type, ipddress, port=None, hostOSH=None, serverName=None, domainName=None):
1925 """
1926 VERY IMPORTANT: despite serverName has default value(None) it is very important to set its name
1927 since this is key attribute for j2eeserver. In case it is None we set it to 'Default Server'
1928 """
1929 if not __J2EE_SERVERS.has_key(type):
1930 errorMsg = 'Invalid j2eeserver type %s' % type
1931 raise Exception, errorMsg
1932
1933 if hostOSH == None:
1934 hostOSH = createHostOSH(ipddress)
1935
1936 j2eeServer = __J2EE_SERVERS[type]
1937 serverCategory = 'J2EE Server'
1938
1939 serverOSH = createApplicationOSH(j2eeServer.className, j2eeServer.name, hostOSH, serverCategory, j2eeServer.vendor)
1940
1941 serverOSH.setAttribute('application_ip', ipddress)
1942 if port != None:
1943 serverOSH.setIntegerAttribute('application_port', int(port))
1944 serverOSH.setAttribute('j2eeserver_listenadress', ipddress)
1945
1946 if serverName == None:
1947 serverName = 'Default Server'
1948 setAdditionalKeyAttribute(serverOSH, 'j2eeserver_servername', serverName)
1949
1950 __setAttributeIfExists(serverOSH, 'application_server_type', __J2EE_APP_SERVER.app_server_type, None)
1951 if domainName is not None:
1952 __setAttributeIfExists(serverOSH, 'administration_domain', domainName, None)
1953 return serverOSH
1954
1955
1956 -def setJ2eeServerAdminDomain(serverOSH, adminDomainName):
1957 __setAttributeIfExists(serverOSH, 'administration_domain', adminDomainName, None)
1958
1959
1961 'str, str, str, str -> ObjectStateHolder'
1962 ntcmdOSH = ObjectStateHolder('ntcmd')
1963 ntcmdOSH.setAttribute('data_name', 'ntcmd')
1964 ntcmdOSH.setAttribute('application_ip', ip_address)
1965 ntcmdOSH.setAttribute('credentials_id',credentialsId)
1966 ntcmdOSH.setAttribute('language', language)
1967 ntcmdOSH.setAttribute('codepage', codePage)
1968 return ntcmdOSH
1969
1970
1972 'str, str -> ObjectStateHolder'
1973 return createTTYOSH('ssh', ip_address, port)
1974
1975
1977 'str, str -> ObjectStateHolder'
1978 return createTTYOSH('telnet', ip_address, port)
1979
1980
1982 'str, str -> ObjectStateHolder'
1983 return createTTYOSH('snmp', ip_address, port)
1984
1985
1987 'str, str, str(port) -> ObjectStateHolder'
1988 tty_obj = ObjectStateHolder(clientType)
1989 tty_obj.setAttribute('application_ip', ip_address)
1990 tty_obj.setAttribute('data_name', clientType)
1991 if port:
1992 tty_obj.setAttribute('application_port', port)
1993 return tty_obj
1994
1995
1997 'str -> ObjectStateHolder'
1998 wmiOsh = ObjectStateHolder('wmi')
1999 wmiOsh.setAttribute('application_ip', ip_address)
2000 wmiOsh.setAttribute('data_name', ClientsConsts.WMI_PROTOCOL_NAME)
2001 return wmiOsh
2002
2003
2005 category = 'Cluster'
2006 if clustName == 'Microsoft Cluster SW' and not vendor:
2007 vendor = 'microsoft_corp'
2008 elif clustName == 'HP Service Guard Cluster SW' and not vendor:
2009 vendor = 'hewlett_packard_co'
2010
2011 clusterSoftware = createApplicationOSH('failoverclustersoftware',
2012 clustName, hostOSH, category, vendor)
2013 if version:
2014 clusterSoftware.setAttribute('application_version', version)
2015 return clusterSoftware
2016
2017
2018 -def createCpuOsh(cid, hostOsh, speed=None, coreNumber=None, vendor=None, descr=None, data_name=None):
2019 '''Creates CPU OSH by specified cid and node container
2020 str, ObjectStateHolder[, long(speed MHz), int(coreNumber), str, str, str] -> ObjectStateHolder
2021 @param cid: cid - key attribute
2022 @param hostOsh: OSH instance of the container node - key attribute
2023 @raise ValueError: if key attribute CID is missing
2024 '''
2025 cpuOsh = ObjectStateHolder('cpu')
2026 if not cid:
2027 raise ValueError("Key attribute CID is missing")
2028 cpuOsh.setContainer(hostOsh)
2029 cpuOsh.setAttribute('cpu_cid', cid)
2030
2031 if vendor:
2032 cpuOsh.setAttribute('cpu_vendor', vendor)
2033 try:
2034 speed = long(speed)
2035 except:
2036 logger.warn("Invalid CPU speed value: %s" % speed)
2037 else:
2038 cpuOsh.setLongAttribute("cpu_clock_speed", speed)
2039 if data_name:
2040 cpuOsh.setAttribute('data_name', data_name)
2041 if coreNumber is not None:
2042 if str(coreNumber).isdigit() and int(coreNumber) > 0:
2043 cpuOsh.setIntegerAttribute('core_number', coreNumber)
2044 else:
2045 logger.warn("Invalid CPU core number value: %s" % coreNumber)
2046 if descr:
2047 cpuOsh.setAttribute('data_description', descr)
2048 return cpuOsh
2049
2050 ACTIVE_DIRECTORY_DOMAIN_CIT = 'activedirectorydomain'
2051 DOMAIN_CONTROLLER_CIT = 'domaincontroller'
2052
2053
2055 'str, str -> ObjectStateHolder'
2056 adOsh = ObjectStateHolder(className)
2057 adOsh.setAttribute("data_name", dataName)
2058 return adOsh
2059
2060
2062 '''
2063 Creates a new OSH that represent a configuration item of type 'className'
2064 @param className: type of CI
2065 @type className: string
2066 @param cmdbId: CI ID in UCMDB
2067 @type cmdbId: CmdbObjectId
2068 @return: new OSH instance
2069 @rtype: ObjectStateHolder
2070 '''
2071 return __createOshByCmdbId(className, cmdbId)
2072
2073
2075 '''
2076 Creates a new OSH that represent a configuration item of type 'className'
2077 @param className: type of CI
2078 @type className: string
2079 @param ucmdbId: CI ID in UCMDB
2080 @type ucmdbId: string
2081 @return: new OSH instance
2082 @rtype: ObjectStateHolder
2083 '''
2084 CmdbOIDFactory = CmdbObjectID.Factory
2085 cmdbId = CmdbOIDFactory.restoreObjectID(cmdbId)
2086 return __createOshByCmdbId(className, cmdbId)
2087
2088
2090 return ObjectStateHolder(className, cmdbId)
2091
2092
2094 """
2095 Helper function that parses a string representing a date in UTC format
2096 and returns date as java.util.Date object
2097 UTC date example: 20080517201331.843750+180
2098 """
2099 matcher = re.match('(\d{14}\.\d{3})\d{3}([+-]\d{3})$', utcDateString)
2100 if matcher:
2101 dateString = matcher.group(1)
2102 timezoneOffsetString = matcher.group(2)
2103 timezoneMillis = int(timezoneOffsetString) * 60 * 1000
2104 timezone = SimpleTimeZone(timezoneMillis, '')
2105 utcDateFormatString = 'yyyyMMddHHmmss.SSS'
2106 return getDateFromString(dateString, utcDateFormatString, timezone)
2107 else:
2108 raise ValueError("Value '%s' is not a valid UTC date" % utcDateString)
2109
2110
2111 -def getDateFromString(dateString, dateFormatString, timeZone=None, locale=Locale.ENGLISH):
2112 """
2113 Helper function that parses a date from string using specified date format, timezone and locale
2114 Timezone is java.util.TimeZone instance
2115 Locale is java.util.Locale instance, defaults to English
2116 Returns date as java.util.Date object
2117 """
2118 dateFormat = SimpleDateFormat(dateFormatString, locale)
2119 dateFormat.setLenient(0)
2120 if timeZone is not None:
2121 dateFormat.setTimeZone(timeZone)
2122 try:
2123 date = dateFormat.parse(dateString)
2124 return date
2125 except ParseException:
2126 raise ValueError("Error while parsing date string '%s'" % dateString)
2127
2128
2130 ''' CMDB class model wrapper
2131
2132 Used to request information stored in CMDB class model.
2133 Model information obtained in two ways:
2134 1. Using class model file, stored on probe (till UCMDB 9)
2135 2. Class model with changes (for UCMDB 9) obtained from service in Framework
2136 '''
2138 '''
2139 If framework instance is not specified - used one registered for
2140 current thread.
2141 '''
2142 self.__framework = framework
2143 self.__version = None
2144
2146 if not self.__framework:
2147 self.__framework = ScriptsExecutionManager.getFramework()
2148 return self.__framework
2149
2151 '''
2152 Check whether specified attribute is a key attribut for specified CIT
2153 @return: Truth or False values
2154 '''
2155 cmdbAttr = self.getAttributeDefinition(citName, attributeName)
2156 return (cmdbAttr
2157 and cmdbAttr.getQualifierByName('ID_ATTRIBUTE') is not None)
2158
2160 return ConfigFilesManagerImpl.getInstance()
2161
2163 '''
2164 Get attribute definition if such exists in CMDB model
2165 @rtype: com.mercury.topaz.cmdb.shared.classmodel.cmdbclass.attribute.CmdbAttribute
2166 @return: Definition or None
2167 '''
2168 if citName and attributeName:
2169 try:
2170 cmdbModel = self.getConfigFileManager().getCmdbClassModel()
2171 cmdbClass = cmdbModel.getClass(citName)
2172 return (cmdbClass
2173 and cmdbClass.getAttributeByName(attributeName))
2174 except:
2175 pass
2176
2178 r'''Get type definition by name. Type definition is domain specific
2179 type of attribute used in particular CIT
2180 @types: str -> com.mercury.topaz.cmdb.shared.classmodel.type.typedef.CmdbTypeDef'''
2181 cmdbModel = self.getConfigFileManager().getCmdbClassModel()
2182 return cmdbModel.getAllTypeDefs().getCmdbTypeDefByName(name)
2183
2185 '''
2186 Check whether attribute exists in the specified CIT.
2187
2188 First method checks in CMDB model using interface to probe class model file.
2189 Otherwise using Framework service (available since 8.04)
2190 @return: Truth or False value
2191 '''
2192
2193 if self.getAttributeDefinition(citName, attributeName):
2194 return 1
2195
2196 try:
2197 if self.__getFramework().getClassModelServices().IsAttributeExist(citName, attributeName):
2198 return 1
2199 except:
2200 pass
2201
2202
2203 - def setAttributeIfExists(self, osh, attributeName, attributeValue, attributeTypeStr = AppilogTypes.STRING_DEF):
2204 'osh, str, object, attribute type -> bool'
2205 if self.isExistingAttribute(osh.getObjectClass(), attributeName):
2206 if attributeTypeStr is not None:
2207 attrOsh = AttributeStateHolder(attributeName, attributeValue, attributeTypeStr)
2208 else:
2209 attrOsh = AttributeStateHolder(attributeName, attributeValue)
2210 osh.setAttribute(attrOsh)
2211 return 1
2212
2218
2219 _CMDB_CLASS_MODEL = CmdbClassModel()
2220 '''@deprecated methods'''
2221 checkAttributeExists = _CMDB_CLASS_MODEL.isExistingAttribute
2222 checkIsKeyAttribute = _CMDB_CLASS_MODEL.isKeyAttribute
2223 __setAttributeIfExists = _CMDB_CLASS_MODEL.setAttributeIfExists
2224 ''' end '''
2225
2226
2230
2231
2233 SERIAL_EXCLUDE_PATTERN = 'Not Specified|System Serial Number|To Be Filled By O\.E\.M\.|CHASSIS SERIAL NUMBER'
2234 if serialNumber:
2235 serialNumber = serialNumber.strip()
2236 if (re.match(SERIAL_EXCLUDE_PATTERN, serialNumber,
2237 re.IGNORECASE) or (serialNumber.lower() == 'none')):
2238 logger.warn('Serial number %s was ignored as invalid and set to empty value' % serialNumber)
2239 serialNumber = ''
2240 hostOsh.setAttribute('host_serialnumber', serialNumber)
2241
2242
2244 hostBuilder = HostBuilder(hostOsh)
2245 MANUFACTURER_EXCLUDE_PATTERN = 'System manufacturer|To Be Filled By O\.E\.M\.'
2246 if manufacturer:
2247 manufacturer = manufacturer.replace('_', ' ').strip()
2248 if re.search(MANUFACTURER_EXCLUDE_PATTERN ,manufacturer, re.IGNORECASE):
2249 logger.warn('Manufacturer %s was ignored as invalid and set to empty value' % manufacturer)
2250 manufacturer = ''
2251 else:
2252 if manufacturer == 'VMware, Inc.':
2253 logger.warn('Manufacturer is VMware, assuming node is virtual machine')
2254 hostBuilder.setAsVirtual(1)
2255 hostBuilder.setAttribute('host_manufacturer', manufacturer)
2256 hostBuilder.build()
2257
2258
2260 MODEL_EXCLUDE_PATTERN = 'None|System Name|System Product Name|To Be Filled By O\.E\.M\.'
2261 if model:
2262 model = model.replace('_', ' ').strip()
2263 if re.search(MODEL_EXCLUDE_PATTERN, model, re.IGNORECASE):
2264 logger.warn('Node model %s was ignored as invalid and set to empty value' % model)
2265 model = ''
2266 hostOsh.setAttribute('host_model',model)
2267
2268
2271
2272
2275
2276
2278 __setAttributeIfExists(hostOsh, 'swap_memory_size', int(swapMemorySizeInMegabytes), AppilogTypes.INTEGER_DEF)
2279
2280
2282 if (not __setAttributeIfExists(vlanOsh, 'vlan_id', int(vlanId), AppilogTypes.INTEGER_DEF)):
2283 vlanOsh.setIntegerAttribute('vlan_number', vlanId)
2284
2285
2287 if (not __setAttributeIfExists(portOsh, 'port_index', int(portNumber), AppilogTypes.INTEGER_DEF)):
2288 portOsh.setStringAttribute('port_number', str(portNumber))
2289
2290
2293
2294
2298
2299
2305
2306
2308 if remoteNumber:
2309 remoteIndex = None
2310 try:
2311 remoteIndex = int(remoteNumber)
2312 except:
2313 if not checkAttributeExists(portOsh.getObjectClass(), 'port_remote_index'):
2314 portOsh.setAttribute('port_remotestpptid', remoteNumber)
2315 else:
2316 __setAttributeIfExists(portOsh, 'port_remote_index', remoteIndex, AppilogTypes.INTEGER_DEF)
2317
2318
2323
2324
2326 winsAppOsh = createApplicationOSH('application', 'WINS server', winsHostOsh)
2327 winsAppOsh.setAttribute('application_ip', winsServerIp)
2328 return winsAppOsh
2329
2331 dhcpAppOsh = createApplicationOSH('application', 'DHCP server', dhcpHostOsh)
2332 dhcpAppOsh.setAttribute('application_ip', dhcpServerIp)
2333 return dhcpAppOsh
2334
2335
2337 'Class that represents static method'
2339 self.__call__ = self.callable = callable
2340
2341
2344 self.oshProvider = oshProvider
2345
2347 osh = self.oshProvider(*args)
2348 return HostBuilder(osh)
2349
2350
2354
2356 return getattr(self.osh, name)
2357
2360
2361
2363 '''
2364 @return: hostOsh or None
2365 @deprecated
2366 '''
2367 if hostOsh:
2368 return HostBuilder(hostOsh).build()
2369
2370
2374 '''Defines whether OSH owns defined role
2375 ObjectStateHolder -> bool
2376 '''
2377 pass
2378
2379 DEFAULT_FILTER = Filter()
2380
2381 - def __init__(self, name, alternativeBoolAttribute = None, filter = None):
2382 '(str, str, RoleDefinition.Filter) -> RoleDefinition'
2383 self.name = name
2384 self.alternativeAttribute = alternativeBoolAttribute
2385 self.filter = filter or RoleDefinition.DEFAULT_FILTER
2386
2389
2390
2391 -class OshClassEntryFilter(RoleDefinition.Filter):
2392 'Defines whether OSH class is among owners'
2393 - def __init__(self, *appropriateClasses):
2394 self.appropriateClasses = appropriateClasses
2395
2396 - def isAccepted(self, osh):
2397 return osh.getObjectClass() in self.appropriateClasses
2398
2399
2401 'Predefined role definitions that node may own'
2402
2403 VIRTUAL = RoleDefinition("virtualized_system", 'host_isvirtual')
2404 ROUTER = RoleDefinition("router", 'host_isroute', OshClassEntryFilter("router", "switchrouter"))
2405 FIREWALL = RoleDefinition("firewall", filter=OshClassEntryFilter("firewall"))
2406 ATM = RoleDefinition("atm_switch", filter=OshClassEntryFilter("atmswitch"))
2407 LAN = RoleDefinition("lan_switch", filter=OshClassEntryFilter("switch", "fcswitch"))
2408 DESKTOP = RoleDefinition("desktop", 'host_isdesktop')
2409 SERVER = RoleDefinition("server")
2410 LOAD_BALANCER = RoleDefinition("load_balancer", filter=OshClassEntryFilter('lb'))
2411 NET_PRINTER = RoleDefinition("printer", filter=OshClassEntryFilter('netprinter'))
2412
2416
2417
2419 ATTR_NODE_ROLE = "node_role"
2420 CLASS_NAME = "node"
2421
2424
2426 'str -> HostBuilder'
2427 __setAttributeIfExists(self.osh, "discovered_description", value or None)
2428 return self
2429
2436
2437 'methods setAs* are deprecated, use setRole method instead'
2440
2443
2446
2449
2452
2455
2458
2460 'str -> HostBuilder'
2461 if osName:
2462 self.osh.setAttribute('host_os', osName)
2463 self.osh.setAttribute('host_osaccuracy', '')
2464
2465 globalSettings = GeneralSettingsConfigFile.getInstance()
2466 desktopOperationalSystems = globalSettings.getPropertyStringValue(
2467 CollectorsConstants.TAG_DESKTOP_OPERATING_SYSTEMS, '')
2468 serverOperationalSystems = globalSettings.getPropertyStringValue(
2469 CollectorsConstants.TAG_SERVER_OPERATING_SYSTEMS, '')
2470 if isMatchedByRegexpList(desktopOperationalSystems, osName):
2471 self.setRole(HostRoleEnum.DESKTOP)
2472 elif isMatchedByRegexpList(serverOperationalSystems, osName):
2473 self.setRole(HostRoleEnum.SERVER)
2474 return self
2475
2479
2480 - def setRole(self, roleDef, value=1, isRoleApplied=1):
2481 'RoleDefinition, bool -> HostBuilder'
2482 if roleDef.alternativeAttribute:
2483 self.osh.setBoolAttribute(roleDef.alternativeAttribute, value)
2484 if (checkAttributeExists(self.CLASS_NAME, self.ATTR_NODE_ROLE)
2485 and isRoleApplied):
2486 list_ = StringVector((roleDef.name,))
2487 roleAttribute = AttributeStateHolder(self.ATTR_NODE_ROLE, list_)
2488 self.osh.addAttributeToList(roleAttribute)
2489 return self
2490
2491 '''
2492 @see Documentation for module methods that are used as
2493 parameter for __BuilderStaticMethod
2494 @see: HostBuilder
2495 '''
2496 HostBuilder.incompleteByIp = _HostBuilderStaticMethod(createHostOSH)
2497 HostBuilder.completeByHostKey = _HostBuilderStaticMethod(createCompleteHostOSH)
2498 HostBuilder.fromClassName = _HostBuilderStaticMethod(ObjectStateHolder)
2499
2500
2502 oshv = ObjectStateHolderVector()
2503 layer2Osh = ObjectStateHolder('layer2_connection')
2504 if macList:
2505 macList.sort()
2506 layer2Connection_id = ''
2507
2508 if localInterface:
2509 hostOsh = parentSwitch.hostOSH
2510 interfOsh = createInterfaceOSH(localInterface.ifMac, hostOsh, localInterface.ifDescr, localInterface.ifIndex, localInterface.ifType, localInterface.ifAdminStatus, localInterface.ifOperStatus, localInterface.ifSpeed, localInterface.ifName, localInterface.ifAlias)
2511 if interfOsh:
2512 layer2Connection_id += localInterface.ifMac + ":"
2513 linkOsh = createLinkOSH('member', layer2Osh, interfOsh)
2514 oshv.add(hostOsh)
2515 oshv.add(interfOsh)
2516 oshv.add(linkOsh)
2517
2518 for mac in macList:
2519 hostOsh = None
2520 if mac and mac.strip():
2521 macAddress = mac
2522 if mac.find('.') > 0:
2523 macAddress = (''.join([re.findall('..$', hex(int(x)).upper())[0] for x in mac.split('.')]).replace('X','0'))
2524 hostOsh = createCompleteHostOSH('node', macAddress)
2525 else:
2526 hostOsh = parentSwitch.hostOSH
2527 if hostOsh:
2528 interfOsh = createInterfaceOSH(macAddress, hostOsh)
2529 if interfOsh:
2530 layer2Connection_id += macAddress + ":"
2531 linkOsh = createLinkOSH('member', layer2Osh, interfOsh)
2532 oshv.add(hostOsh)
2533 oshv.add(interfOsh)
2534 oshv.add(linkOsh)
2535 if layer2Connection_id:
2536 layer2Connection_id = layer2Connection_id[:len(layer2Connection_id)-1]
2537 layer2Osh.setAttribute('layer2_connection_id', str(hash(layer2Connection_id)))
2538 oshv.add(layer2Osh)
2539 return oshv
2540
2541
2543 """
2544 Helper class that is used to extract the executable path of service from full command line.
2545 It's applicable to Windows command lines only, since we are relying on specific folder separator
2546 and are searching the first occurrence of '.exe' or '.bat' extension.
2547 Class is stateless and can be used in multiple extracts.
2548 When extraction fails exception is raised.
2549 """
2551 self.__replacements = {r"/+": r"\\"}
2552 self.__modifiers = [
2553 lambda x: x.strip(),
2554 self.__useFirstQuotedString,
2555 self.__applyReplacements]
2556
2557 self.__mainPatternTemplate = r"(\w:.+?[\\/]|\%%.+?\%%.*?[\\/]|\\\\.+?[\\])%s($|\s+.+)"
2558 self.__fileNameAnchors = [
2559 r"[^\\/]+?\.(exe|bat|cmd)",
2560
2561
2562
2563
2564
2565
2566
2567 "svchost",
2568 "mysqld(-nt)?",
2569 "TNSLSNR",
2570 "msiexec"
2571 ]
2572
2573 self.__extractors = [self.__mainExtractor]
2574
2576 matcher = re.match("\"(.+?)\".*", input)
2577 if matcher:
2578 return matcher.group(1)
2579 else:
2580 return input
2581
2583 for key, repl in self.__replacements.items():
2584 (input, count) = re.subn(key, repl, input)
2585 return input
2586
2587 - def __mainExtractor(self, input):
2588 for anchor in self.__fileNameAnchors:
2589 try:
2590 path = self.__extractWithAnchor(input, anchor)
2591 return path
2592 except ValueError:
2593 pass
2594 raise ValueError
2595
2597
2598
2599 pattern = Pattern.compile(self.__mainPatternTemplate % anchor, Pattern.CASE_INSENSITIVE)
2600 matcher = pattern.matcher(String(input))
2601 if matcher.matches():
2602 return matcher.group(1)
2603 else:
2604 raise ValueError
2605
2607 modifiedInput = input
2608 for modifier in self.__modifiers:
2609 modifiedInput = modifier(modifiedInput)
2610 for extractor in self.__extractors:
2611 try:
2612 extractedValue = extractor(modifiedInput)
2613 return extractedValue
2614 except ValueError:
2615 pass
2616 raise ValueError("Failed to extract the path from '%s'" % input)
2617
2618 SERVICE_DESCRIPTION_MAX_LENGTH = 1000
2619 SERVICE_COMMAND_LINE_MAX_LENGTH = 2500
2620
2621
2622 -def createServiceOSH(hostOsh, serviceName, serviceDescr, serviceCommand, serviceStartType=None, serviceOperatingStatus=None, serviceCanBePaused=None, serviceCanBeUninstalled=None, serviceStartUser=None):
2623 '''Creates Windows Service OSH by specified service name and node container
2624 @types: hostOsh, str, str, str[, str, str, str, str, str] -> serviceOsh
2625 '''
2626 serviceOsh = ObjectStateHolder('service')
2627 serviceOsh.setContainer(hostOsh)
2628 serviceOsh.setAttribute("data_name", serviceName)
2629
2630 if serviceDescr != None:
2631 if(len(serviceDescr) > SERVICE_DESCRIPTION_MAX_LENGTH):
2632 serviceDescr = serviceDescr[0:SERVICE_DESCRIPTION_MAX_LENGTH-1]
2633 serviceOsh.setAttribute("service_description", serviceDescr)
2634
2635 if serviceCommand != None:
2636 serviceCmdLine = serviceCommand
2637 if len(serviceCmdLine) > SERVICE_COMMAND_LINE_MAX_LENGTH:
2638 serviceCmdLine = serviceCmdLine[0:SERVICE_COMMAND_LINE_MAX_LENGTH-1]
2639 serviceOsh.setAttribute("service_commandline", serviceCmdLine)
2640 try:
2641 extractor = PathExtractor()
2642 servicePathToExec = extractor.extract(serviceCmdLine)
2643 serviceOsh.setAttribute("service_pathtoexec", servicePathToExec)
2644 except ValueError, ex:
2645 logger.debug(str(ex))
2646 if serviceStartType:
2647 serviceOsh.setAttribute("service_starttype", serviceStartType)
2648 if serviceOperatingStatus:
2649 serviceOsh.setAttribute("service_operatingstatus", serviceOperatingStatus)
2650 if serviceCanBePaused:
2651 serviceOsh.setAttribute("service_canbepaused", serviceCanBePaused)
2652 if serviceCanBeUninstalled:
2653 serviceOsh.setAttribute("service_canbeuninstalled", serviceCanBeUninstalled)
2654 if serviceStartUser:
2655 serviceOsh.setAttribute("service_startuser", serviceStartUser)
2656 return serviceOsh
2657
2658
2660 if vlanId is None:
2661 return None
2662 vlanOsh = ObjectStateHolder('vlan')
2663 ucmdbVersion = logger.Version().getVersion(ScriptsExecutionManager.getFramework())
2664
2665 if ucmdbVersion < 9:
2666 if parentOsh:
2667 vlanOsh.setContainer(parentOsh)
2668 else:
2669 logger.warn('No root container for Vlan %s' % vlanId)
2670 return None
2671 setVlanIdAttribute(vlanOsh, vlanId)
2672 if ucmdbVersion > 9.01:
2673 vlanUniqueId = None
2674 if portIdList:
2675 vlanUniqueId = str(hash(':'.join(portIdList.sort())))
2676 elif parentOsh:
2677 try:
2678 vlanUniqueId = str(hash(parentOsh.getAttributeValue('host_key')))
2679 except:
2680 pass
2681 if vlanUniqueId is None:
2682 vlanUniqueId = 1
2683 vlanOsh.setStringAttribute('vlan_unique_id', vlanUniqueId)
2684 return vlanOsh
2685