Parse a single EMR cluster

        :param global_params:           Parameters shared for all regions
        :param region:                  Name of the AWS region
        :param cluster:                 EMR cluster
168443
def parse_cluster(self, global_params, region, cluster):
        
        cluster_id = cluster['Id']
        cluster = api_clients[region].describe_cluster(ClusterId = cluster_id)['Cluster']
        cluster['id'] = cluster.pop('Id')
        cluster['name'] = cluster.pop('Name')
        vpc_id = 'TODO' # The EMR API won't disclose the VPC ID, so wait until all configs have been fetch and look up the VPC based on the subnet ID
        manage_dictionary(self.vpcs, vpc_id, VPCConfig(self.vpc_resource_types))
        self.vpcs[vpc_id].clusters[cluster_id] = cluster
119190
def _parse_global_index(self, clause, attrs):
        
        index_type, name = clause[:2]
        name = resolve(name)

        def get_key(field, data_type=None):
            """ Get or set the DynamoKey from the field name """
            if field in attrs:
                key = attrs[field]
                if data_type is not None:
                    if TYPES[data_type] != key.data_type:
                        raise SyntaxError(
                            "Key %r %s already declared with type %s" % field,
                            data_type,
                            key.data_type,
                        )
            else:
                if data_type is None:
                    raise SyntaxError("Missing data type for %r" % field)
                key = DynamoKey(field, data_type=TYPES[data_type])
                attrs[field] = key
            return key

        g_hash_key = get_key(*clause.hash_key)
        g_range_key = None
        # For some reason I can't get the throughput section to have a name
        # Use an index instead
        tp_index = 3
        if clause.range_key:
            tp_index += 1
            g_range_key = get_key(*clause.range_key)
        if clause.include_vars:
            tp_index += 1
        kwargs = {}
        if tp_index < len(clause):
            throughput = clause[tp_index]
            kwargs["throughput"] = Throughput(*map(resolve, throughput))
        index_type = clause.index_type[0]
        if index_type in ("ALL", "INDEX"):
            factory = GlobalIndex.all
        elif index_type == "KEYS":
            factory = GlobalIndex.keys
        elif index_type == "INCLUDE":
            factory = GlobalIndex.include
            if not clause.include_vars:
                raise SyntaxError("Include index %r missing include fields" % name)
            kwargs["includes"] = [resolve(v) for v in clause.include_vars]
        return factory(name, g_hash_key, g_range_key, **kwargs)
1165020
def view_global_gmfs(token, dstore):
    
    imtls = dstore['oqparam'].imtls
    row = dstore['gmf_data/data']['gmv'].mean(axis=0)
    return rst_table([row], header=imtls)
125293
def _ep_for_region(self, region):
        
        rgn = region.upper()
        try:
            rgn_ep = [ep for ep in list(self.endpoints.values())
                    if ep.region.upper() == rgn][0]
        except IndexError:
            # See if there is an 'ALL' region.
            try:
                rgn_ep = [ep for ep in list(self.endpoints.values())
                        if ep.region.upper() == "ALL"][0]
            except IndexError:
                rgn_ep = None
        return rgn_ep
1011509
def __get_region(conn, vm_):
    '''
    
    '''
    location = __get_location(conn, vm_)
    region = '-'.join(location.name.split('-')[:2])

    return conn.ex_get_region(region)
703538
def parse_identitie(self, global_params, region, identity_name):
        
        identity = {'name': identity_name, 'policies': {}}
        policy_names = api_clients[region].list_identity_policies(Identity = identity_name)['PolicyNames']
        if len(policy_names):
            policies = api_clients[region].get_identity_policies(Identity = identity_name, PolicyNames = policy_names)['Policies']
            for policy_name in policies:
                identity['policies'][policy_name] = json.loads(policies[policy_name])
        dkim = api_clients[region].get_identity_dkim_attributes(Identities = [ identity_name ])['DkimAttributes'][identity_name]
        identity['DkimEnabled'] = dkim['DkimEnabled']
        identity['DkimVerificationStatus'] = dkim['DkimVerificationStatus']
        self.identities[self.get_non_aws_id(identity_name)] = identity
