Esempio n. 1
0
def postdeploy(appliances=[],
               credentials=[],
               timeout=120,
               no_check_hostname=False,
               Domain="",
               unquiesce_domain=True,
               unquiesce_appliance=False,
               postdeploy_command=None,
               save_config=True,
               web=False):
    """This is a simple script which will allow you to unquiesce
your domain or appliances after you quiesce them for a deployment.
Also this will allow you to save the config.

Parameters:

* `-a, --appliances`: The hostname(s), ip address(es), environment name(s)
or alias(es) of the appliances you would like to affect. For details
on configuring environments please see the comments in
`environments.conf` located in `$MAST_HOME/etc/default`. For details
on configuring aliases, please see the comments in `hosts.conf` located in
`$MAST_HOME/etc/default`. To pass multiple arguments to this parameter,
use multiple entries of the form `[-a appliance1 [-a appliance2...]]`
* `-c, --credentials`: The credentials to use for authenticating to the
appliances. Should be either one set to use for all appliances
or one set for each appliance. Credentials should be in the form
`username:password`. To pass multiple credentials to this parameter, use
multiple entries of the form `[-c credential1 [-c credential2...]]`.
When referencing multiple appliances with multiple credentials,
there must be a one-to-one correspondence of credentials to appliances:
`[-a appliance1 [-a appliance2...]] [-c credential1 [-c credential2...]]`
If you would prefer to not use plain-text passwords,
you can use the output of `$ mast-system xor <username:password>`.
* `-t, --timeout`: The timeout in seconds to wait for a response from
an appliance for any single request. __NOTE__ Program execution may
halt if a timeout is reached.
* `-n, --no-check-hostname`: If specified SSL verification will be turned
off when sending commands to the appliances.
* `-D, --Domain`: The domain which will be unquiesced and persisted.
* `-N, --no-unquiesce-domain`: If specified, this script will not attempt
to unquiesce the domain
* `-u, --unquiesce-appliance`: If specified, this script will attempt to
unquiesce the appliance
* `-p, --postdeploy-command`: This command will be "shelled out"
to the machine running MAST after unquiescing and saving the configuration,
use this parameter to clean up VCS artifacts and/or perform check-outs
of your deployed services or similar operations
* `--no-save-config`: If specified, the configuration will not be saved in
the application domain
* `-w, --web`: __For Internel Use Only, will be removed in future versions.
DO NOT USE.__"""
    import mast.datapower.system as system
    check_hostname = not no_check_hostname
    logger = make_logger('mast.datapower.deployment')

    env = datapower.Environment(
        appliances,
        credentials,
        timeout,
        check_hostname=check_hostname)

    if web:
        output = ""
        history = ""
    for appliance in env.appliances:
        if unquiesce_appliance:
            appliance.log_info("Attempting to unquiesce appliance")

            _out = system.unquiesce_appliance(
                appliances=[appliance.hostname],
                credentials=[appliance.credentials],
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                web=web)
            appliance.log_info(
                "Finished Unquiescing appliance")

            if web:
                output += _out[0]
                history += _out[1]
            else:
                print "Finished unquiescing appliance"

        if unquiesce_domain:
            appliance.log_info("Attempting to unquiesce domain")

            _out = system.unquiesce_domain(
                appliances=[appliance.hostname],
                credentials=[appliance.credentials],
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                Domain=Domain,
                web=web)
            appliance.log_info(
                "Finished Unquiescing domain")

            if web:
                output += _out[0]
                history += _out[1]
            else:
                print "Finished unquiescing domain"

        if save_config:
            appliance.log_info(
                "Attempting to save configuration after deployment")

            _out = system.save_config(
                appliances=[appliance.hostname],
                credentials=[appliance.credentials],
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                Domain=Domain,
                web=web)

            appliance.log_info(
                "Finished saving configuration after deployment")

            if web:
                output += _out[0]
                history += _out[1]
            else:
                print "Finished saving the configuration"

    if postdeploy_command:
        logger.info(
            "Post-Deployment command '{}' found. Executing at {}".format(
                postdeploy_command, str(Timestamp())))

        out, err = system_call(command=postdeploy_command)
        out = str(out)
        err = str(err)

        logger.info(
            "finished executing Post-Deployment command '{}' at {}., output: {}".format(
                postdeploy_command, str(Timestamp()), ";".join([out, err])))
        if web:
            results = {"postdeploy command": "{}\n\nout: {}\n\nerr: {}".format(postdeploy_command, out, err)}
            output += render_results_table(results)
        else:
            print "Finished running post-deploy command. output: {}".format(
                ";".join([out, err]))

    if web:
        return output, history
