python and em cli: the enterprise management super tools

113
#C14LV #EM12c #EMCLI #Python @Seth_M_Miller [email protected] http://sethmiller.org Python and EM CLI The Enterprise Management Super Tools

Upload: seth-miller

Post on 13-May-2015

562 views

Category:

Technology


7 download

DESCRIPTION

Release 3 of Enterprise Manager gives the command line interface for EM a distinct advantage by moving the EMCLI functionality into Jython, a Java implementation of the Python programming language. This session will provide an introduction to Python and give attendees a crash course in the newest version of EMCLI so they can get started using this powerful tool in their environments right away. Learning Objectives: -- Evaluate where Python can provide solutions in other aspects of the DBA's responsibility including automating password changes and backups. -- Understand how to implement and use release 3 of EMCLI. Differentiate between the Jython architecture of release 3 versus earlier versions of EMCLI. -- Have a basic understanding of and be able to construct simple scripts in Python.

TRANSCRIPT

Page 1: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

Python and EM CLI

The Enterprise Management

Super Tools

Page 2: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgWho Am I?

• Oracle ACE• IOUG Board of Directors• Oracle University Instructor• TCOUG Vice President• RAC Attack! Ninja• Lives in St. Paul, MN

Page 3: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgOverview

• History of Python• BDFL• Jython• JSON• Python Examples• EM CLI Examples

Page 4: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgHistory

• Created by Guido Van Rossum • Influenced by ABC• Released in 1991• Named after Monty Python’s

Flying Circus

Page 5: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgBenevolent Dictator for Life (BDFL)

Page 6: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

Scripting or Programming

• Both!• Programming

languages must be compiled

• Compiled at runtime

Page 7: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJython

• Python written in Java• Released in 1997 as JPython• Replaced “C” implementation of

Python• EM CLI and WLST• No Java Experience Required

Page 8: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON

• JavaScript Object Notation• Data Interchange Standard• A collection of name/value pairs• Universal• Python object

Page 9: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgGetting Started

• Built for Ease-of-Use• Indentation Format• Interactive Interface

for VAR in myLoop: do this commandprint('This line does not \ belong in myLoop')

Page 10: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgHello World!

myvar = 'Hello World!'if myvar: print(myvar)

Hello World!

Page 11: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgHELP!

• Search for Python

help()help> STRINGSemcli> help('list_active_sessions')

Page 12: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgBasic Object Types

• String• List• Dictionary (Hash)

Page 13: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mystring = 'word word word'>>> yourstring = mystring>>> yourstring += mystring>>> yourstring'word word wordword word word'

Strings

Page 14: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

mystring = 'word word word'

Strings

Page 15: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

yourstring = mystring

Strings

Page 16: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

yourstring += mystring

Strings

Page 17: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> yourstring 'word word wordword word word'

Strings

Page 18: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mystring = 'word word word'>>> yourstring = mystring>>> yourstring += mystring>>> yourstring'word word wordword word word'

Strings

Page 19: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> oraline = 'orcl:/u01/app/oracle:N'>>> oraline.split(':')['orcl', '/u01/app/oracle', 'N']>>> orasplit = oraline.split(':')>>> if orasplit[0] == 'orcl':... print('ORACLE_HOME: ' + orasplit[1])ORACLE_HOME: /u01/app/oracle>>> while orasplit:... print(orasplit.pop())N/u01/app/oracleorcl>>> orasplit[]

Page 20: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> oraline = 'orcl:/u01/app/oracle:N'

Page 21: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> oraline.split(':')

Page 22: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> oraline.split(':') ['orcl', '/u01/app/oracle', 'N']

Page 23: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> orasplit = oraline.split(':')

Page 24: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> if orasplit[0] == 'orcl': print('ORACLE_HOME: ' + orasplit[1])ORACLE_HOME: /u01/app/oracle

Page 25: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> while orasplit: print(orasplit.pop()) N /u01/app/oracle orcl

Page 26: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> orasplit []

Page 27: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgLists – Parse /etc/oratab entries

