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)
def _get_a_list(self, d, list_name, names=None, max=-1, startToken=None): if names == None: sorted_keys = sorted(d.keys()) else: for n in names: if n not in d: empty_list = AWSListType(list_name) return (empty_list, None) sorted_keys = sorted(names) next_name = None if max is None or max < 0: max = len(sorted_keys) elif max != len(sorted_keys): next_name = d[sorted_keys[max]].LaunchConfigurationName activated = False if startToken is None: activated = True lc_list_type = AWSListType(list_name) for i in range(0, max): k = sorted_keys[i] if startToken and d[k] == startToken: activated = True if not activated: continue lc_list_type.add_item(d[k]) if lc_list_type.get_length() == max: return (lc_list_type, next_name) return (lc_list_type, next_name)
def get_autoscale_groups(self, user_obj, names=None, max=-1, startToken=None): epu_list = self._epum_client.list_domains(caller=user_obj.access_id) log(logging.DEBUG, "Incoming epu list is %s" % (str(epu_list))) next_token = None epu_list.sort() asg_list_type = AWSListType('AutoScalingGroups') for asg_name in epu_list: if asg_list_type.get_length() >= max and max > -1: break if asg_name == startToken: startToken = None if startToken is None and (names is None or asg_name in names): asg_description = self._epum_client.describe_domain( asg_name, caller=user_obj.access_id) asg = convert_epu_description_to_asg_out( asg_description, asg_name) asg_list_type.add_item(asg) # XXX need to set next_token return (asg_list_type, next_token)
def _get_a_list(self, d, list_name, names=None, max=-1, startToken=None): if names == None: sorted_keys = sorted(d.keys()) else: for n in names: if n not in d: empty_list = AWSListType(list_name) return (empty_list, None) sorted_keys = sorted(names) next_name = None if max is None or max < 0: max = len(sorted_keys) elif max != len(sorted_keys): next_name = d[sorted_keys[max]].LaunchConfigurationName activated = False if startToken is None: activated = True lc_list_type = AWSListType(list_name) for i in range(0, max): k = sorted_keys[i] if startToken and d[k] == startToken: activated = True if not activated: continue lc_list_type.add_item(d[k]) if lc_list_type.get_length() == max: return (lc_list_type, next_name) return (lc_list_type, next_name)
def get_autoscale_groups(self, user_obj, names=None, max=-1, startToken=None): epu_list = self._epum_client.list_domains(caller=user_obj.access_id) log(logging.DEBUG, "Incoming epu list is %s" %(str(epu_list))) next_token = None epu_list.sort() asg_list_type = AWSListType('AutoScalingGroups') for asg_name in epu_list: if asg_list_type.get_length() >= max and max > -1: break if asg_name == startToken: startToken = None if startToken is None and (names is None or asg_name in names): asg_description = self._epum_client.describe_domain(asg_name, caller=user_obj.access_id) asg = convert_epu_description_to_asg_out(asg_description, asg_name) asg_list_type.add_item(asg) # XXX need to set next_token return (asg_list_type, next_token)
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)