source/Tools Integration/CE-Integration/CE-automation-scripts/mfcommon.py [303:384]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def CElogin(userapitoken):
    login_data = {'userApiToken': userapitoken}
    r = requests.post(ce_address + ce_endpoint.format('login'),
                  data=json.dumps(login_data), headers=ce_headers)
    if r.status_code == 200:
        print("CloudEndure : You have successfully logged in")
        print("")
    if r.status_code != 200 and r.status_code != 307:
        if r.status_code == 401 or r.status_code == 403:
            print('ERROR: The CloudEndure login credentials provided cannot be authenticated....')
            return None, None
        elif r.status_code == 402:
            print('ERROR: There is no active license configured for this CloudEndure account....')
            return None, None
        elif r.status_code == 429:
            print('ERROR: CloudEndure Authentication failure limit has been reached. The service will become available for additional requests after a timeout....')
            return None, None

    # check if need to use a different API entry point
    if r.history:
        endpointnew = '/' + '/'.join(r.url.split('/')[3:-1]) + '/{}'
        r = requests.post(ce_address + endpointnew.format('login'),
                      data=json.dumps(login_data), headers=ce_headers)
    try:
       ce_headers['X-XSRF-TOKEN'] = r.cookies['XSRF-TOKEN']
       return r.cookies['session'], ce_headers['X-XSRF-TOKEN']
    except:
       pass

    return r.cookies['session'], None

def GetCERegion(project_id, ce_session, ce_headers):
    region_ids = []
    rep = requests.get(ce_address + ce_endpoint.format('projects/{}/replicationConfigurations').format(project_id), headers=ce_headers, cookies=ce_session)
    for item in json.loads(rep.text)['items']:
        region = requests.get(ce_address + ce_endpoint.format('cloudCredentials/{}/regions/{}').format(item['cloudCredentials'], item['region']), headers=ce_headers, cookies=ce_session)
        name = json.loads(region.text)['name']
        region_code = ""
        if "Northern Virginia" in name:
            region_code = 'us-east-1'
        elif "Frankfurt" in name:
            region_code = 'eu-central-1'
        elif "Paris" in name:
            region_code = 'eu-west-3'
        elif "Stockholm" in name:
            region_code = 'eu-north-1'
        elif "Northern California" in name:
            region_code = 'us-west-1'
        elif "Oregon" in name:
            region_code = 'us-west-2'
        elif "AWS GovCloud (US)" in name:
            region_code = 'us-gov-west-1'
        elif "Bahrain" in name:
            region_code = 'me-south-1'
        elif "Hong Kong" in name:
            region_code = 'ap-east-1'
        elif "Tokyo" in name:
            region_code = 'ap-northeast-1'
        elif "Singapore" in name:
            region_code = 'ap-southeast-1'
        elif "AWS GovCloud (US-East)" in name:
            region_code = 'us-gov-east-1'
        elif "Mumbai" in name:
            region_code = 'ap-south-1'
        elif "South America" in name:
            region_code = 'sa-east-1'
        elif "Sydney" in name:
            region_code = 'ap-southeast-2'
        elif "London" in name:
            region_code = 'eu-west-2'
        elif "Central" in name:
            region_code = 'ca-central-1'
        elif "Ireland" in name:
            region_code = 'eu-west-1'
        elif "Seoul" in name:
            region_code = 'ap-northeast-2'
        elif "Ohio" in name:
            region_code = 'us-east-2'
        else:
            print("Incorrect Region Name")
        region_ids.append(region_code)
    return region_ids
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



source/Tools Integration/MGN-Integration/MGN-automation-scripts/mfcommon.py [189:270]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def CElogin(userapitoken):
    login_data = {'userApiToken': userapitoken}
    r = requests.post(ce_address + ce_endpoint.format('login'),
                  data=json.dumps(login_data), headers=ce_headers)
    if r.status_code == 200:
        print("CloudEndure : You have successfully logged in")
        print("")
    if r.status_code != 200 and r.status_code != 307:
        if r.status_code == 401 or r.status_code == 403:
            print('ERROR: The CloudEndure login credentials provided cannot be authenticated....')
            return None, None
        elif r.status_code == 402:
            print('ERROR: There is no active license configured for this CloudEndure account....')
            return None, None
        elif r.status_code == 429:
            print('ERROR: CloudEndure Authentication failure limit has been reached. The service will become available for additional requests after a timeout....')
            return None, None

    # check if need to use a different API entry point
    if r.history:
        endpointnew = '/' + '/'.join(r.url.split('/')[3:-1]) + '/{}'
        r = requests.post(ce_address + endpointnew.format('login'),
                      data=json.dumps(login_data), headers=ce_headers)
    try:
       ce_headers['X-XSRF-TOKEN'] = r.cookies['XSRF-TOKEN']
       return r.cookies['session'], ce_headers['X-XSRF-TOKEN']
    except:
       pass

    return r.cookies['session'], None

def GetCERegion(project_id, ce_session, ce_headers):
    region_ids = []
    rep = requests.get(ce_address + ce_endpoint.format('projects/{}/replicationConfigurations').format(project_id), headers=ce_headers, cookies=ce_session)
    for item in json.loads(rep.text)['items']:
        region = requests.get(ce_address + ce_endpoint.format('cloudCredentials/{}/regions/{}').format(item['cloudCredentials'], item['region']), headers=ce_headers, cookies=ce_session)
        name = json.loads(region.text)['name']
        region_code = ""
        if "Northern Virginia" in name:
            region_code = 'us-east-1'
        elif "Frankfurt" in name:
            region_code = 'eu-central-1'
        elif "Paris" in name:
            region_code = 'eu-west-3'
        elif "Stockholm" in name:
            region_code = 'eu-north-1'
        elif "Northern California" in name:
            region_code = 'us-west-1'
        elif "Oregon" in name:
            region_code = 'us-west-2'
        elif "AWS GovCloud (US)" in name:
            region_code = 'us-gov-west-1'
        elif "Bahrain" in name:
            region_code = 'me-south-1'
        elif "Hong Kong" in name:
            region_code = 'ap-east-1'
        elif "Tokyo" in name:
            region_code = 'ap-northeast-1'
        elif "Singapore" in name:
            region_code = 'ap-southeast-1'
        elif "AWS GovCloud (US-East)" in name:
            region_code = 'us-gov-east-1'
        elif "Mumbai" in name:
            region_code = 'ap-south-1'
        elif "South America" in name:
            region_code = 'sa-east-1'
        elif "Sydney" in name:
            region_code = 'ap-southeast-2'
        elif "London" in name:
            region_code = 'eu-west-2'
        elif "Central" in name:
            region_code = 'ca-central-1'
        elif "Ireland" in name:
            region_code = 'eu-west-1'
        elif "Seoul" in name:
            region_code = 'ap-northeast-2'
        elif "Ohio" in name:
            region_code = 'us-east-2'
        else:
            print("Incorrect Region Name")
        region_ids.append(region_code)
    return region_ids
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