>>> oraline = 'orcl:/u01/app/oracle:N'>>> oraline.split(':')['orcl', '/u01/app/oracle', 'N']>>> orasplit = oraline.split(':')>>> if orasplit[0] == 'orcl':... print('ORACLE_HOME: ' + orasplit[1])ORACLE_HOME: /u01/app/oracle>>> while orasplit:... print(orasplit.pop())N/u01/app/oracleorcl>>> orasplit[]

Page 28: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

Dictionaries (Hashes) Target Properties

>>> mydict = {'Product':'Enterprise Manager', 'Vendor':'Oracle', 'Acronym':'EM', 'CLI':'EM CLI'}>>> mydict['Product']'Enterprise Manager'>>> mydict2 = {'Purpose':'Alerts', 'Size':'100GB'}>>> mydict.update(mydict2)>>> mydict{'Product': 'Enterprise Manager', 'Vendor': 'Oracle', 'CLI': 'EM CLI', 'Acronym': 'EM', 'Size': '100GB', 'Purpose': 'Alerts'}>>> for a, b in mydict.items(): print('Key: ' + a + '\nValue: ' + b + '\n')Key: ProductValue: Enterprise Manager

Key: VendorValue: Oracle

Key: CLIValue: EM CLI

Key: AcronymValue: EM

Key: SizeValue: 100GB

Key: PurposeValue: Alerts

Page 29: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mydict = {'Product':'Enterprise Manager', 'Vendor':'Oracle', 'Acronym':'EM', 'CLI':'EM CLI'}

Dictionaries (Hashes) Target Properties

Page 30: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mydict['Product']'Enterprise Manager'

Dictionaries (Hashes) Target Properties

Page 31: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mydict2 = {'Purpose':'Alerts', 'Size':'100GB'}

Dictionaries (Hashes) Target Properties

Page 32: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mydict.update(mydict2)

Dictionaries (Hashes) Target Properties

Page 33: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mydict{'Product': 'Enterprise Manager‘, 'Vendor': 'Oracle', 'CLI': 'EM CLI', 'Acronym': 'EM', 'Size': '100GB', 'Purpose': 'Alerts'}

Dictionaries (Hashes) Target Properties

Page 34: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> for a, b in mydict.items(): print('Key: ' + a + '\nValue: ' + b + '\n')

Dictionaries (Hashes) Target Properties

Page 35: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

Key: VendorValue: Oracle

Key: CLIValue: EM CLI

Key: AcronymValue: EM

Key: SizeValue: 100GB

Key: PurposeValue: Alerts

Dictionaries (Hashes) Target Properties

Page 36: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

>>> mydict = {'Product':'Enterprise Manager', 'Vendor':'Oracle', 'Acronym':'EM', 'CLI':'EM CLI'}>>> mydict['Product']'Enterprise Manager'>>> mydict2 = {'Purpose':'Alerts', 'Size':'100GB'}>>> mydict.update(mydict2)>>> mydict{'Product': 'Enterprise Manager', 'Vendor': 'Oracle', 'CLI': 'EM CLI', 'Acronym': 'EM', 'Size': '100GB', 'Purpose': 'Alerts'}>>> for a, b in mydict.items(): print('Key: ' + a + '\nValue: ' + b + '\n')Key: ProductValue: Enterprise Manager

Key: VendorValue: Oracle

Key: CLIValue: EM CLI

Key: AcronymValue: EM

Key: SizeValue: 100GB

Key: PurposeValue: Alerts

Dictionaries (Hashes) Target Properties

Page 37: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgExamples

• Logon Script• Text Mode• JSON Mode• Update Properties Function• Class

Page 38: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

from emcli import *

def myLogin(): set_client_property('EMCLI_OMS_URL', 'https://em12cr3.example.com:7802/em') set_client_property('EMCLI_TRUSTALL', 'true') login(username='sysman')

myLogin()

Logon Script

Page 39: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

[oracle~] export JYTHONPATH=/home/oracle/scripts[oracle~] $ORACLE_HOME/bin/emcli

emcli>import startEnter password : **********emcli>

Logon Script

Page 40: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'TEXT')emcli>str(get_client_property('EMCLI_OUTPUT_TYPE'))'TEXT'emcli>get_targets().isJson()Falseemcli>type(get_targets().out())<type 'unicode'>emcli>type(get_targets().out().splitlines())<type 'list'>emcli>get_targets()Status Status Target Type Target Name ID4 Agent Unreachab host em12cr3.example.com le