1354216
def __CombineGlobalParams(self, global_params, default_params):
        """"""
        util.Typecheck(global_params, (type(None), self.__client.params_type))
        result = self.__client.params_type()
        global_params = global_params or self.__client.params_type()
        for field in result.all_fields():
            value = global_params.get_assigned_value(field.name)
            if value is None:
                value = default_params.get_assigned_value(field.name)
            if value not in (None, [], ()):
                setattr(result, field.name, value)
        return result
1108735
def parse_trail(self, global_params, region, trail):
        
        trail_config = {}
        trail_config['name'] = trail.pop('Name')
        trail_id = self.get_non_aws_id(trail_config['name'])
        trail_details = None

        api_client = api_clients[region]

        # Do not duplicate entries for multiregion trails
        if 'IsMultiRegionTrail' in trail and trail['IsMultiRegionTrail'] and trail['HomeRegion'] != region:
            for key in ['HomeRegion', 'TrailARN']:
                trail_config[key] = trail[key]
            trail_config['scout2_link'] = 'services.cloudtrail.regions.%s.trails.%s' % (trail['HomeRegion'], trail_id)
        else:
            for key in trail:
                trail_config[key] = trail[key]
            trail_config['bucket_id'] = self.get_non_aws_id(trail_config.pop('S3BucketName'))
            for key in ['IsMultiRegionTrail', 'LogFileValidationEnabled']:
                if key not in trail_config:
                    trail_config[key] = False
            trail_details = api_client.get_trail_status(Name=trail['TrailARN'])
            for key in ['IsLogging', 'LatestDeliveryTime', 'LatestDeliveryError', 'StartLoggingTime', 'StopLoggingTime', 'LatestNotificationTime', 'LatestNotificationError', 'LatestCloudWatchLogsDeliveryError', 'LatestCloudWatchLogsDeliveryTime']:
                trail_config[key] = trail_details[key] if key in trail_details else None

        if trail_details:
            trail_config['wildcard_data_logging'] = self.data_logging_status(trail_config['name'], trail_details, api_client)

        self.trails[trail_id] = trail_config
