Merge "Transitioned collector client to new API"

This commit is contained in:
Jenkins
2015-08-01 03:59:40 +00:00
committed by Gerrit Code Review
6 changed files with 150 additions and 14 deletions

View File

@@ -31,6 +31,7 @@ from cloudkittyclient import client as ckclient
from cloudkittyclient.common import utils from cloudkittyclient.common import utils
from cloudkittyclient import exc from cloudkittyclient import exc
from cloudkittyclient.openstack.common import cliutils from cloudkittyclient.openstack.common import cliutils
from cloudkittyclient.v1.collector import shell as collector_shell
from cloudkittyclient.v1.report import shell as report_shell from cloudkittyclient.v1.report import shell as report_shell
from cloudkittyclient.v1.storage import shell as storage_shell from cloudkittyclient.v1.storage import shell as storage_shell
@@ -119,6 +120,7 @@ class CloudkittyShell(object):
subparsers = parser.add_subparsers(metavar='<subcommand>') subparsers = parser.add_subparsers(metavar='<subcommand>')
submodule = utils.import_versioned_module(version, 'shell') submodule = utils.import_versioned_module(version, 'shell')
self._find_actions(subparsers, submodule) self._find_actions(subparsers, submodule)
self._find_actions(subparsers, collector_shell)
self._find_actions(subparsers, report_shell) self._find_actions(subparsers, report_shell)
self._find_actions(subparsers, storage_shell) self._find_actions(subparsers, storage_shell)
extensions = extension.ExtensionManager( extensions = extension.ExtensionManager(

View File

@@ -17,6 +17,7 @@ from stevedore import extension
from cloudkittyclient import client as ckclient from cloudkittyclient import client as ckclient
from cloudkittyclient.openstack.common.apiclient import client from cloudkittyclient.openstack.common.apiclient import client
from cloudkittyclient.v1 import collector
from cloudkittyclient.v1 import core from cloudkittyclient.v1 import core
from cloudkittyclient.v1 import report from cloudkittyclient.v1 import report
from cloudkittyclient.v1 import storage from cloudkittyclient.v1 import storage
@@ -55,6 +56,7 @@ class Client(object):
self.http_client = client.BaseClient(self.client) self.http_client = client.BaseClient(self.client)
self.modules = core.CloudkittyModuleManager(self.http_client) self.modules = core.CloudkittyModuleManager(self.http_client)
self.collector = collector.CollectorManager(self.http_client)
self.reports = report.ReportManager(self.http_client) self.reports = report.ReportManager(self.http_client)
self.quotations = core.QuotationManager(self.http_client) self.quotations = core.QuotationManager(self.http_client)
self.storage = storage.StorageManager(self.http_client) self.storage = storage.StorageManager(self.http_client)

View File

@@ -12,19 +12,11 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from cloudkittyclient.common import base from cloudkittyclient.v1.collector import mapping
from cloudkittyclient.v1.collector import state
class Collector(base.Resource): class CollectorManager(object):
def __init__(self, http_client):
key = 'collector' self.mappings = mapping.MappingManager(http_client)
self.states = state.StateManager(http_client)
def __repr__(self):
return "<Collector %s>" % self._info
class CollectorManager(base.Manager):
resource_class = Collector
base_url = "/v1/rating"
key = "collector"
collection_key = "collectors"

View File

@@ -0,0 +1,30 @@
# 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 Mapping(base.Resource):
key = 'mapping'
def __repr__(self):
return "<Mapping %s>" % self._info
class MappingManager(base.CrudManager):
resource_class = Mapping
base_url = "/v1/collector"
key = "mapping"
collection_key = "mappings"

View File

@@ -0,0 +1,80 @@
# 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('--collector',
help='Collector name to filter on.',
required=False,
default=None)
def do_collector_mapping_list(cc, args):
data = cc.collector.mappings.list(collector=args.collector)
fields = ['service', 'collector']
fields_labels = ['Service', 'Collector']
utils.print_list(data, fields, fields_labels, sortby=0)
@utils.arg('--service',
help='Which service to get the mapping for.',
required=True)
def do_collector_mapping_get(cc, args):
data = cc.collector.mappings.get(mapping_id=args.service)
utils.print_dict(data.to_dict())
@utils.arg('--collector',
help='Map a service to this collector.',
required=True)
@utils.arg('--service',
help='Map a collector to this service.',
required=True)
def do_collector_mapping_create(cc, args):
out = cc.collector.mappings.create(service=args.service,
collector=args.collector)
utils.print_dict(out.to_dict())
@utils.arg('--service',
help='Filter on this service.',
required=True)
def do_collector_mapping_delete(cc, args):
# TODO(sheeprine): Use a less hacky way to do this
cc.collector.mappings.delete(mapping_id=args.service)
@utils.arg('--name',
help='Name of the collector.',
required=True)
def do_collector_state_get(cc, args):
data = cc.collector.states.get(state_id=args.name)
utils.print_dict(data.to_dict())
@utils.arg('--name',
help='Name of the collector.',
required=True)
def do_collector_state_enable(cc, args):
new_state = cc.collector.states.update(name=args.name, enabled=True)
utils.print_dict(new_state.to_dict())
@utils.arg('--name',
help='Name of the collector.',
required=True)
def do_collector_state_disable(cc, args):
new_state = cc.collector.states.update(name=args.name, enabled=False)
utils.print_dict(new_state.to_dict())

View File

@@ -0,0 +1,30 @@
# 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 State(base.Resource):
key = 'state'
def __repr__(self):
return "<State %s>" % self._info
class StateManager(base.CrudManager):
resource_class = State
base_url = "/v1/collector"
key = "state"
collection_key = "states"