emcli>linenum = 0emcli>for i in get_targets().out().splitlines()[0:4]: linenum += 1 print('Linenum ' + str(linenum) + ': ' + i)Linenum 1: Status Status Target Type Target NameLinenum 2: IDLinenum 3: 4 Agent Unreachab host em12cr3.example.comLinenum 4: le

Page 41: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'TEXT')

Page 42: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>str(get_client_property('EMCLI_OUTPUT_TYPE'))'TEXT'

Page 43: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>get_targets().isJson()False

Page 44: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>type(get_targets().out())<type 'unicode'>

Page 45: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>type(get_targets().out().splitlines())<type 'list'>

Page 46: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>get_targets()Status Status Target Type Target NameID4 Agent Unreachab host em12cr3.example.comle

Page 47: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>linenum = 0emcli>for i in get_targets().out().splitlines()[0:4]: linenum += 1 print('Linenum ' + str(linenum) + ': ' + i)Linenum 1: Status Status Target Type Target NameLinenum 2: IDLinenum 3: 4 Agent Unreachab host em12cr3.example.comLinenum 4: le

Page 48: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgTEXT Mode

emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'TEXT')emcli>str(get_client_property('EMCLI_OUTPUT_TYPE'))'TEXT'emcli>get_targets().isJson()Falseemcli>type(get_targets().out())<type 'unicode'>emcli>type(get_targets().out().splitlines())<type 'list'>emcli>get_targets()Status Status Target Type Target Name ID4 Agent Unreachab host em12cr3.example.com le

emcli>linenum = 0emcli>for i in get_targets().out().splitlines()[0:4]: linenum += 1 print('Linenum ' + str(linenum) + ': ' + i)Linenum 1: Status Status Target Type Target NameLinenum 2: IDLinenum 3: 4 Agent Unreachab host em12cr3.example.comLinenum 4: le

Page 49: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')emcli>str(get_client_property('EMCLI_OUTPUT_TYPE'))'JSON'emcli>get_targets().isJson()Trueemcli>type(get_targets().out())<type 'dict'>emcli>type(get_targets().out()['data'])<type 'list'>emcli>get_targets().out()['data'][0]{'Status': 'Agent Unreachable', 'Target Name': 'em12cr3.example.com', 'Status ID': '4', 'Warning': '0', 'Critical': '0', 'Target Type': 'host'}emcli>for i in get_targets().out()['data']: print('Target: ' + i['Target Name'])Target: em12cr3.example.comTarget: /EMGC_GCDomain/GCDomain/EMGC_OMS1/emgcTarget: /EMGC_GCDomain/GCDomain/EMGC_OMS1/OCMRepeater

Page 50: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

Page 51: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>str(get_client_property('EMCLI_OUTPUT_TYPE'))'JSON'

Page 52: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>get_targets().isJson()True

Page 53: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>type(get_targets().out())<type 'dict'>

Page 54: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>type(get_targets().out()['data'])<type 'list'>

Page 55: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>get_targets().out()['data'][0]{'Status': 'Agent Unreachable', 'Target Name': 'em12cr3.example.com', 'Status ID': '4', 'Warning': '0', 'Critical': '0', 'Target Type': 'host'}

Page 56: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>for i in get_targets().out()['data']: print('Target: ' + i['Target Name'])Target: em12cr3.example.comTarget: /EMGC_GCDomain/GCDomain/EMGC_OMS1/emgcTarget: /EMGC_GCDomain/GCDomain/EMGC_OMS1/OCMRepeater

Page 57: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgJSON Mode

emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')emcli>str(get_client_property('EMCLI_OUTPUT_TYPE'))'JSON'emcli>get_targets().isJson()Trueemcli>type(get_targets().out())<type 'dict'>emcli>type(get_targets().out()['data'])<type 'list'>emcli>get_targets().out()['data'][0]{'Status': 'Agent Unreachable', 'Target Name': 'em12cr3.example.com', 'Status ID': '4', 'Warning': '0', 'Critical': '0', 'Target Type': 'host'}emcli>for i in get_targets().out()['data']: print('Target: ' + i['Target Name'])Target: em12cr3.example.comTarget: /EMGC_GCDomain/GCDomain/EMGC_OMS1/emgcTarget: /EMGC_GCDomain/GCDomain/EMGC_OMS1/OCMRepeater

