|
32 | 32 | except ImportError:
|
33 | 33 | HAS_GOOGLE_LIBRARIES = False
|
34 | 34 |
|
| 35 | +try: |
| 36 | + from azure.mgmt.automation import AutomationClient |
| 37 | + import azure.mgmt.automation.models as AutomationModel |
| 38 | + |
| 39 | + HAS_AZURE_LIBRARIES = True |
| 40 | +except ImportError: |
| 41 | + HAS_AZURE_LIBRARIES = False |
| 42 | + |
35 | 43 | routes = web.RouteTableDef()
|
36 | 44 | PROJECT_ROOT = dirname(dirname(__file__))
|
37 | 45 | pool = None
|
@@ -253,6 +261,46 @@ async def check_scaleway_config(_):
|
253 | 261 | return web.json_response({"has_secret": 'SCW_TOKEN' in os.environ})
|
254 | 262 |
|
255 | 263 |
|
| 264 | +@routes.get('/hetzner_config') |
| 265 | +async def check_hetzner_config(_): |
| 266 | + return web.json_response({"has_secret": 'HCLOUD_TOKEN' in os.environ}) |
| 267 | + |
| 268 | + |
| 269 | +@routes.post('/hetzner_regions') |
| 270 | +async def hetzner_regions(request): |
| 271 | + data = await request.json() |
| 272 | + token = data.get('token', os.environ.get('HCLOUD_TOKEN')) |
| 273 | + if not token: |
| 274 | + return web.json_response({'error': 'no token provided'}, status=400) |
| 275 | + |
| 276 | + headers = { |
| 277 | + 'Content-Type': 'application/json', |
| 278 | + 'Authorization': 'Bearer {0}'.format(token), |
| 279 | + } |
| 280 | + async with ClientSession(headers=headers) as session: |
| 281 | + async with session.get('https://api.hetzner.cloud/v1/datacenters') as r: |
| 282 | + json_body = await r.json() |
| 283 | + return web.json_response(json_body) |
| 284 | + |
| 285 | + |
| 286 | +@routes.get('/azure_config') |
| 287 | +async def azure_config(_): |
| 288 | + if not HAS_REQUESTS: |
| 289 | + return web.json_response({'error': 'missing_requests'}, status=400) |
| 290 | + if not HAS_AZURE_LIBRARIES: |
| 291 | + return web.json_response({'error': 'missing_azure'}, status=400) |
| 292 | + response = {'status': 'ok'} |
| 293 | + return web.json_response(response) |
| 294 | + |
| 295 | + |
| 296 | +@routes.get('/azure_regions') |
| 297 | +async def azure_regions(_): |
| 298 | + with open(join(PROJECT_ROOT, 'roles', 'cloud-azure', 'defaults', 'main.yml'), 'r') as f: |
| 299 | + regions_json = yaml.safe_load(f.read()) |
| 300 | + regions = json.loads(regions_json['_azure_regions']) |
| 301 | + return web.json_response(regions) |
| 302 | + |
| 303 | + |
256 | 304 | app = web.Application()
|
257 | 305 | app.router.add_routes(routes)
|
258 | 306 | app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))])
|
|
0 commit comments