Skip to content

Commit

Permalink
Cloud APIEndpoint, APIResource and clouds list command
Browse files Browse the repository at this point in the history
  • Loading branch information
machristie committed Apr 26, 2018
1 parent c3e5e4e commit 7cd5b20
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cloudlaunch_cli/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, url=None, token=None):
credentials.azure = endpoints.AzureCredentials(config)
credentials.gce = endpoints.GCECredentials(config)
self.auth.user.credentials = credentials
self.infrastructure = types.SimpleNamespace()
self.infrastructure.clouds = endpoints.Clouds(config)


# For testing purposes only
Expand Down
6 changes: 6 additions & 0 deletions cloudlaunch_cli/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,9 @@ class Applications(CoreAPIBasedAPIEndpoint):
path = ['applications']
resource_type = resources.Application
id_param_name = 'slug'


class Clouds(CoreAPIBasedAPIEndpoint):
path = ['infrastructure', 'clouds']
resource_type = resources.Cloud
id_param_name = 'slug'
2 changes: 1 addition & 1 deletion cloudlaunch_cli/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def run_delete(self):


class Cloud(APIResource):
pass
id_field_name = 'slug'


class Image(APIResource):
Expand Down
30 changes: 30 additions & 0 deletions cloudlaunch_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,36 @@ def _print_applications(applications):
**app._data))


@click.group()
def clouds():
pass


@click.command()
def list_clouds():
clouds = cloudlaunch_client.infrastructure.clouds.list()
_print_clouds(clouds)


def _print_clouds(clouds):
slug_width = max([len(cloud.slug) for cloud in clouds]) + 1
if len(clouds) > 0:
header_format = "{{:{slug_width!s}s}} {{:20s}} {{:12s}} {{:20s}}"\
.format(slug_width=slug_width)
print(header_format.format(
"Slug", "Name", "Cloud Type", "Region"))
else:
print("No clouds found.")
row_format = "{{slug:{slug_width!s}.{slug_width!s}s}} {{name:20.20s}} "\
"{{cloud_type:12.12}} {{region_name:20.20s}}"\
.format(slug_width=slug_width)
for cloud in clouds:
print(row_format.format(**cloud.asdict()))


client.add_command(deployments)
client.add_command(applications)
client.add_command(clouds)
client.add_command(config)

config.add_command(set_config, name='set')
Expand All @@ -154,5 +182,7 @@ def _print_applications(applications):
applications.add_command(create_application, name='create')
applications.add_command(list_applications, name='list')

clouds.add_command(list_clouds, name='list')

if __name__ == '__main__':
client()

0 comments on commit 7cd5b20

Please sign in to comment.