Page 58: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>myprops = {'LifeCycle Status':'Development', 'Location':'COLO'}emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')emcli>mytargs = list(resource='Targets').out()['data']emcli>mytargprops = list(resource='TargetProperties').out()['data']emcli>for targ in mytargs: if targ['TARGET_TYPE'] == 'oracle_database' and 'em12cr3' in targ['TARGET_NAME']: print(targ['TARGET_NAME'])orcl_em12cr3.example.com

emcli>for targ in mytargs: if 'oracle_database' in targ['TARGET_TYPE'] and 'em12cr3' in targ['TARGET_NAME']: target_name = targ['TARGET_NAME'] target_type = targ['TARGET_TYPE'] for propkey, propvalue in myprops.items(): myrec = target_name + ':' + target_type + ':' + propkey + ':' + propvalue set_target_property_value(property_records=myrec)Properties updated successfully

Properties updated successfully

Page 59: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>myprops = { 'LifeCycle Status':'Development', 'Location':'COLO'}

Page 60: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>set_client_property( 'EMCLI_OUTPUT_TYPE', 'JSON')

Page 61: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>mytargs = list( resource='Targets').out()['data']

Page 62: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>mytargprops = list( resource='TargetProperties' ).out()['data']

Page 63: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>for targ in mytargs: if targ['TARGET_TYPE'] == \ 'oracle_database' and 'em12cr3' \ in targ['TARGET_NAME']: print(targ['TARGET_NAME'])

orcl_em12cr3.example.com

Page 64: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>for targ in mytargs: if 'oracle_database' in \ targ['TARGET_TYPE'] and \ 'em12cr3' in targ['TARGET_NAME']:

Page 65: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

target_name = targ['TARGET_NAME']target_type = targ['TARGET_TYPE']

Page 66: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

for propkey, propvalue in myprops.items():

Page 67: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

for propkey, propvalue in myprops.items():

myrec = target_name + ':' + \ target_type + ':' + propkey + ':' + \ propvalue

Page 68: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

for propkey, propvalue in myprops.items():

set_target_property_value( property_records=myrec)

Properties updated successfully

Properties updated successfully

Page 69: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgUpdate Properties

emcli>myprops = {'LifeCycle Status':'Development', 'Location':'COLO'}emcli>set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')emcli>mytargs = list(resource='Targets').out()['data']emcli>mytargprops = list(resource='TargetProperties').out()['data']emcli>for targ in mytargs: if targ['TARGET_TYPE'] == 'oracle_database' and 'em12cr3' in targ['TARGET_NAME']: print(targ['TARGET_NAME'])orcl_em12cr3.example.com

emcli>for targ in mytargs: if 'oracle_database' in targ['TARGET_TYPE'] and 'em12cr3' in targ['TARGET_NAME']: target_name = targ['TARGET_NAME'] target_type = targ['TARGET_TYPE'] for propkey, propvalue in myprops.items(): myrec = target_name + ':' + target_type + ':' + propkey + ':' + propvalue set_target_property_value(property_records=myrec)Properties updated successfully

Properties updated successfully

Page 70: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgQuery Target Properties

emcli>mytargprops = list(resource='TargetProperties').out()['data'] emcli>for i in mytargprops: if i['TARGET_TYPE'] == 'oracle_database' and i['TARGET_NAME'] == \ 'orcl_em12cr3.example.com' and 'orcl_gtp' in i['PROPERTY_NAME']: print([i['PROPERTY_NAME'], i['PROPERTY_VALUE']])['orcl_gtp_os', 'Linux']['orcl_gtp_platform', 'x86_64']['orcl_gtp_target_version', '12.1.0.1.0']['orcl_gtp_location', 'COLO']['orcl_gtp_lifecycle_status', 'Development']

