Update the BigAnimal API version to V2. #5147

This commit is contained in:
Khushboo Vashi 2022-11-24 10:49:42 +05:30 committed by GitHub
parent 9d3654bd69
commit 6442854fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 51 deletions

View File

@ -19,7 +19,7 @@ from utils.io import debug, error, output
class BigAnimalProvider(AbsProvider):
BASE_URL = 'https://portal.biganimal.com/api/v1'
BASE_URL = 'https://portal.biganimal.com/api/v2'
def __init__(self):
self._clients = {}
@ -87,7 +87,9 @@ class BigAnimalProvider(AbsProvider):
ip = ip.split(',')
for i in ip:
ip_ranges.append([i, 'pgcloud client {}'.format(i)])
ip_ranges.append({'cidrBlock': i,
'description': 'pgcloud client {}'.format(i)
})
debug('Creating BigAnimal cluster: {}...'.format(args.name))
@ -98,23 +100,27 @@ class BigAnimalProvider(AbsProvider):
_data = {
'clusterName': args.name,
'instanceTypeId': args.instance_type,
'instanceType': {'instanceTypeId': args.instance_type},
'password': self._database_pass,
'postgresTypeId': args.db_type,
'postgresVersion': args.db_version,
'pgType': {'pgTypeId': args.db_type},
'pgVersion': {'pgVersionId': args.db_version},
'privateNetworking': private_network,
'providerId': 'azure',
'regionId': args.region,
'replicas': 3,
'volumePropertiesId': args.volume_properties,
'volumeTypeId': args.volume_type,
'clusterArch': {'id': args.cluster_arch, 'nodes': int(
args.nodes)},
'pgConfigMap': [],
'provider': {'cloudProviderId': 'azure'},
'region': {'regionId': args.region},
'replicas': 1,
'storage': {
'volumePropertiesId': args.volume_properties,
'volumeTypeId': args.volume_type
},
'clusterArchitecture': {
'clusterArchitectureId': args.cluster_arch,
'nodes': int(args.nodes)
},
'pgConfig': [],
}
if not private_network:
_data['allowIpRangeMap'] = ip_ranges
_data['allowedIpRanges'] = ip_ranges
cluster_resp = requests.post(_url,
headers=_headers,
@ -122,17 +128,17 @@ class BigAnimalProvider(AbsProvider):
if cluster_resp.status_code == 202 and cluster_resp.content:
cluster_info = json.loads(cluster_resp.content)
instance_id = cluster_info['pgId']
instance_id = cluster_info['data']['clusterId']
instance = self.get_instance_status(instance_id)
data = {'instance': {
'ImageName': instance['imageName'],
'Database Type': instance['pgType']['name'],
'Hostname': instance['clusterConnectionInfo'][
'ImageName': instance['clusterName'],
'Database Type': instance['pgType']['pgTypeName'],
'Hostname': instance['connection'][
'serviceName'],
'Port': instance['clusterConnectionInfo']['port'],
'Database': instance['clusterConnectionInfo'][
'Port': instance['connection']['port'],
'Database': instance['connection'][
'databaseName'],
'Username': instance['clusterConnectionInfo'][
'Username': instance['connection'][
'username']
}}
@ -159,14 +165,9 @@ class BigAnimalProvider(AbsProvider):
if cluster_resp.status_code == 200 and cluster_resp.content:
cluster_info = json.loads(cluster_resp.content)
self._cluster_info = cluster_info[0]
self._cluster_info = cluster_info['data']
if self._cluster_info['instance'] != 0 and\
self._cluster_info['phase'] not in [
'Cluster creation request received',
'Setting up primary',
'Creating CNP cluster'
]:
if self._cluster_info['phase'] == 'Cluster in healthy state':
running = False
if status != self._cluster_info['phase']:

View File

@ -153,7 +153,7 @@ def biganimal_volume_properties(region_id, volume_type):
class BigAnimalProvider():
"""BigAnimal provider class"""
BASE_URL = 'https://portal.biganimal.com/api/v1'
BASE_URL = 'https://portal.biganimal.com/api/v2'
def __init__(self):
self.provider = {}
@ -228,7 +228,8 @@ class BigAnimalProvider():
def exchange_token(self):
_url = "{0}/{1}".format(self.BASE_URL, 'auth/token')
_headers = {"content-type": "application/json"}
_headers = {"content-type": "application/json",
"accept": "application/json"}
_data = {'token': self.raw_access_token}
token_resp = requests.post(_url,
headers=_headers,
@ -249,14 +250,14 @@ class BigAnimalProvider():
"""
_url = "{0}/{1}".format(
self.BASE_URL,
'admin/permissions')
'permissions')
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code != 200:
return False
if resp.status_code == 200 and resp.content:
content = json.loads(resp.content)
if 'permissionsList' in content and 'create:clusters' in content[
'permissionsList']:
if 'data' in content and 'create:clusters' in content[
'data']:
return True
return False
@ -269,7 +270,7 @@ class BigAnimalProvider():
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code == 200 and resp.content:
regions_resp = json.loads(resp.content)
for value in regions_resp['regionsList']:
for value in regions_resp['data']:
regions.append({
'label': value['regionName'],
'value': value['regionId']
@ -286,17 +287,17 @@ class BigAnimalProvider():
"""Get Postgres Types."""
_url = "{0}/{1}".format(
self.BASE_URL,
'postgres-types')
'pg-types')
pg_types = []
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code == 200 and resp.content:
pg_types_resp = json.loads(resp.content)
for value in pg_types_resp['pgTypesList']:
for value in pg_types_resp['data']:
# Extreme HA is in Beta, so avoid it
if len(value['supportedClusterArchitectureIds']) != 1:
pg_types.append({
'label': value['name'],
'value': value['id']
'label': value['pgTypeName'],
'value': value['pgTypeId']
})
return pg_types
@ -304,15 +305,15 @@ class BigAnimalProvider():
"""Get Postgres Versions."""
_url = "{0}/{1}".format(
self.BASE_URL,
'postgres-versions')
'pg-versions')
pg_versions = []
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code == 200 and resp.content:
pg_versions_resp = json.loads(resp.content)
for value in pg_versions_resp['pgVersionsList']:
for value in pg_versions_resp['data']:
pg_versions.append({
'label': value['versionName'],
'value': value['versionId']
'label': value['pgVersionName'],
'value': value['pgVersionId']
})
return pg_versions
@ -327,7 +328,7 @@ class BigAnimalProvider():
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code == 200 and resp.content:
pg_types = json.loads(resp.content)
return pg_types['instanceTypesList']
return pg_types['data']
return []
def get_volume_types(self, region_id):
@ -342,10 +343,10 @@ class BigAnimalProvider():
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code == 200 and resp.content:
volume_resp = json.loads(resp.content)
for value in volume_resp['volumeTypesList']:
for value in volume_resp['data']:
volume_types.append({
'label': value['displayName'],
'value': value['id']
'label': value['volumeTypeName'],
'value': value['volumeTypeId']
})
return volume_types
@ -362,10 +363,10 @@ class BigAnimalProvider():
resp = requests.get(_url, headers=self._get_headers())
if resp.status_code == 200 and resp.content:
volume_prop = json.loads(resp.content)
for value in volume_prop['volumePropertiesList']:
for value in volume_prop['data']:
volume_properties.append({
'label': value['value'],
'value': value['id']
'label': value['volumePropertiesName'],
'value': value['volumePropertiesId']
})
return volume_properties

View File

@ -422,8 +422,8 @@ class BigAnimalInstanceSchema extends BaseUISchema {
_options = [];
_.forEach(_types, (value) => {
_options.push({
'label': value.instanceType + ' (' + value.cpu + 'vCPU, ' + value.ram + 'GB RAM)',
'value': value.instanceType + ' (' + value.cpu + 'vCPU, ' + value.ram + 'GB RAM)' + '||' + value.id,
'label': value.instanceTypeName + ' (' + value.cpu + 'vCPU, ' + value.ram + 'GB RAM)',
'value': value.instanceTypeName + ' (' + value.cpu + 'vCPU, ' + value.ram + 'GB RAM)' + '||' + value.instanceTypeId,
});
});
return _options;