So in this blog we expand on the previous blogs to enable a OEM group to be created and for that group to have the targets added based on certain target properties.
To recap on the original script follow this link:
So the new script has a few revisions on it. I will just pull out the key parts of the Jython script.
def get_target_list(): l_sql = "select target_name from mgmt$target_properties where property_value = '" +v_tier_description + "' and property_name = 'udtp_3' and target_type='oracle_database'" return obj
Firstly when I pull back the target names I have added an additional item to a where clause. This ensures that when we look for the ‘Tier Names’ in the specific property category of udtp_3. As target properties are free text there could be other targets with other properties and property values like our tier names, unlikely I know but it could happen.
The next section below takes an input for a group name and then creates the group based on the targets select.
v_group_name = raw_input("Specify Your Group Name: ") print "You Specified: " +v_group_name l_target_list_grp = get_target_list_grp() for target_list_grp in l_target_list_grp.out()['data']: tng = target_list_grp['TARGET_NAME'] print "Target String: " +tng create_group(name=v_group_name,add_targets=tng)
However there are a couple of things to note:
- You can’t create an empty group
- If you want to add members to a group in one statement they have to be in the format “db1:oracle_database;db2:oracle_database”. Therefore to get around this problem we reselect the targets using an analytic function. This creates a list of targets into a single row with the correct syntax for the create group emcli verb.
def get_target_list_grp(): l_sql = "select LISTAGG(target_name||':oracle_database',';') WITHIN GROUP (order by target_name) target_name from mgmt$target_properties where property_value = '" +v_tier_description + "' and property_name = 'udtp_3' and target_type='oracle_database'" return obj
This is the secondary target list which as you can see uses the LISTAGG function to generate the single row.
So now we have a script which will:
- Show a distinct list of property values against a given target type and property type, in this case oracle_database and tier
- Allow you to select a particular tier and will show you all the given targets
- Allow you to specify a name for a new group
- Add those targets into that group based on the property value and type
So that is how you can use emcli and Jython to make dynamic scripts and groups.