Get ami from a web url.

    Args:
        region (str): AWS Region to find AMI ID.

    Returns:
        dict: Contents in dictionary format.
320472
def _get_ami_dict(json_url):
    
    LOG.info("Getting AMI from %s", json_url)
    response = requests.get(json_url)
    assert response.ok, "Error getting ami info from {}".format(json_url)
    ami_dict = response.json()
    LOG.debug('AMI json contents: %s', ami_dict)
    return ami_dict
713088
def get_zones(region, auth_kwargs):
    
    ec2_conn = boto.ec2.connect_to_region(region, **auth_kwargs)
    return [zone.name for zone in ec2_conn.get_all_zones()]
92200
def _get_regions(self):
        """"""
        if self._specs_in[_REGIONS_STR] == 'all':
            return [_get_all_objs_of_type(
                Region, getattr(self._obj_lib, 'regions', self._obj_lib)
            )]
        else:
            return [set(self._specs_in[_REGIONS_STR])]
509601
def _safe_region(region=None, context=None):
    """"""
    ret = region or settings.get("region")
    context = context or identity
    if not ret:
        # Nothing specified; get the default from the identity object.
        if not context:
            _create_identity()
            context = identity
        ret = context.get_default_region()
    if not ret:
        # Use the first available region
        try:
            ret = regions[0]
        except IndexError:
            ret = ""
    return ret
319315
def get_s3_region_from_endpoint(endpoint):
    

    # Extract region by regex search.
    m = _EXTRACT_REGION_REGEX.search(endpoint)
    if m:
        # Regex matches, we have found a region.
        region = m.group(1)
        if region == 'external-1':
            # Handle special scenario for us-east-1 URL.
            return 'us-east-1'
        if region.startswith('dualstack'):
            # Handle special scenario for dualstack URL.
            return region.split('.')[1]
        return region

    # No regex matches return None.
    return None
1193940
def connect_to_ec2(region, access_key_id, secret_access_key):
    
    conn = boto.ec2.connect_to_region(region,
                                      aws_access_key_id=access_key_id,
                                      aws_secret_access_key=secret_access_key)
    return conn
547569
def _get_content(self, params, mode_translate):
        
        token = self._get_token()
        headers = {'Authorization': 'Bearer '+ token}
        parameters = params
        translation_url = mode_translate
        return self._make_request(parameters, translation_url, headers)
1098530
def describe_key_pairs():
    
    region_keys = {}
    for r in boto3.client('ec2', 'us-west-2').describe_regions()['Regions']:
        region = r['RegionName']
        client = boto3.client('ec2', region_name=region)
        try:
            pairs = client.describe_key_pairs()
            if pairs:
                region_keys[region] = pairs
        except Exception as e:
            app.logger.info(e)
    return region_keys
1064453
def connect(self, region, **kw_params):
        
        self.ec2 = boto.ec2.connect_to_region(region, **kw_params)
        if not self.ec2:
            raise EC2ManagerException('Unable to connect to region "%s"' % region)
        self.remote_images.clear()

        if self.images and any(('image_name' in img and 'image_id' not in img) for img in self.images.values()):
            for img in self.images.values():
                if 'image_name' in img and 'image_id' not in img:
                    img['image_id'] = self.resolve_image_name(img.pop('image_name'))
1104626
def GetAmi(ec2, ami_spec):
     
    images = ec2.get_all_images(owners=[ami_spec.owner_id] )
    requested_image = None
    for image in images:
      if image.name == ami_spec.ami_name:
        requested_image = image
        break
    return requested_image
