Python script to migrate hooks from PowerShell version 2 to host's default powerShell version.
Overview
With 6.0.3.0, the Delphix Engine will use the default PowerShell version installed on the host (hereinafter referred as default PowerShell) to perform all its operations, also the new hooks and hook templates can be created using the default PowerShell. The existing hooks and hook templates on the engine will continue functioning using PowerShell version 2, and there will be an option to migrate them to use default PowerShell.
The article intends to introduce a Python script that can be used to migrate all the hooks and hook templates on the engine to default PowerShell. The motivation behind writing the script is to save the manual effort required in doing the migration via the UI or CLI.
migrate_mssql_hooks_and_hook_templates.py .
Requirements for running the script
The requirements for running the script are as follows, they are the same as running any Python script in general.
The machine where the script is run should have Python installed.
Relevant link: https://www.python.org/downloads/
The script is supported for both Python 2 and Python 3 release.
The machine where the script is run should have the
delphixpy
Python package installed.Relevant link: https://pypi.org/project/delphixpy/
python.org documentation on installing packages and creating Python environments: Installing packages using pip and virtual environments.
If the package is already installed, it should be upgraded to the latest version, the minimum
delphixpy
version required to run the script is 1.11.3.0.
The Delphix Engine should be accessible from the machine where the script is run since the script makes API requests to the Delphix Engine to perform the migration,
The easiest way to verify the same is to use the ping command.
Functionalities of the script
The script can migrate the hooks and hook templates in the Delphix Engine to run with default PowerShell.
The script can also migrate the hooks and hook templates back to PowerShell version 2.
It is possible to migrate only the hooks or only the hook templates.
If INSTALLEDPOWERSHELL feature flag is enabled on the Delphix Engine, the script will disable the same.
The script parameters and usage
Script parameter | Description | Type | Possible values | Default value |
---|---|---|---|---|
| Displays the description and usage details of the parameters for the script on the terminal | Optional | Not applicable | Not applicable |
| The Delphix Engine host address. | Required | Not applicable | Not applicable |
| The username for System Administrator user to log into the Delphix Engine. | Required | Not applicable | Not applicable |
| The password for System Administrator user to log into the Delphix Engine. | Required | Not applicable | Not applicable |
| The username for Engine Administrator user to log into the Delphix Engine. | Required | Not applicable | Not applicable |
| The password for Engine Administrator user to log into the Delphix Engine. | Required | Not applicable | Not applicable |
| Migrates all the hooks to PowerShell Version two. | Optional | default, ps2 | default |
| Migrates all the hook templates to PowerShell Version two. | Optional | default, ps2 | default |
| Migrates only the hook or only the hook templates. Input "hooks" for migrating only the hooks, whereas input "templates" for migrating only the hook templates | Optional | hooks, templates, hooks-and-templates | hooks-and-templates |
| In case there is an error executing the script, prints the Python stack trace required for debugging. | Optional | Not applicable | Not applicable |
Command examples
Displaying the description and usage details of the parameters for the script on the terminal
CODEpython <path to the script> --help
An example command for migrating all the hook and hook templates to default PowerShell version:
CODEpython <path to the script> --engine-addr engine.delphix.com --sys-admin-usr sysadmin --sys-admin-pwd sysadmin --admin-usr admin --admin-pwd delphix
An example command for migrating all the hook and hook templates to PowerShell version 2:
CODEpython <path to the script> --engine-addr engine.delphix.com --sys-admin-usr sysadmin --sys-admin-pwd sysadmin --admin-usr admin --admin-pwd delphix --hook-ps-version ps2 --hook-templ-ps-version ps2
Please note that this will migrate all the hooks and hook templates in the Delphix Engine to PowerShell version two, the script does not have the functionality to perform the migration for specific hooks or hook templates.
An example command for migrating only the hook templates:
CODEpython <path to the script> --engine-addr engine.delphix.com --sys-admin-usr sysadmin --sys-admin-pwd sysadmin --admin-usr admin --admin-pwd delphix --migrate-only templates
An example command for running the script in debug mode:
CODEpython <path to the script> --engine-addr engine.delphix.com --sys-admin-usr sysadmin --sys-admin-pwd sysadmin --admin-usr admin --admin-pwd delphix --debug
Common errors while running the script:
If the Delphix engine is not accessible from the machine where the script is run, the connectivity test run by the script prior to running the migration will fail, and the following error will be thrown:
CODEError occurred while connecting to the engine via the given Delphix System Administrator user: [Errno 8] nodename nor servname provided, or not known Error occurred while connecting to the engine via the given Engine Administrator user: [Errno 8] nodename nor servname provided, or not known
The connectivity test run by the script prior to running the migration will fail if the value of the required parameters provided is not correct, and the following error will be thrown:
CODEError occurred while connecting to the engine via the given Engine Administrator user: HTTP status was 401 when doing POST '{"username": "admin", "password": "blah", "type": "LoginRequest", "target": "DOMAIN"}' to '/resources/json/delphix/login': {"type":"ErrorResult","status":"ERROR","error":{"type":"APIError","details":"Invalid username or password.","action":"Try with a different set of credentials.","id":"exception.webservices.login.failed","commandOutput":null,"diagnoses":[]}}
If for some reason, the script execution stops in between before migrating all the hooks and hook templates, it’s perfectly fine to run the script again; each time the script is run, the hooks and hook templates will be migrated to the specified PowerShell version.