Ejemplo n.º 1
0
 def _get_cluster(self):
     try:
         clusters = self._ecs_describe_clusters(clusters=[
             self.name,
         ])
         if not clusters['clusters']:
             raise CloudComposeException(
                 "{} cluster could not be found".format(self.name))
         return clusters['clusters']
     except KeyError:
         raise CloudComposeException(
             "Could not retrieve cluster status for {}".format(self.name))
Ejemplo n.º 2
0
 def _get_auto_scaling_group(self):
     try:
         asgs = self._asg_describe_auto_scaling_groups(
             AutoScalingGroupNames=[
                 self.name,
             ])
         if len(asgs['AutoScalingGroups']) == 1:
             return asgs['AutoScalingGroups'].pop()
         else:
             raise CloudComposeException('{} ASG is not unique'.format(
                 self.name))
     except KeyError:
         raise CloudComposeException(
             'AutoScalingGroup could not be retrieved for {}'.format(
                 self.name))
Ejemplo n.º 3
0
    def _create_ebs_volume_config(self, volume, default_device, use_snapshots):
        device = volume.get('block', default_device)
        volume_config = {
            "DeviceName": device,
            "Ebs": {
                "VolumeSize": self._format_size(volume.get("size", "10G")),
                "DeleteOnTermination": volume.get("delete_on_termination",
                                                  True),
                "VolumeType": volume.get("volume_type", "gp2")
            }
        }

        if volume_config['Ebs']['VolumeType'] == 'io1':
            max_iops = volume_config['Ebs']['VolumeSize'] * 30
            iops = volume.get("iops", 100)

            if iops > max_iops:
                raise CloudComposeException(
                    'Cluster not created\nSpecified IOPS (%s) is greater than the max (%s) with a volume size of %sG'
                    % (iops, max_iops, volume_config['Ebs']['VolumeSize']))

            volume_config['Ebs']['Iops'] = iops

        if use_snapshots:
            self._add_snapshot_id(volume_config, volume, device)

        return volume_config
Ejemplo n.º 4
0
    def _get_ecs_services(self):
        ecs_services = []
        more_services = True
        next_token = False

        while more_services:
            if next_token:
                cluster_services = self._ecs_list_services(
                    cluster=self.name, nextToken=next_token)
            else:
                cluster_services = self._ecs_list_services(cluster=self.name)

            service_arns = cluster_services.get('serviceArns', [])
            if service_arns:
                describe_services = self._ecs_describe_services(
                    cluster=self.name, services=service_arns)
                ecs_services = ecs_services + describe_services['services']
            else:
                raise CloudComposeException(
                    "Services could not be retrieved for {}".format(self.name))

            if cluster_services.get('nextToken'):
                next_token = cluster_services.get('nextToken')
            else:
                more_services = False

        return ecs_services
Ejemplo n.º 5
0
    def align_primaries(self):
        msg_prefix = 'ERROR: unable to make the same EC2 instance PRIMARY for both mongodb and configdb because %s'
        mongodb_health, _ = self._repl_set_health(27018, 'mongodb')
        if not mongodb_health:
            raise CloudComposeException(msg_prefix % 'mongodb is SICK')

        configdb_health, _ = self._repl_set_health(27019, 'configdb')
        if not configdb_health:
            raise CloudComposeException(msg_prefix % 'configdb is SICK')

        _, primary_node_name = self.primary_instance_name()
        members = self._repl_set_status(27019).get('members', [])
        for member in members:
            node_name = member['name'].split(':')[0]
            if member.get('state', 6) == 1:
                if node_name != primary_node_name:
                    self._stepdown_configdb(members, node_name,
                                            primary_node_name)
Ejemplo n.º 6
0
 def _get_ecs_instances(self):
     try:
         ecs_instances = self._ecs_list_container_instances(
             cluster=self.name)
         instances = self._ecs_describe_container_instances(
             cluster=self.name,
             containerInstances=ecs_instances['containerInstanceArns'])
         return instances['containerInstances']
     except:
         raise CloudComposeException(
             'ECS container instances could not be retrieved for {}'.format(
                 self.name))
Ejemplo n.º 7
0
 def has_failures(self):
     """
     Checks if there are any failures on the ECS cluster.
     :return: True if there are failures
     """
     try:
         newest_instance = self._get_newest_ecs_instance()
         # If there are stopped tasks, then there's something preventing
         # tasks from starting on the new ECS instance.
         tasks = self._ecs_list_tasks(
             cluster=self.name,
             containerInstance=newest_instance['containerInstanceArn'],
             desiredStatus='STOPPED')
         return tasks['taskArns']
     except KeyError:
         raise CloudComposeException(
             "Could not retrieve stopped tasks for {}".format(self.name))
Ejemplo n.º 8
0
    def _resolve_ami_name(self, upgrade_image):
        if self.aws['ami'].startswith('ami-'):
            return self.aws['ami']

        ami = None
        message = None

        if not upgrade_image and not self.aws.get('asg'):
            ami = self._find_ami_on_cluster()
            if ami:
                message = 'as used on other cluster nodes'

        if not ami:
            ami, creation_date = self._find_ami_by_name_tag()
            if ami:
                message = 'created on %s' % creation_date

        if ami:
            print 'ami %s resolves to %s %s' % (self.aws['ami'], ami, message)
        else:
            raise CloudComposeException('Unable to resolve AMI %s' %
                                        self.aws['ami'])

        return ami