Page 71: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgQuery Target Properties

emcli>mytargprops = list( resource='TargetProperties' ).out()['data']

Page 72: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgQuery Target Properties

emcli>for i in mytargprops: if i['TARGET_TYPE'] == \ 'oracle_database' and \ i['TARGET_NAME'] == \ 'orcl_em12cr3.example.com' and \ 'orcl_gtp' in i['PROPERTY_NAME']: print([i['PROPERTY_NAME‘ ], i['PROPERTY_VALUE']])

Page 73: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgQuery Target Properties

['orcl_gtp_os', 'Linux']['orcl_gtp_platform', 'x86_64']['orcl_gtp_target_version', '12.1.0.1.0']['orcl_gtp_location', 'COLO']['orcl_gtp_lifecycle_status', 'Development']

Page 74: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgQuery Target Properties

emcli>mytargprops = list(resource='TargetProperties').out()['data'] emcli>for i in mytargprops: if i['TARGET_TYPE'] == 'oracle_database' and i['TARGET_NAME'] == \ 'orcl_em12cr3.example.com' and 'orcl_gtp' in i['PROPERTY_NAME']: print([i['PROPERTY_NAME'], i['PROPERTY_VALUE']])['orcl_gtp_os', 'Linux']['orcl_gtp_platform', 'x86_64']['orcl_gtp_target_version', '12.1.0.1.0']['orcl_gtp_location', 'COLO']['orcl_gtp_lifecycle_status', 'Development']

Page 75: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 76: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 77: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property( 'EMCLI_OUTPUT_TYPE', 'JSON')

Page 78: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

class mySetProperties():

Page 79: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 80: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def __init__(self, filter='.*'):

Page 81: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

self.targs = []self.filt(filter)

Page 82: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def __init__(self, filter='.*'): self.targs = [] self.filt(filter)

Page 83: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 84: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def filt(self, filter): self.targs = [] __compfilt = re.compile(filter)

Page 85: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in emcli.list( resource='Targets' ).out()['data']:

Page 86: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in emcli.list(resource='Targets').out()['data']:

if __compfilt.search( __inttarg['TARGET_NAME']): self.targs.append(__inttarg)

Page 87: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list( resource='Targets').out()['data']: if __compfilt.search( __inttarg['TARGET_NAME']): self.targs.append(__inttarg)

Page 88: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 89: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def show(self): self.targprops = emcli.list( resource='TargetProperties' ).out()['data']

Page 90: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME'))print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80))

TARGET_TYPE.....................TARGET_NAME PROPERTY_NAME.........PROPERTY_VALUE=========================================================================

Page 91: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME'])) self.__showprops(__inttarg['TARGET_GUID']) print('')

oracle_dbsys....................orcl_em12cr3.example.com_sys

Page 92: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME'])) self.__showprops(__inttarg['TARGET_GUID']) print('')

Page 93: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 94: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + \ __delim

Page 95: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in self.targs: for __propkey, __propvalue in props.items():

Page 96: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in self.targs: for __propkey, __propvalue in props.items():

__property_records = \ __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + \ __propvalue

Page 97: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in self.targs: for __propkey, __propvalue in props.items():

print('Target: ' + \ __inttarg['TARGET_NAME'] + \ ' (' + __inttarg['TARGET_TYPE'] + \ ')\n\tProperty: ' +__propkey + \ '\n\tValue: ' + __propvalue + '\n')

Page 98: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttarg in self.targs: for __propkey, __propvalue in props.items():

emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records)

Page 99: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records)

Page 100: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 101: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops[ 'PROPERTY_NAME'].split('_')

Page 102: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttargprops in self.targprops:

if (__inttargprops['TARGET_GUID'] ) == guid and ( __intpropname[0:2] == [ 'orcl', 'gtp']):

Page 103: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

for __inttargprops in self.targprops: if (__inttargprops['TARGET_GUID‘]) == guid and (__intpropname[0:2] == ['orcl', 'gtp']):

print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:] ).ljust(30, '.'), __inttargprops[ 'PROPERTY_VALUE']))