1022408
def parse!(argv)
      command = nil
      arguments = nil
      # https://github.com/aws/aws-sdk-ruby/blob/v2.3.11/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb#L18
      region_keys = %w(AWS_REGION AMAZON_REGION AWS_DEFAULT_REGION)
      options = { aws: { region: ENV.values_at(*region_keys).compact.first,
                  retry_limit: DEFAULT_OPTION_RETRY_LIMIT } }

      opt = ::OptionParser.new
      opt.summary_width = 65535
      set_usage!(opt)

      opt.on('-k', '--access-key ACCESS_KEY') {|v| options[:aws][:access_key_id]     = v }
      opt.on('-s', '--secret-key SECRET_KEY') {|v| options[:aws][:secret_access_key] = v }
      opt.on('-r', '--region REGION')         {|v| options[:aws][:region]            = v }
      opt.on('',   '--retry-limit LIMIT')     {|v| options[:aws][:retry_limit]       = v }

      opt.on('', '--profile PROFILE') do |v|
        options[:aws][:credentials] ||= {}
        options[:aws][:credentials][:profile_name] = v
      end

      opt.on('', '--credentials-path PATH') do |v|
        options[:aws][:credentials] ||= {}
        options[:aws][:credentials][:path] = v
      end

      plugin_exts = Kumogata2::Plugin.plugins.flat_map(&:ext).uniq
      opt.on(''  , '--output-format FORMAT', plugin_exts) do |v|
        options[:output_format] = v
      end

      opt.on('-p', '--parameters KEY_VALUES', Array) {|v| options[:parameters]              = v }
      opt.on('-j', '--json-parameters JSON')         {|v| options[:json_parameters]         = v }
      opt.on(''  , '--[no-]deletion-policy-retain')  {|v| options[:deletion_policy_retain]  = v }

      {
        disable_rollback: :boolean,
        timeout_in_minutes: Integer,
        notification_arns: Array,
        capabilities: Array,
        resource_types: Array,
        on_failure: nil,
        stack_policy_body: nil,
        stack_policy_url: nil,
        use_previous_template: :boolean,
        stack_policy_during_update_body: nil,
        stack_policy_during_update_url: nil,
        tags: Array,
      }.each do |key, type|
        opt_str = key.to_s.gsub('_', '-')
        opt_val = key.to_s.upcase

        case type
        when :boolean
          opt.on('', "--[no-]#{opt_str}") {|v| options[key] = v }
        when nil
          opt.on('', "--#{opt_str} #{opt_val}") {|v| options[key] = v }
        else
          opt.on('', "--#{opt_str} #{opt_val}", type) {|v| options[key] = v }
        end
      end

      opt.on(''  , '--result-log PATH')         {|v| options[:result_log]       = v }
      opt.on(''  , '--command-result-log PATH') {|v| options[:command]          = v }
      opt.on(''  , '--[no-]detach')             {|v| options[:detach]           = v }
      opt.on(''  , '--[no-]force')              {|v| options[:force]            = v }
      opt.on(''  , '--[no-]color')              {|v| options[:color]            = v }
      opt.on(''  , '--[no-]ignore-all-space')   {|v| options[:ignore_all_space] = v }
      opt.on(''  , '--[no-]debug')              {|v| options[:debug]            = v }

      opt.parse!

      unless (command = argv.shift)
        puts opt.help
        exit_parse!(1)
      end

      orig_command = command
      command = command.gsub('-', '_').to_sym
      command = find_command(command)

      unless command
        raise "Unknown command: #{orig_command}"
      end

      arguments = argv.dup
      validate_arguments(command, arguments)

      options = DEFAULT_OPTIONS.merge(options)
      options = Hashie::Mash.new(options)

      if options[:aws][:credentials]
        credentials = Aws::SharedCredentials.new(options[:aws][:credentials])
        options[:aws][:credentials] = credentials
      end

      Aws.config.update(options[:aws].dup)
      options = Hashie::Mash.new(options)

      String.colorize = options.color?
      Diffy::Diff.default_format = options.color? ? :color : :text

      if options.debug?
        Kumogata2::Logger.instance.set_debug(options.debug?)

        Aws.config.update(
          http_wire_trace: true,
          logger: Kumogata2::Logger.instance
        )
      end

      update_parameters(options)
      output = COMMANDS.fetch(command).fetch(:output, true)

      options.command = command
      options.arguments = arguments
      options.output_result = output

      [command, arguments, options, output]
    end
1036791
def parse_region(self, login_response):
        
        auth_token = login_response.cgx_content['x_auth_token']
        auth_token_dict = self.parse_auth_token(auth_token)
        auth_region = auth_token_dict.get('region')
        return auth_region
315009
def list_subgroups_global(self, id):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - id
        """ID"""
        path["id"] = id

        self.logger.debug("GET /api/v1/global/outcome_groups/{id}/subgroups with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/global/outcome_groups/{id}/subgroups".format(**path), data=data, params=params, all_pages=True)
1035123
function requestBucketRegion(resp, done) {
    var error = resp.error;
    var req = resp.request;
    var bucket = req.params.Bucket || null;

    if (!error || !bucket || error.region || req.operation === 'listObjects' ||
        (AWS.util.isNode() && req.operation === 'headBucket') ||
        (error.statusCode === 400 && req.operation !== 'headObject') ||
        regionRedirectErrorCodes.indexOf(error.code) === -1) {
      return done();
    }
    var reqOperation = AWS.util.isNode() ? 'headBucket' : 'listObjects';
    var reqParams = {Bucket: bucket};
    if (reqOperation === 'listObjects') reqParams.MaxKeys = 0;
    var regionReq = req.service[reqOperation](reqParams);
    regionReq._requestRegionForBucket = bucket;
    regionReq.send(function() {
      var region = req.service.bucketRegionCache[bucket] || null;
      error.region = region;
      done();
    });
  }
