Пример #1
0
    def get_launch_configs(self, user_obj, names=None, max=-1, startToken=None):
        next_token = None

        dts = self._dtrs_client.list_dts(user_obj.access_id)
        dts.sort()

        # now that we have the final list, look up each description
        lc_list_type = AWSListType('LaunchConfigurations')
        for lc_name in dts:
            if lc_list_type.get_length() >= max and max > -1:
                break

            dt_descr = self._get_dt_details(lc_name, user_obj.access_id)
            for site in sorted(dt_descr['mappings'].keys()):
                mapped_def = dt_descr['mappings'][site]
                out_name = '%s@%s' % (lc_name, site)
                if lc_list_type.get_length() >= max and max > -1:
                    break

                if out_name == startToken:
                    startToken = None

                if startToken is None and (names is None or out_name in names):
                    ot_lc = LaunchConfigurationType('LaunchConfiguration')
                    ot_lc.BlockDeviceMappings = AWSListType('BlockDeviceMappings')

                    if 'CreatedTime' not in mapped_def.keys():
                        # This is an LC that was created with the new Phantom API, ignore it
                        continue

                    tm = _get_time(mapped_def['CreatedTime'])
                    ot_lc.CreatedTime = DateTimeType('CreatedTime', tm)

                    ot_lc.ImageId = mapped_def['iaas_image']
                    ot_lc.InstanceMonitoring = InstanceMonitoringType('InstanceMonitoring')
                    ot_lc.InstanceMonitoring.Enabled = False
                    ot_lc.InstanceType = mapped_def['iaas_allocation']
                    ot_lc.KernelId = None
                    ot_lc.KeyName = phantom_get_default_key_name()
                    ot_lc.LaunchConfigurationARN = mapped_def['LaunchConfigurationARN']
                    ot_lc.LaunchConfigurationName = out_name
                    ot_lc.RamdiskId = None
                    ot_lc.SecurityGroups = AWSListType('SecurityGroups')
                    contextualization = dt_descr.get('contextualization')
                    if contextualization is not None and contextualization.get('method') == 'userdata':
                        # UserData should be base64-encoded to be properly decoded by boto
                        ot_lc.UserData = base64.b64encode(contextualization.get('userdata'))
                    else:
                        ot_lc.UserData = None

                    lc_list_type.add_item(ot_lc)

        # XXX need to set next_token
        return (lc_list_type, next_token)
Пример #2
0
def convert_epu_description_to_asg_out(desc, name):

    log(logging.DEBUG, "conversion description: %s" % (str(desc)))

    config = desc['config']['engine_conf']

    asg = AutoScalingGroupType('AutoScalingGroup')
    asg.AutoScalingGroupName = desc['name']
    asg.DesiredCapacity = config['minimum_vms']
    tm = _get_key_or_none(config, 'CreatedTime')
    if tm:
        tm = _get_time(config['CreatedTime'])
        asg.CreatedTime = DateTimeType('CreatedTime', tm)

    asg.AutoScalingGroupARN = _get_key_or_none(config, 'AutoScalingGroupARN')
    asg.AvailabilityZones = AWSListType('AvailabilityZones')

    dt_name = config.get('dtname')
    if dt_name is None:
        dt_name = config.get('deployable_type')

    asg.HealthCheckType = _get_key_or_none(config, 'HealthCheckType')
    asg.LaunchConfigurationName = "%s" % (dt_name)
    asg.MaxSize = config.get('maximum_vms')
    if asg.MaxSize is None:
        asg.MaxSize = config.get('maximum_vms')
    asg.MinSize = config.get('minimum_vms')
    if asg.MinSize is None:
        asg.MinSize = config.get('minimum_vms')
    asg.PlacementGroup = _get_key_or_none(config, 'PlacementGroup')
    #asg.Status
    asg.VPCZoneIdentifier = _get_key_or_none(config, 'VPCZoneIdentifier')
    asg.EnabledMetrics = AWSListType('EnabledMetrics')
    asg.HealthCheckGracePeriod = 0
    asg.LoadBalancerNames = AWSListType('LoadBalancerNames')
    asg.SuspendedProcesses = AWSListType('SuspendedProcesses')
    asg.Tags = AWSListType('Tags')
    asg.Cooldown = 0

    inst_list = desc['instances']

    asg.Instances = AWSListType('Instances')

    for inst in inst_list:
        out_t = convert_instance_type(name, inst)
        asg.Instances.type_list.append(out_t)

    return asg
