|
3 | 3 |
|
4 | 4 | import yaml |
5 | 5 | import boto3 |
6 | | -from os.path import join, dirname |
7 | | -from aiohttp import web |
| 6 | +from os.path import join, dirname, expanduser |
| 7 | +from aiohttp import web, ClientSession |
8 | 8 | import concurrent.futures |
9 | 9 | import sys |
| 10 | +import os |
10 | 11 |
|
11 | 12 | from google.auth.transport.requests import AuthorizedSession |
12 | 13 | from google.oauth2 import service_account |
@@ -165,6 +166,32 @@ async def gce_regions(request): |
165 | 166 | return web.json_response(json.loads(response.content)) |
166 | 167 |
|
167 | 168 |
|
| 169 | +@routes.get('/vultr_config') |
| 170 | +async def check_vultr_config(request): |
| 171 | + default_path = expanduser(join('~', '.vultr.ini')) |
| 172 | + response = {'path': None} |
| 173 | + try: |
| 174 | + open(default_path, 'r').read() |
| 175 | + response['path'] = default_path |
| 176 | + except IOError: |
| 177 | + pass |
| 178 | + |
| 179 | + if 'VULTR_API_CONFIG' in os.environ: |
| 180 | + try: |
| 181 | + open(os.environ['VULTR_API_CONFIG'], 'r').read() |
| 182 | + response['path'] = os.environ['VULTR_API_CONFIG'] |
| 183 | + except IOError: |
| 184 | + pass |
| 185 | + return web.json_response(response) |
| 186 | + |
| 187 | + |
| 188 | +@routes.get('/vultr_regions') |
| 189 | +async def vultr_regions(request): |
| 190 | + async with ClientSession() as session: |
| 191 | + async with session.get('https://api.vultr.com/v1/regions/list') as r: |
| 192 | + json_body = await r.json() |
| 193 | + return web.json_response(json_body) |
| 194 | + |
168 | 195 | app = web.Application() |
169 | 196 | app.router.add_routes(routes) |
170 | 197 | app.add_routes([web.static('/static', join(PROJECT_ROOT, 'app', 'static'))]) |
|
0 commit comments