473829
def get_saml_provider_arn(name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    try:
        response = conn.list_saml_providers()
        for saml_provider in response.list_saml_providers_response.list_saml_providers_result.saml_provider_list:
            if saml_provider['arn'].endswith(':saml-provider/' + name):
                return saml_provider['arn']
        return False
    except boto.exception.BotoServerError as e:
        aws = __utils__['boto.get_error'](e)
        log.debug(aws)
        log.error('Failed to get ARN of SAML provider %s.', name)
        return False
155202
def _get_roots(self):
        
        region = self._get_session().region_name or r'[\w-]+'
        return (
                # S3 scheme
                # - s3://<bucket>/<key>
                's3://',

                # Virtual-hosted–style URL
                # - http://<bucket>.s3.amazonaws.com/<key>
                # - https://<bucket>.s3.amazonaws.com/<key>
                # - http://<bucket>.s3-<region>.amazonaws.com/<key>
                # - https://<bucket>.s3-<region>.amazonaws.com/<key>
                _re.compile(r'https?://[\w.-]+\.s3\.amazonaws\.com'),
                _re.compile(
                    r'https?://[\w.-]+\.s3-%s\.amazonaws\.com' % region),

                # Path-hosted–style URL
                # - http://s3.amazonaws.com/<bucket>/<key>
                # - https://s3.amazonaws.com/<bucket>/<key>
                # - http://s3-<region>.amazonaws.com/<bucket>/<key>
                # - https://s3-<region>.amazonaws.com/<bucket>/<key>
                _re.compile(r'https?://s3\.amazonaws\.com'),
                _re.compile(r'https?://s3-%s\.amazonaws\.com' % region),

                # Transfer acceleration URL
                # - http://<bucket>.s3-accelerate.amazonaws.com
                # - https://<bucket>.s3-accelerate.amazonaws.com
                # - http://<bucket>.s3-accelerate.dualstack.amazonaws.com
                # - https://<bucket>.s3-accelerate.dualstack.amazonaws.com
                _re.compile(
                    r'https?://[\w.-]+\.s3-accelerate\.amazonaws\.com'),
                _re.compile(
                    r'https?://[\w.-]+\.s3-accelerate\.dualstack'
                    r'\.amazonaws\.com'))
1359579
def _get_ami_file(region='us-east-1'):
    
    LOG.info("Getting AMI from Gitlab")
    lookup = FileLookup(git_short='devops/ansible')
    filename = 'scripts/{0}.json'.format(region)
    ami_contents = lookup.remote_file(filename=filename, branch='master')
    LOG.debug('AMI file contents in %s: %s', filename, ami_contents)
    return ami_contents
264465
def regions():
    
    return [SDBRegionInfo(name='us-east-1',
                          endpoint='sdb.amazonaws.com'),
            SDBRegionInfo(name='eu-west-1',
                          endpoint='sdb.eu-west-1.amazonaws.com'),
            SDBRegionInfo(name='us-west-1',
                          endpoint='sdb.us-west-1.amazonaws.com'),
            SDBRegionInfo(name='sa-east-1',
                          endpoint='sdb.sa-east-1.amazonaws.com'),
            SDBRegionInfo(name='us-west-2',
                          endpoint='sdb.us-west-2.amazonaws.com'),
            SDBRegionInfo(name='ap-northeast-1',
                          endpoint='sdb.ap-northeast-1.amazonaws.com'),
            SDBRegionInfo(name='ap-southeast-1',
                          endpoint='sdb.ap-southeast-1.amazonaws.com')
            ]
1372500
def get(provider_name, region_name)
      provider_region = "#{provider_name}/#{region_name}"
      response = http_get(resource_url(provider_region))
      format_object(response, TYPE)
    end
143481
def by_id(self, region, encrypted_summoner_id):
        
        url, query = SummonerApiV4Urls.by_id(
            region=region, encrypted_summoner_id=encrypted_summoner_id
        )
        return self._raw_request(self.by_id.__name__, region, url, query)
209731
def get_image_id_another_region(glance_url, image_name, token):
    
    url = glance_url + '/images?property-sdc_aware=true'
    headers = {'Accept': 'application/json', 'X-Auth-Token': token}
    try:
        response = requests.get(url, headers=headers)
        response_json = response.json()
        for image_info in response_json['images']:
            if image_info['name'] == image_name:
                return image_info['id']
        return None
    except Exception as e:
        return None