def postdeploy(appliances=[],
               credentials=[],
               timeout=120,
               no_check_hostname=False,
               Domain="",
               unquiesce_domain=True,
               unquiesce_appliance=False,
               postdeploy_command=None,
               save_config=True,
               web=False):
    """This is a simple script which will allow you to unquiesce
your domain or appliances after you quiesce them for a deployment.
Also this will allow you to save the config.

Parameters:

* `-a, --appliances`: The hostname(s), ip address(es), environment name(s)
or alias(es) of the appliances you would like to affect. For details
on configuring environments please see the comments in
`environments.conf` located in `$MAST_HOME/etc/default`. For details
on configuring aliases, please see the comments in `hosts.conf` located in
`$MAST_HOME/etc/default`. To pass multiple arguments to this parameter,
use multiple entries of the form `[-a appliance1 [-a appliance2...]]`
* `-c, --credentials`: The credentials to use for authenticating to the
appliances. Should be either one set to use for all appliances
or one set for each appliance. Credentials should be in the form
`username:password`. To pass multiple credentials to this parameter, use
multiple entries of the form `[-c credential1 [-c credential2...]]`.
When referencing multiple appliances with multiple credentials,
there must be a one-to-one correspondence of credentials to appliances:
`[-a appliance1 [-a appliance2...]] [-c credential1 [-c credential2...]]`
If you would prefer to not use plain-text passwords,
you can use the output of `$ mast-system xor <username:password>`.
* `-t, --timeout`: The timeout in seconds to wait for a response from
an appliance for any single request. __NOTE__ Program execution may
halt if a timeout is reached.
* `-n, --no-check-hostname`: If specified SSL verification will be turned
off when sending commands to the appliances.
* `-D, --Domain`: The domain which will be unquiesced and persisted.
* `-N, --no-unquiesce-domain`: If specified, this script will not attempt
to unquiesce the domain
* `-u, --unquiesce-appliance`: If specified, this script will attempt to
unquiesce the appliance
* `-p, --postdeploy-command`: This command will be "shelled out"
to the machine running MAST after unquiescing and saving the configuration,
use this parameter to clean up VCS artifacts and/or perform check-outs
of your deployed services or similar operations
* `--no-save-config`: If specified, the configuration will not be saved in
the application domain
* `-w, --web`: __For Internel Use Only, will be removed in future versions.
DO NOT USE.__"""
    import mast.datapower.system as system
    check_hostname = not no_check_hostname
    logger = make_logger('mast.datapower.deployment')

    env = datapower.Environment(appliances,
                                credentials,
                                timeout,
                                check_hostname=check_hostname)

    if web:
        output = ""
        history = ""
    for appliance in env.appliances:
        if unquiesce_appliance:
            appliance.log_info("Attempting to unquiesce appliance")

            _out = system.unquiesce_appliance(
                appliances=[appliance.hostname],
                credentials=[appliance.credentials],
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                web=web)
            appliance.log_info("Finished Unquiescing appliance")

            if web:
                output += _out[0]
                history += _out[1]
            else:
                print "Finished unquiescing appliance"

        if unquiesce_domain:
            appliance.log_info("Attempting to unquiesce domain")

            _out = system.unquiesce_domain(appliances=[appliance.hostname],
                                           credentials=[appliance.credentials],
                                           timeout=timeout,
                                           no_check_hostname=no_check_hostname,
                                           Domain=Domain,
                                           web=web)
            appliance.log_info("Finished Unquiescing domain")

            if web:
                output += _out[0]
                history += _out[1]
            else:
                print "Finished unquiescing domain"

        if save_config:
            appliance.log_info(
                "Attempting to save configuration after deployment")

            _out = system.save_config(appliances=[appliance.hostname],
                                      credentials=[appliance.credentials],
                                      timeout=timeout,
                                      no_check_hostname=no_check_hostname,
                                      Domain=Domain,
                                      web=web)

            appliance.log_info(
                "Finished saving configuration after deployment")

            if web:
                output += _out[0]
                history += _out[1]
            else:
                print "Finished saving the configuration"

    if postdeploy_command:
        logger.info(
            "Post-Deployment command '{}' found. Executing at {}".format(
                postdeploy_command, str(Timestamp())))

        out, err = system_call(command=postdeploy_command)
        out = str(out)
        err = str(err)

        logger.info(
            "finished executing Post-Deployment command '{}' at {}., output: {}"
            .format(postdeploy_command, str(Timestamp()), ";".join([out,
                                                                    err])))
        if web:
            from mast.plugin_utils.plugin_utils import render_results_table
            results = {
                "postdeploy command":
                "{}\n\nout: {}\n\nerr: {}".format(postdeploy_command, out, err)
            }
            output += render_results_table(results)
        else:
            print "Finished running post-deploy command. output: {}".format(
                ";".join([out, err]))

    if web:
        return output, history