Page 104: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = __inttargprops[ 'PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID'] ) == guid and ( __intpropname[0:2] == [ 'orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:] ).ljust(30, '.'), __inttargprops[ 'PROPERTY_VALUE']))

Page 105: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

import emcliimport reemcli.set_client_property('EMCLI_OUTPUT_TYPE', 'JSON')

class mySetProperties(): def __init__(self, filter='.*'): self.targs = [] self.filt(filter) def filt(self, filter): self.targs = [] __compfilt = re.compile(filter) for __inttarg in emcli.list(resource='Targets' ).out()['data']: if __compfilt.search(__inttarg['TARGET_NAME']): self.targs.append(__inttarg) def show(self): self.targprops = emcli.list( resource='TargetProperties').out()['data'] print('%-5s%-40s%s' % (' ', 'TARGET_TYPE'.ljust(40, '.'), 'TARGET_NAME')) print('%-15s%-30s%s\n%s\n' % (' ', 'PROPERTY_NAME'.ljust(30, '.'), 'PROPERTY_VALUE', '=' * 80)) for __inttarg in self.targs: print('%-5s%-40s%s' % (' ', __inttarg['TARGET_TYPE'].ljust(40, '.'), __inttarg['TARGET_NAME']))

self.__showprops(__inttarg['TARGET_GUID']) print('') def setprops(self, props): __delim = '@#&@#&&' __subseparator = 'property_records=' + __delim for __inttarg in self.targs: for __propkey, __propvalue in props.items(): __property_records = __inttarg['TARGET_NAME'] + \ __delim + __inttarg['TARGET_TYPE'] + \ __delim + __propkey + __delim + __propvalue print('Target: ' + __inttarg['TARGET_NAME'] + ' (' + __inttarg['TARGET_TYPE'] + ')\n\tProperty: ‘ +__propkey + '\n\tValue: ' + __propvalue + '\n') emcli.set_target_property_value( subseparator=__subseparator, property_records=__property_records) def __showprops(self, guid): for __inttargprops in self.targprops: __intpropname = \ __inttargprops['PROPERTY_NAME'].split('_') if (__inttargprops['TARGET_GUID']) == guid and ( __intpropname[0:2] == ['orcl', 'gtp']): print('%-15s%-30s%s' % (' ', ' '.join(__intpropname[2:]).ljust(30, '.'), __inttargprops['PROPERTY_VALUE']))

Page 106: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

emcli>myprops = {'LifeCycle Status':'Development', 'Location':'COLO'}emcli>from mySetProperties import mySetProperties

Page 107: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

emcli>mySetProperties(filter= '^orcl_em12cr3' ).show() TARGET_TYPE.....................TARGET_NAME PROPERTY_NAME.........PROPERTY_VALUE=========================================================================

oracle_dbsys....................orcl_em12cr3.example.com_sys

oracle_database.................orcl_em12cr3.example.com os....................Linux platform..............x86_64 target version........12.1.0.1.0

Page 108: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

emcli>mySetProperties(filter= '^orcl_em12cr3.*[^(_sys)]$' ).show() TARGET_TYPE.....................TARGET_NAME PROPERTY_NAME.........PROPERTY_VALUE=========================================================================

oracle_database.................orcl_em12cr3.example.com os....................Linux platform..............x86_64 target version........12.1.0.1.0

Page 109: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

emcli>mysetp = mySetProperties( '^orcl_em12cr3.*[^(_sys)]$')

Page 110: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

emcli>mysetp.setprops(myprops)Target: orcl_em12cr3.example.com (oracle_database) Property: Location Value: COLO

Target: orcl_em12cr3.example.com (oracle_database) Property: LifeCycle Status Value: Development

Page 111: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.orgClasses

emcli>mysetp.show() TARGET_TYPE.......................TARGET_NAME PROPERTY_NAME...........PROPERTY_VALUE================================================================= oracle_database...................orcl_em12cr3.example.com os......................Linux platform................x86_64 target version..........12.1.0.1.0 location................COLO lifecycle status........Development

Page 112: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

Page 113: Python and EM CLI: The Enterprise Management Super Tools

#C14LV #EM12c #EMCLI #Python@Seth_M_Miller

[email protected]://sethmiller.org

Thank You!