diff --git a/app/server.py b/app/server.py index 46d5b7787..34c5c5401 100644 --- a/app/server.py +++ b/app/server.py @@ -32,6 +32,14 @@ except ImportError: HAS_GOOGLE_LIBRARIES = False +try: + from azure.mgmt.automation import AutomationClient + import azure.mgmt.automation.models as AutomationModel + + HAS_AZURE_LIBRARIES = True +except ImportError: + HAS_AZURE_LIBRARIES = False + routes = web.RouteTableDef() PROJECT_ROOT = dirname(dirname(__file__)) pool = None @@ -253,6 +261,46 @@ async def check_scaleway_config(_): return web.json_response({"has_secret": 'SCW_TOKEN' in os.environ}) +@routes.get('/hetzner_config') +async def check_hetzner_config(_): + return web.json_response({"has_secret": 'HCLOUD_TOKEN' in os.environ}) + + +@routes.post('/hetzner_regions') +async def hetzner_regions(request): + data = await request.json() + token = data.get('token', os.environ.get('HCLOUD_TOKEN')) + if not token: + return web.json_response({'error': 'no token provided'}, status=400) + + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(token), + } + async with ClientSession(headers=headers) as session: + async with session.get('https://api.hetzner.cloud/v1/datacenters') as r: + json_body = await r.json() + return web.json_response(json_body) + + +@routes.get('/azure_config') +async def azure_config(_): + if not HAS_REQUESTS: + return web.json_response({'error': 'missing_requests'}, status=400) + if not HAS_AZURE_LIBRARIES: + return web.json_response({'error': 'missing_azure'}, status=400) + response = {'status': 'ok'} + return web.json_response(response) + + +@routes.get('/azure_regions') +async def azure_regions(_): + with open(join(PROJECT_ROOT, 'roles', 'cloud-azure', 'defaults', 'main.yml'), 'r') as f: + regions_json = yaml.safe_load(f.read()) + regions = json.loads(regions_json['_azure_regions']) + return web.json_response(regions) + + app = web.Application() app.router.add_routes(routes) app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))]) diff --git a/app/static/provider-azure.vue b/app/static/provider-azure.vue new file mode 100644 index 000000000..afd2c7bfc --- /dev/null +++ b/app/static/provider-azure.vue @@ -0,0 +1,96 @@ + + + + Python module "requests" is missing, please install it to proceed + + + Python Azure SDK libraries are missing, please install it to proceed + + + Prerequisites: Install azure-cli + + + + Next + + + + + diff --git a/app/static/provider-setup.vue b/app/static/provider-setup.vue index 5ef2464a9..bf5a1601f 100644 --- a/app/static/provider-setup.vue +++ b/app/static/provider-setup.vue @@ -63,7 +63,8 @@ module.exports = { 'gce': window.httpVueLoader('/static/provider-gce.vue'), 'vultr': window.httpVueLoader('/static/provider-vultr.vue'), 'scaleway': window.httpVueLoader('/static/provider-scaleway.vue'), - 'hetzner': window.httpVueLoader('/static/provider-hetzner.vue') + 'hetzner': window.httpVueLoader('/static/provider-hetzner.vue'), + 'azure': window.httpVueLoader('/static/provider-azure.vue') } };