Esempio n. 3
0
def deploy(
        appliances=[],
        credentials=[],
        timeout=180,
        no_check_hostname=False,
        Domain=[],
        file_in=None,
        deployment_policy="",
        dry_run=False,
        overwrite_files=True,
        overwrite_objects=True,
        rewrite_local_ip=True,
        object_audit=True,
        out_dir='tmp',
        format='ZIP',
        quiesce_domain=True,
        quiesce_appliance=False,
        quiesce_timeout=120,
        web=False):

    """Perform a deployment/migration of a service/object to an IBM DataPower
appliance. This script will try to perform the deployment/migration in a
manner consistent with best practices.

__WARNING__: There is an inherent security risk involved in this script,
in order to allow the most flexible integration with various
Version Control Systems possible, we allow a pre-deployment
hook and a post-deployment hook which will be "shelled out"
to your operating system. For this reason PLEASE be sure to
run this script (and the MAST Web GUI server) as a user with
appropriate permissions.

DO NOT RUN AS ROOT!!!

Parameters:

* `-a, --appliances`: The hostname(s), ip address(es), environment name(s)
or alias(es) of the appliances you would like to affect. For details
on configuring environments please see the comments in
`environments.conf` located in `$MAST_HOME/etc/default`. For details
on configuring aliases, please see the comments in `hosts.conf` located in
`$MAST_HOME/etc/default`. To pass multiple arguments to this parameter,
use multiple entries of the form `[-a appliance1 [-a appliance2...]]`
* `-c, --credentials`: The credentials to use for authenticating to the
appliances. Should be either one set to use for all appliances
or one set for each appliance. Credentials should be in the form
`username:password`. To pass multiple credentials to this parameter, use
multiple entries of the form `[-c credential1 [-c credential2...]]`.
When referencing multiple appliances with multiple credentials,
there must be a one-to-one correspondence of credentials to appliances:
`[-a appliance1 [-a appliance2...]] [-c credential1 [-c credential2...]]`
If you would prefer to not use plain-text passwords,
you can use the output of `$ mast-system xor <username:password>`.
* `-t, --timeout`: The timeout in seconds to wait for a response from
an appliance for any single request. __NOTE__ Program execution may
halt if a timeout is reached.
* `-n, --no-check-hostname`: If specified SSL verification will be turned
off when sending commands to the appliances.
* `-D, --Domain`: The domain to import the configuration into, also the
domain to quiesce if `--no-quiesce-domain` is not specified.
* `-f, --file-in`: This is the configuration file that you are
importing. It must be in the format specified by the format
parameter.
* `-d, --deployment-policy`: The deployment policy to apply to the
import, must already exist on the appliance
* `--dry-run`: If specified, a dry-run will be performed instead of
an actual import
* `-N, --no-overwrite-files`: If specified, no files will be over-
written during the import
* `--no-overwrite-objects`: If specified, no objects will be over-
written during import
* `--no-rewrite-local-ip`: If specified local ip addresses will not
be rewritten on import
* `--no-object-audit`: If specified, an object audit will not be
performed. An object audit is  a diff between the running and
persisted configuration
* `-o, --out-dir`: This is where to place the artifacts generated
by this script
* `-F, --format`: The format of the configuration file, must be
either "ZIP" or "XML".
* `--no-quiesce-domain`: If specified, the domain will not be quiesced
prior to the deployment.
* `-q, --quiesce-appliance`: If specified, the appliance will be
quiesced prior to the deployment
* `-Q, --quiesce-timeout`: This is the amount of time for the appliance
to wait before beginning the quiescence procedure.
* `-w, --web`: __For Internel Use Only, will be removed in future versions.
DO NOT USE.__"""
    import mast.datapower.system as system
    from mast.datapower.developer import _import

    logger = make_logger('mast.datapower.deployment')
    if web:
        output = ""
        history = ""

    check_hostname = not no_check_hostname
    env = datapower.Environment(
        appliances,
        credentials,
        timeout,
        check_hostname=check_hostname)

    for appliance in env.appliances:
        appliance.log_info("Deployment started on {}".format(
            appliance.hostname))

        # Quiesce Domain
        if quiesce_domain:
            logger.info(
                "Quiescing domain {} before deployment at {}".format(
                    Domain, str(Timestamp())))

            _out = system.quiesce_domain(
                appliances=[appliance.hostname],
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                Domain=Domain,
                quiesce_timeout=quiesce_timeout,
                web=web)

            logger.info(
                "Finished quiescing domain {} before deployment at {}".format(
                    Domain, str(Timestamp())))

            sleep(quiesce_timeout)

            if web:
                output += _out[0]
                history += _out[1]

        # Quiesce Appliance
        if quiesce_appliance:
            logger.info(
                "Quiescing appliances before deployment at {}".format(
                    str(Timestamp())))

            _out = system.quiesce_appliance(
                appliances=appliance.hostname,
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                quiesce_timeout=quiesce_timeout,
                web=web)

            logger.info(
                "Finished quiescing appliances before deployment at {}".format(
                    str(Timestamp())))

            sleep(quiesce_timeout)

            if web:
                output += _out[0]
                history += _out[1]

        appliance.log_info("Attempting to import configuration at '{}'".format(
            str(Timestamp())))

        file_out = os.path.join(
            out_dir, '{}-deployment_results.txt'.format(appliance.hostname))

        # import configuration
        _out = _import(
            appliances=[appliance.hostname],
            credentials=credentials,
            timeout=timeout,
            no_check_hostname=no_check_hostname,
            Domain=Domain,
            file_in=file_in,
            deployment_policy=deployment_policy,
            dry_run=dry_run,
            overwrite_files=overwrite_files,
            overwrite_objects=overwrite_objects,
            rewrite_local_ip=rewrite_local_ip,
            source_type=format,
            out_dir=out_dir,
            web=web)


        if web:
            output += _out[0]
            history += _out[1]

        appliance.log_info("Finished importing configuration at {}".format(
            str(Timestamp())))

        # unquiesce domain
        if quiesce_domain:
            appliance.log_info("Attempting to unquiesce domain")

            _out = system.unquiesce_domain(
                appliances=[appliance.hostname],
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                Domain=Domain,
                web=web)

            appliance.log_info("Finished unquiescing domain")

            if web:
                output += _out[0]
                history += _out[1]

        # unquiesce appliance
        if quiesce_appliance:
            logger.info(
                "Quiescing appliances before deployment at {}".format(
                    str(Timestamp())))

            _out = system.unquiesce_appliance(
                appliances=[appliance.hostname],
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                web=web)

            logger.info(
                "Finished quiescing appliances before deployment at {}".format(
                    str(Timestamp())))

            if web:
                output += _out[0]
                history += _out[1]

        if object_audit:
            appliance.log_info(
                "Post-Deployment Object audit started at {}".format(
                    str(Timestamp())))

            _out = system.objects_audit(
                appliances=[appliance.hostname],
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                out_dir=out_dir,
                web=web)

            appliance.log_info(
                "Post-Deployment Object audit finished at {}".format(
                    str(Timestamp())))

            if web:
                output += _out[0]
                history += _out[1]

    if web:
        return output, history
