Table 4-3 provides an analysis of each line of the code.
Table 4-3 Line-by_Line Script Analysis
Lines | Description |
---|---|
1 |
Imports all EM CLI verbs, and imports VerbExecutionError. |
2 |
Imports Jython libraries. |
4-9 |
Sets variables:
|
10 |
Defines input arguments. |
11-15 |
Defines the message displayed to the user if they run the script with invalid or missing arguments: Usage: promote_discovered_dbs.py [-help][-all] Add all discovered Single Instance DBs[-targets <target1:target2:...] Add only targets listed |
17-41 |
Defines a For loop that checks that the input variables (defined in lines 4 to 9) are valid and present, otherwise the script terminates and displays the message defined in lines 11-15. |
43-50 |
Defines an If statement to check that the user doesn't provide the |
52-58 |
Defines an If statement to check that user provides the user name, password, and URL of Enterprise Manager when running the script. If any of these arguments are missing, then the scripts terminates and displays the message defined in lines 11-15. |
60-62 |
Necessary connection to OMS to retrieve all targets. Before connecting to the OMS, you must set the OMS connection details using the set_client_property() function. This sets the OMS URL to https://myoms.com/em and enables the client to trust all certificates. Note that none of these details are stored in disk. These details are stored in memory and only last for a single script execution. For more information on client properties, enter help('client_properties') from the interactive shell. You can define EMCLI_OMS_URL and EMCLI_TRUSTALL variables as environment variables if you do not want to set these in your script. If you have downloaded certificates somewhere, you can also use the environment variable EMCLI_CERT_LOC to point to the certificate directory. In this case, you do not need EMCLI_TRUSTALL. For more information, see Interactive Mode — Connecting to an Oracle Management Server (OMS). |
63 |
Provides a login to the OMS. You can remove this if you have set up EM CLI with autologin. For more information about setup and autologin, see Downloading and Deploying the EM CLI Client with the Script Option and the setup and the login verbs. |
65 |
Defines a variable for the credential string required for monitoring targets. |
67 |
Defines an if statement to determine if the |
68 |
Sets the value for target_params |
69 |
Sets the values for target_array, using the targets (where the list of targets is defined by targetparams), unmanaged, and properties parameters of the get_targets verb. When it is set for the first target, the script then moves on to the next target. |
70-71 |
Defines an else if statement to set the values for target_array if the -all option is provided when running the script, using the targets, unmanaged, and properties parameters of the get_targets verb. When it is set for the first target, the script then moves on to the next target. |
72-74 |
Defines an else statement in case the -targets or -all options are not provided when running the script. If this happens, the script terminates and displays the message defined in lines 11-15. |
76-78 |
Determines if there is data in the array, and if there is data, the script displays a message similar to the following:
|
80-82 |
Extracts the host name from the host information |
83-88 |
Adds the targets to the Management Repository using the add_target verb and displays the following message: Succeeded If the script fails to add targets to the Management Repository, then it displays the following message: Failed |
90 |
From line 76, if there are no targets in the array, the script terminates, and displays the following message to the user: INFO: There are no targets to be promoted. Please verify the targets in Enterprise Manager webpages.Logout successful |