From 558255e222812e6d67febcc0056e17820ec33120 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Mon, 20 Apr 2015 15:01:51 +0200 Subject: [PATCH] Add support for the storage API Change-Id: Icefefc27b6f77268b473d8ddf79963a92354c666 --- cloudkittyclient/shell.py | 2 ++ cloudkittyclient/v1/client.py | 2 ++ cloudkittyclient/v1/storage/__init__.py | 20 ++++++++++++ cloudkittyclient/v1/storage/dataframe.py | 29 +++++++++++++++++ cloudkittyclient/v1/storage/shell.py | 40 ++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 cloudkittyclient/v1/storage/__init__.py create mode 100644 cloudkittyclient/v1/storage/dataframe.py create mode 100644 cloudkittyclient/v1/storage/shell.py diff --git a/cloudkittyclient/shell.py b/cloudkittyclient/shell.py index dccf281..cc526ce 100644 --- a/cloudkittyclient/shell.py +++ b/cloudkittyclient/shell.py @@ -32,6 +32,7 @@ from cloudkittyclient.common import utils from cloudkittyclient import exc from cloudkittyclient.openstack.common import cliutils from cloudkittyclient.v1.report import shell as report_shell +from cloudkittyclient.v1.storage import shell as storage_shell SUBMODULES_NAMESPACE = 'cloudkitty.client.modules' @@ -119,6 +120,7 @@ class CloudkittyShell(object): submodule = utils.import_versioned_module(version, 'shell') self._find_actions(subparsers, submodule) self._find_actions(subparsers, report_shell) + self._find_actions(subparsers, storage_shell) extensions = extension.ExtensionManager( SUBMODULES_NAMESPACE, ) diff --git a/cloudkittyclient/v1/client.py b/cloudkittyclient/v1/client.py index 884088a..60014c7 100644 --- a/cloudkittyclient/v1/client.py +++ b/cloudkittyclient/v1/client.py @@ -19,6 +19,7 @@ from cloudkittyclient import client as ckclient from cloudkittyclient.openstack.common.apiclient import client from cloudkittyclient.v1 import core from cloudkittyclient.v1 import report +from cloudkittyclient.v1 import storage SUBMODULES_NAMESPACE = 'cloudkitty.client.modules' @@ -56,6 +57,7 @@ class Client(object): self.modules = core.CloudkittyModuleManager(self.http_client) self.reports = report.ReportManager(self.http_client) self.quotations = core.QuotationManager(self.http_client) + self.storage = storage.StorageManager(self.http_client) self._expose_submodules() def _expose_submodules(self): diff --git a/cloudkittyclient/v1/storage/__init__.py b/cloudkittyclient/v1/storage/__init__.py new file mode 100644 index 0000000..90d6493 --- /dev/null +++ b/cloudkittyclient/v1/storage/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2015 Objectif Libre +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from cloudkittyclient.v1.storage import dataframe + + +class StorageManager(object): + def __init__(self, http_client): + self.dataframes = dataframe.DataFrameManager(http_client) diff --git a/cloudkittyclient/v1/storage/dataframe.py b/cloudkittyclient/v1/storage/dataframe.py new file mode 100644 index 0000000..8dbd442 --- /dev/null +++ b/cloudkittyclient/v1/storage/dataframe.py @@ -0,0 +1,29 @@ +# Copyright 2015 Objectif Libre +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from cloudkittyclient.common import base + + +class DataFrameResource(base.Resource): + key = 'dataframe' + + def __repr__(self): + return "" % self._info + + +class DataFrameManager(base.CrudManager): + resource_class = DataFrameResource + base_url = '/v1/storage' + key = 'dataframe' + collection_key = 'dataframes' diff --git a/cloudkittyclient/v1/storage/shell.py b/cloudkittyclient/v1/storage/shell.py new file mode 100644 index 0000000..00f8d4e --- /dev/null +++ b/cloudkittyclient/v1/storage/shell.py @@ -0,0 +1,40 @@ +# Copyright 2015 Objectif Libre +# +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from cloudkittyclient.common import utils + + +@utils.arg('--begin', + help='Starting date/time (YYYY-MM-ddThh:mm:ss)', + required=True) +@utils.arg('--end', + help='Ending date/time (YYYY-MM-ddThh:mm:ss)', + required=True) +@utils.arg('--tenant', + help='Tenant ID', + required=False, + default=None) +@utils.arg('--resource-type', + help='Resource type (compute, image, ...)', + required=False, + default=None) +def do_storage_dataframe_list(cc, args): + data = cc.storage.dataframes.list(begin=args.begin, end=args.end, + tenant_id=args.tenant, + resource_type=args.resource_type) + fields = ['begin', 'end', 'tenant_id', 'resources'] + fields_labels = ['Begin', 'End', 'Tenant ID', 'Resources'] + utils.print_list(data, fields, fields_labels, sortby=0)