def deploy(appliances=[],
           credentials=[],
           timeout=180,
           no_check_hostname=False,
           Domain=[],
           file_in=None,
           deployment_policy="",
           dry_run=False,
           overwrite_files=True,
           overwrite_objects=True,
           rewrite_local_ip=True,
           object_audit=True,
           out_dir='tmp',
           format='ZIP',
           quiesce_domain=True,
           quiesce_appliance=False,
           quiesce_timeout=120,
           web=False):
    """Perform a deployment/migration of a service/object to an IBM DataPower
appliance. This script will try to perform the deployment/migration in a
manner consistent with best practices.

__WARNING__: There is an inherent security risk involved in this script,
in order to allow the most flexible integration with various
Version Control Systems possible, we allow a pre-deployment
hook and a post-deployment hook which will be "shelled out"
to your operating system. For this reason PLEASE be sure to
run this script (and the MAST Web GUI server) as a user with
appropriate permissions.

DO NOT RUN AS ROOT!!!

Parameters:

* `-a, --appliances`: The hostname(s), ip address(es), environment name(s)
or alias(es) of the appliances you would like to affect. For details
on configuring environments please see the comments in
`environments.conf` located in `$MAST_HOME/etc/default`. For details
on configuring aliases, please see the comments in `hosts.conf` located in
`$MAST_HOME/etc/default`. To pass multiple arguments to this parameter,
use multiple entries of the form `[-a appliance1 [-a appliance2...]]`
* `-c, --credentials`: The credentials to use for authenticating to the
appliances. Should be either one set to use for all appliances
or one set for each appliance. Credentials should be in the form
`username:password`. To pass multiple credentials to this parameter, use
multiple entries of the form `[-c credential1 [-c credential2...]]`.
When referencing multiple appliances with multiple credentials,
there must be a one-to-one correspondence of credentials to appliances:
`[-a appliance1 [-a appliance2...]] [-c credential1 [-c credential2...]]`
If you would prefer to not use plain-text passwords,
you can use the output of `$ mast-system xor <username:password>`.
* `-t, --timeout`: The timeout in seconds to wait for a response from
an appliance for any single request. __NOTE__ Program execution may
halt if a timeout is reached.
* `-n, --no-check-hostname`: If specified SSL verification will be turned
off when sending commands to the appliances.
* `-D, --Domain`: The domain to import the configuration into, also the
domain to quiesce if `--no-quiesce-domain` is not specified.
* `-f, --file-in`: This is the configuration file that you are
importing. It must be in the format specified by the format
parameter.
* `-d, --deployment-policy`: The deployment policy to apply to the
import, must already exist on the appliance
* `--dry-run`: If specified, a dry-run will be performed instead of
an actual import
* `-N, --no-overwrite-files`: If specified, no files will be over-
written during the import
* `--no-overwrite-objects`: If specified, no objects will be over-
written during import
* `--no-rewrite-local-ip`: If specified local ip addresses will not
be rewritten on import
* `--no-object-audit`: If specified, an object audit will not be
performed. An object audit is  a diff between the running and
persisted configuration
* `-o, --out-dir`: This is where to place the artifacts generated
by this script
* `-F, --format`: The format of the configuration file, must be
either "ZIP" or "XML".
* `--no-quiesce-domain`: If specified, the domain will not be quiesced
prior to the deployment.
* `-q, --quiesce-appliance`: If specified, the appliance will be
quiesced prior to the deployment
* `-Q, --quiesce-timeout`: This is the amount of time for the appliance
to wait before beginning the quiescence procedure.
* `-w, --web`: __For Internel Use Only, will be removed in future versions.
DO NOT USE.__"""
    import mast.datapower.system as system
    from mast.datapower.developer import _import

    logger = make_logger('mast.datapower.deployment')
    if web:
        output = ""
        history = ""

    check_hostname = not no_check_hostname
    env = datapower.Environment(appliances,
                                credentials,
                                timeout,
                                check_hostname=check_hostname)

    for appliance in env.appliances:
        appliance.log_info("Deployment started on {}".format(
            appliance.hostname))

        # Quiesce Domain
        if quiesce_domain:
            logger.info("Quiescing domain {} before deployment at {}".format(
                Domain, str(Timestamp())))

            _out = system.quiesce_domain(appliances=[appliance.hostname],
                                         credentials=credentials,
                                         timeout=timeout,
                                         no_check_hostname=no_check_hostname,
                                         Domain=Domain,
                                         quiesce_timeout=quiesce_timeout,
                                         web=web)

            logger.info(
                "Finished quiescing domain {} before deployment at {}".format(
                    Domain, str(Timestamp())))

            sleep(quiesce_timeout)

            if web:
                output += _out[0]
                history += _out[1]

        # Quiesce Appliance
        if quiesce_appliance:
            logger.info("Quiescing appliances before deployment at {}".format(
                str(Timestamp())))

            _out = system.quiesce_appliance(
                appliances=appliance.hostname,
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                quiesce_timeout=quiesce_timeout,
                web=web)

            logger.info(
                "Finished quiescing appliances before deployment at {}".format(
                    str(Timestamp())))

            sleep(quiesce_timeout)

            if web:
                output += _out[0]
                history += _out[1]

        appliance.log_info("Attempting to import configuration at '{}'".format(
            str(Timestamp())))

        file_out = os.path.join(
            out_dir, '{}-deployment_results.txt'.format(appliance.hostname))

        # import configuration
        _out = _import(appliances=[appliance.hostname],
                       credentials=credentials,
                       timeout=timeout,
                       no_check_hostname=no_check_hostname,
                       Domain=Domain,
                       file_in=file_in,
                       deployment_policy=deployment_policy,
                       dry_run=dry_run,
                       overwrite_files=overwrite_files,
                       overwrite_objects=overwrite_objects,
                       rewrite_local_ip=rewrite_local_ip,
                       source_type=format,
                       out_dir=out_dir,
                       web=web)

        if web:
            output += _out[0]
            history += _out[1]

        appliance.log_info("Finished importing configuration at {}".format(
            str(Timestamp())))

        # unquiesce domain
        if quiesce_domain:
            appliance.log_info("Attempting to unquiesce domain")

            _out = system.unquiesce_domain(appliances=[appliance.hostname],
                                           credentials=credentials,
                                           timeout=timeout,
                                           no_check_hostname=no_check_hostname,
                                           Domain=Domain,
                                           web=web)

            appliance.log_info("Finished unquiescing domain")

            if web:
                output += _out[0]
                history += _out[1]

        # unquiesce appliance
        if quiesce_appliance:
            logger.info("Quiescing appliances before deployment at {}".format(
                str(Timestamp())))

            _out = system.unquiesce_appliance(
                appliances=[appliance.hostname],
                credentials=credentials,
                timeout=timeout,
                no_check_hostname=no_check_hostname,
                web=web)

            logger.info(
                "Finished quiescing appliances before deployment at {}".format(
                    str(Timestamp())))

            if web:
                output += _out[0]
                history += _out[1]

        if object_audit:
            appliance.log_info(
                "Post-Deployment Object audit started at {}".format(
                    str(Timestamp())))

            _out = system.objects_audit(appliances=[appliance.hostname],
                                        credentials=credentials,
                                        timeout=timeout,
                                        no_check_hostname=no_check_hostname,
                                        out_dir=out_dir,
                                        web=web)

            appliance.log_info(
                "Post-Deployment Object audit finished at {}".format(
                    str(Timestamp())))

            if web:
                output += _out[0]
                history += _out[1]

    if web:
        return output, history