Beispiel #1
0
 def describe_schedule(self, env, name):
     asg = ASG(name, env)
     schedule = asg.get_schedule()
     if not schedule:
         self.show_result({}, "No ASG schedule set")
     else:
         schedule_value = schedule.get('Value')
         if not schedule_value:
             schedule_value = 'default'
         self.show_result(schedule, "Schedule for {0} in {1} is {2}".format(name, env, schedule_value))
Beispiel #2
0
 def describe_health(self, env, name):
     asg = ASG(name, env)
     health = asg.get_health()
     if health.get('is_healthy'):
         n_services = health.get('required_count')
         n_instances = health.get('instances_count')
         message = '{0} is healthy ({1} services on {2} instances)'.format(name, n_services, n_instances)
     else:
         description = describe_asg_health(result)
         message = '{0} is not healthy: {1}'.format(name, description)
     self.show_result(health, message)
Beispiel #3
0
    def get_status(self, env, name):
        asg = ASG(name, env)
        result = asg.get_status()
        is_ready = result.get("ReadyToDeploy")

        if is_ready:
            self.show_result(result, "{0} is ready for deployments".format(name))
        else:
            n_total = result.get('InstancesTotalCount')
            states = map(lambda state,count: "{0}={1}".format(state, count), 
                    result.get('InstancesByLifecycleState').iteritems())
            self.show_result(result, "{0} is not ready for deployment (instances: {1}, Total={2})".format(name, ", ".join(states), n_total))

        return is_ready 
Beispiel #4
0
    def update_schedule(self, env, name):
        schedule = ''
        if self.cmds.get('on'):
            schedule = 'ON'
        elif self.cmds.get('off'):
            schedule = 'OFF'
        elif self.cmds.get('default'):
            schedule = ''
        else:
            schedule = self.opts.get('cron')

        asg = ASG(name, env)
        result = asg.set_schedule(schedule)
        n = len(list(result.get('ChangedInstances')))
        i = 'instance' if n == 1 else 'instances'
        s = 'default' if self.cmds.get('default') else schedule
        self.show_result(result, "Scheduled {0} {1} in {2} to: {3}".format(n, i, name, s))
Beispiel #5
0
    def get_status(self, env, name):
        asg = ASG(name, env)
        result = asg.get_status()
        is_ready = result.get("ReadyToDeploy")

        if is_ready:
            self.show_result(result,
                             "{0} is ready for deployments".format(name))
        else:
            states = []
            for state, count in result.get(
                    'InstancesByLifecycleState').iteritems():
                states.append("{0}={1}".format(state, count))
            self.show_result(
                result,
                "{0} is not ready for deployment (instances: {1}, Total={2})".
                format(name, ", ".join(states), len(states)))

        return is_ready
Beispiel #6
0
    def get_asg_details(self, patches, env):
        for p in patches:
            asg_name = p.get('server_name')
            asg = self.api.get_asg(env, asg_name)
            # Calculate required scale out size
            n_azs = len(list(asg.get('AvailabilityZones')))
            n_instances = p.get('instances_count')
            scale_up_count = n_instances * 2
            if scale_up_count >= n_azs and scale_up_count % n_azs != 0:
                scale_up_count += 1
            p['az_count'] = n_azs
            p['scale_up_count'] = scale_up_count
            p['max_count'] = asg.get('MaxSize', n_instances)

            # Check for any instances in standby
            if any([
                    instance for instance in asg.get('Instances', [])
                    if instance.get('LifecycleState') == 'Standby'
            ]):
                p['has_standby_instances'] = True
            # Check for overall health
            asg_status = ASG(asg_name, env).get_health()
            if not asg_status.get('is_healthy'):
                p['unhealthy'] = asg_status
Beispiel #7
0
 def check_exists(self, env, name):
     asg = ASG(name, env)
     exists = asg.exists()
     self.show_result({'exists': exists}, exists)
Beispiel #8
0
 def has_scaled_in(patch):
     asg = ASG(patch.get('server_name'), self.env)
     status = asg.get_health()
     return status['is_healthy'] and status[
         'instances_count'] == patch.get('instances_count')
Beispiel #9
0
 def services_installed(patch):
     asg = ASG(patch.get('server_name'), self.env)
     status = asg.get_health()
     return status['is_healthy'] and status[
         'instances_count'] == patch.get('scale_up_count')