1176245
def parse_global_meta(self, global_meta_str):
        

        if global_meta_str:
            global_meta_str = regex_meta.findall(global_meta_str + ',')
        if global_meta_str:
            for par in global_meta_str:
                if par[0] is not '':
                    val1 = par[0].lower()
                    val2 = par[1]
                else:
                    val1 = par[2].lower()
                    val2 = par[3]
                val1 = val1.strip()
                val2 = val2.strip()
                if val1 in self.valid_global_keys :
                    if val1 in ('range', 'corr', 'labeloff'):
                        val2 = val2.split(",")
                        val2 = [x.strip() for x in val2 if x]
                    self.global_meta[val1] = val2
                else:
                    self._raise_error("'{0}' is not a valid global meta key".format(val1))
812849
def parse_args():
    
    parser = argparse.ArgumentParser(description="Uploads specified VMDK file to AWS s3 bucket, and converts to AMI")
    parser.add_argument('-r', '--aws_regions', type=str, nargs='+', required=True,
                        help='list of AWS regions where uploaded ami should be copied. Available'
                             ' regions: {}.'.format(AWSUtilities.aws_regions))
    parser.add_argument('-a', '--aws_profile', type=str, required=True, help='AWS profile name to use for aws cli commands')
    parser.add_argument('-b', '--s3_bucket', type=str, required=True,
                        help='The aws_bucket of the profile to upload and save vmdk to')
    parser.add_argument('-f', '--vmdk_upload_file', type=str, required=True,
                        help="The file to upload if executing ")
    parser.add_argument('-n', '--ami_name', type=str, required=False, help='The name to give to the uploaded ami. '
                                                                           'Defaults to the name of the file')
    parser.add_argument('-d', '--directory', type=str, default=tempfile.mkdtemp(),
                        help='Directory to save temp aws config upload files')
    args = parser.parse_args()

    if not args.ami_name:
        args.ami_name = os.path.basename(args.vmdk_upload_file)

    validate_args(args)

    return args
207144
def parse_clusters(config)
        OodCore::Clusters.load_file(config || '/etc/ood/config/clusters.d')
      rescue OodCore::ConfigurationNotFound
        OodCore::Clusters.new([])
      end
1354978
def _lambda_uri(self, lambda_name, lambda_region):
        '''
        
        '''
        profile = self._common_aws_args.get('profile')
        region = self._common_aws_args.get('region')

        lambda_region = __utils__['boto3.get_region']('lambda', lambda_region, profile)
        apigw_region = __utils__['boto3.get_region']('apigateway', region, profile)

        lambda_desc = __salt__['boto_lambda.describe_function'](lambda_name, **self._common_aws_args)

        if lambda_region != apigw_region:
            if not lambda_desc.get('function'):
                # try look up in the same region as the apigateway as well if previous lookup failed
                lambda_desc = __salt__['boto_lambda.describe_function'](lambda_name, **self._common_aws_args)

        if not lambda_desc.get('function'):
            raise ValueError('Could not find lambda function {0} in '
                             'regions [{1}, {2}].'.format(lambda_name, lambda_region, apigw_region))

        lambda_arn = lambda_desc.get('function').get('FunctionArn')
        lambda_uri = ('arn:aws:apigateway:{0}:lambda:path/2015-03-31'
                      '/functions/{1}/invocations'.format(apigw_region, lambda_arn))
        return lambda_uri
405324
def load_global_config(config_path):
    
    config = configparser.RawConfigParser()
    if os.path.exists(config_path):
        logger.debug("Checking and setting global parameters...")
        config.read(config_path)
    else:
        _initial_run()
        logger.info("Unable to find a global sprinter configuration!")
        logger.info("Creating one now. Please answer some questions" +
                    " about what you would like sprinter to do.")
        logger.info("")
    # checks and sets sections
    if not config.has_section('global'):
        config.add_section('global')

    configure_config(config)
    write_config(config, config_path)

    return config