Beispiel #1
0
 def _get_notification_message_done(app, elb_name=None, elb_dns=None):
     app_name = get_app_friendly_name(app)
     as_name = app['autoscale']['name']
     if elb_name and elb_dns:
         notif = (
             "Blue/green preparation done for [{0}] by creating "
             "the temporary ELB [{1}/{2}] attached to the AutoScale '{3}'".
             format(app_name, elb_name, elb_dns, as_name))
     else:
         notif = (
             "Blue/green preparation done for [{0}] with AutoScale '{1}'".
             format(app_name, as_name))
     return _green(notif)
Beispiel #2
0
    def _destroy_instances(self):
        log(_green("STATE: Started"), self._log_file)
        log(" CONF: Region: {0}".format(self._app['region']), self._log_file)

        try:
            log(
                _yellow(
                    " INFO: Destroy all EC2 instances related to app {0} [{1}]"
                    .format(get_app_friendly_name(self._app),
                            self._app['_id'])), self._log_file)
            destroy_ec2_instances(self._cloud_connection, self._app,
                                  self._log_file)

            self._worker.update_status(
                "done",
                message="Instance deletion OK: [{0}]".format(
                    self._app['name']))
            log(_green("STATE: End"), self._log_file)
        except Exception as e:
            self._worker.update_status(
                "failed",
                message="Destroy all instances Failed: [{0}]\n{1}".format(
                    self._app['name'], str(e)))
            log(_red("STATE: End"), self._log_file)
Beispiel #3
0
 def _get_notification_message_done(app):
     notif = "Blue/green purge done for [{0}] [{1}]".format(
         get_app_friendly_name(app), app['_id'])
     return _green(notif)
Beispiel #4
0
 def _get_notification_message_aborted(app, msg):
     notif = "Blue/green purge aborted for [{0}] : {1}".format(
         get_app_friendly_name(app), msg)
     return _yellow(notif)
Beispiel #5
0
 def _get_notification_message_failed(app, msg):
     notif = "Blue/green purge failed for [{0}] : {1}".format(
         get_app_friendly_name(app), msg)
     return _red(notif)
Beispiel #6
0
 def _get_notification_message_failed(online_app, offline_app, e):
     app_name = get_app_friendly_name(online_app)
     notif = "Blue/green preparation failed for [{0}] between [{1}] and [{2}]: {3}".format(
         app_name, online_app['_id'], offline_app['_id'], str(e))
     return _red(notif)
    def execute(self):
        try:
            log(_green("STATE: Started"), self._log_file)
            rolling_update_strategy = self._job['options'][
                0] if 'options' in self._job and len(
                    self._job['options']) > 0 else None

            as_conn = self._cloud_connection.get_connection(
                self._app['region'], ['autoscaling'], boto_version='boto3')
            if not self._app['autoscale']['name'] or not check_autoscale_exists(
                    self._cloud_connection, self._app['autoscale']['name'],
                    self._app['region']):
                log(
                    _yellow(
                        " INFO: No AutoScale specified, this command will destroy and recreate standalone instances"
                    ), self._log_file)

                destroyed_instances_info = destroy_ec2_instances(
                    self._cloud_connection, self._app, self._log_file,
                    "running")
                destroyed_count = len(destroyed_instances_info)
                if destroyed_count == 0:
                    self._worker.update_status(
                        "aborted",
                        message=
                        "Re-create instances aborted, no instances found: [{0}]"
                        .format(self._app['name']))
                    return

                log(
                    _yellow(
                        " INFO: Waiting for instances to be destroyed before re-creating them with the same network parameters."
                    ), self._log_file)
                while not test_ec2_instance_status(
                        self._cloud_connection, self._app['region'],
                    [host['id']
                     for host in destroyed_instances_info], "terminated"):
                    log("Waiting 10s", self._log_file)
                    time.sleep(10)

                x = 0
                while x < destroyed_count:
                    create_ec2_instance(
                        self._cloud_connection, self._app, self._color,
                        self._config,
                        destroyed_instances_info[x]['private_ip_address'],
                        destroyed_instances_info[x]['subnet_id'],
                        self._log_file)
                    x += 1

                self._worker.update_status(
                    "done",
                    message="Re-create instances OK: [{0}]".format(
                        self._app['name']))
                log(_green("STATE: End"), self._log_file)
            else:
                if rolling_update_strategy:
                    log(
                        _yellow(
                            " INFO: Destroy all EC2 instances related to app {0} [{1}] using rolling update strategy ({2})"
                            .format(get_app_friendly_name(self._app),
                                    self._app['_id'],
                                    rolling_update_strategy)), self._log_file)
                else:
                    log(
                        _yellow(
                            " INFO: Destroy all EC2 instances related to app {0} [{1}] and let the AutoScale ({2}) recreate them"
                            .format(get_app_friendly_name(self._app),
                                    self._app['_id'],
                                    self._app['autoscale']['name'])),
                        self._log_file)

                rollup = RollingUpdate(self._cloud_connection, self._app,
                                       self._app['safe-deployment'],
                                       self._log_file)
                rollup.do_rolling(rolling_update_strategy)

                self._worker.update_status(
                    "done",
                    message="Re-create instances OK: [{0}]".format(
                        self._app['name']))
                log(_green("STATE: End"), self._log_file)

        except Exception as e:
            self._worker.update_status(
                "failed",
                message="Re-create instances Failed: [{0}]\n{1}".format(
                    self._app['name'], str(e)))
            log(_red("STATE: END"), self._log_file)
Beispiel #8
0
 def _get_notification_message_done(online_app, as_old, as_new, elb_name,
                                    elb_dns):
     app_name = get_app_friendly_name(online_app)
     notif = "Blue/green swap done for [{0}] between [{1}] and [{2}] on ELB '{3}' ({4})".format(
         app_name, as_old, as_new, elb_name, elb_dns)
     return _green(notif)
Beispiel #9
0
 def _get_notification_message_failed(online_app, to_deploy_app, msg):
     app_name = get_app_friendly_name(online_app)
     notif = "Blue/green swap failed for [{0}] between [{1}] and [{2}]: {3}".format(
         app_name, online_app['_id'], to_deploy_app['_id'], msg)
     return _red(notif)