Пример #3
0
def convert_epu_description_to_asg_out(desc, name):

    log(logging.DEBUG, "conversion description: %s" %(str(desc)))

    config = desc['config']['engine_conf']
    
    asg = AutoScalingGroupType('AutoScalingGroup')
    asg.AutoScalingGroupName = desc['name']
    asg.DesiredCapacity = config['minimum_vms']
    tm = _get_key_or_none(config, 'CreatedTime')
    if tm:
        tm = _get_time(config['CreatedTime'])
        asg.CreatedTime = DateTimeType('CreatedTime', tm)

    asg.AutoScalingGroupARN = _get_key_or_none(config, 'AutoScalingGroupARN')
    asg.AvailabilityZones = AWSListType('AvailabilityZones')

    dt_name = config.get('dtname')
    if dt_name is None:
        dt_name = config.get('deployable_type')

    asg.HealthCheckType = _get_key_or_none(config, 'HealthCheckType')
    asg.LaunchConfigurationName = "%s" % (dt_name)
    asg.MaxSize = config.get('maximum_vms')
    if asg.MaxSize is None:
        asg.MaxSize = config.get('maximum_vms')
    asg.MinSize = config.get('minimum_vms')
    if asg.MinSize is None:
        asg.MinSize = config.get('minimum_vms')
    asg.PlacementGroup = _get_key_or_none(config,'PlacementGroup')
    #asg.Status
    asg.VPCZoneIdentifier = _get_key_or_none(config,'VPCZoneIdentifier')
    asg.EnabledMetrics = AWSListType('EnabledMetrics')
    asg.HealthCheckGracePeriod = 0
    asg.LoadBalancerNames = AWSListType('LoadBalancerNames')
    asg.SuspendedProcesses = AWSListType('SuspendedProcesses')
    asg.Tags = AWSListType('Tags')
    asg.Cooldown = 0

    inst_list = desc['instances']

    asg.Instances = AWSListType('Instances')

    for inst in inst_list:
        out_t = convert_instance_type(name, inst)
        asg.Instances.type_list.append(out_t)

    return asg
Пример #4
0
    def get_launch_configs(self,
                           user_obj,
                           names=None,
                           max=-1,
                           startToken=None):
        next_token = None

        dts = self._dtrs_client.list_dts(user_obj.access_id)
        dts.sort()

        # now that we have the final list, look up each description
        lc_list_type = AWSListType('LaunchConfigurations')
        for lc_name in dts:
            if lc_list_type.get_length() >= max and max > -1:
                break

            dt_descr = self._get_dt_details(lc_name, user_obj.access_id)
            for site in sorted(dt_descr['mappings'].keys()):
                mapped_def = dt_descr['mappings'][site]
                out_name = '%s@%s' % (lc_name, site)
                if lc_list_type.get_length() >= max and max > -1:
                    break

                if out_name == startToken:
                    startToken = None

                if startToken is None and (names is None or out_name in names):
                    ot_lc = LaunchConfigurationType('LaunchConfiguration')
                    ot_lc.BlockDeviceMappings = AWSListType(
                        'BlockDeviceMappings')

                    if 'CreatedTime' not in mapped_def.keys():
                        # This is an LC that was created with the new Phantom API, ignore it
                        continue

                    tm = _get_time(mapped_def['CreatedTime'])
                    ot_lc.CreatedTime = DateTimeType('CreatedTime', tm)

                    ot_lc.ImageId = mapped_def['iaas_image']
                    ot_lc.InstanceMonitoring = InstanceMonitoringType(
                        'InstanceMonitoring')
                    ot_lc.InstanceMonitoring.Enabled = False
                    ot_lc.InstanceType = mapped_def['iaas_allocation']
                    ot_lc.KernelId = None
                    ot_lc.KeyName = phantom_get_default_key_name()
                    ot_lc.LaunchConfigurationARN = mapped_def[
                        'LaunchConfigurationARN']
                    ot_lc.LaunchConfigurationName = out_name
                    ot_lc.RamdiskId = None
                    ot_lc.SecurityGroups = AWSListType('SecurityGroups')
                    contextualization = dt_descr.get('contextualization')
                    if contextualization is not None and contextualization.get(
                            'method') == 'userdata':
                        # UserData should be base64-encoded to be properly decoded by boto
                        ot_lc.UserData = base64.b64encode(
                            contextualization.get('userdata'))
                    else:
                        ot_lc.UserData = None

                    lc_list_type.add_item(ot_lc)

        # XXX need to set next_token
        return (lc_list_type, next_token)