Merge "Transitioned collector client to new API"
This commit is contained in:
commit
5efcd30fdd
|
@ -31,6 +31,7 @@ from cloudkittyclient import client as ckclient
|
|||
from cloudkittyclient.common import utils
|
||||
from cloudkittyclient import exc
|
||||
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.storage import shell as storage_shell
|
||||
|
||||
|
@ -119,6 +120,7 @@ class CloudkittyShell(object):
|
|||
subparsers = parser.add_subparsers(metavar='<subcommand>')
|
||||
submodule = utils.import_versioned_module(version, 'shell')
|
||||
self._find_actions(subparsers, submodule)
|
||||
self._find_actions(subparsers, collector_shell)
|
||||
self._find_actions(subparsers, report_shell)
|
||||
self._find_actions(subparsers, storage_shell)
|
||||
extensions = extension.ExtensionManager(
|
||||
|
|
|
@ -17,6 +17,7 @@ from stevedore import extension
|
|||
|
||||
from cloudkittyclient import client as ckclient
|
||||
from cloudkittyclient.openstack.common.apiclient import client
|
||||
from cloudkittyclient.v1 import collector
|
||||
from cloudkittyclient.v1 import core
|
||||
from cloudkittyclient.v1 import report
|
||||
from cloudkittyclient.v1 import storage
|
||||
|
@ -55,6 +56,7 @@ class Client(object):
|
|||
|
||||
self.http_client = client.BaseClient(self.client)
|
||||
self.modules = core.CloudkittyModuleManager(self.http_client)
|
||||
self.collector = collector.CollectorManager(self.http_client)
|
||||
self.reports = report.ReportManager(self.http_client)
|
||||
self.quotations = core.QuotationManager(self.http_client)
|
||||
self.storage = storage.StorageManager(self.http_client)
|
||||
|
|
|
@ -12,19 +12,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cloudkittyclient.common import base
|
||||
from cloudkittyclient.v1.collector import mapping
|
||||
from cloudkittyclient.v1.collector import state
|
||||
|
||||
|
||||
class Collector(base.Resource):
|
||||
|
||||
key = 'collector'
|
||||
|
||||
def __repr__(self):
|
||||
return "<Collector %s>" % self._info
|
||||
|
||||
|
||||
class CollectorManager(base.Manager):
|
||||
resource_class = Collector
|
||||
base_url = "/v1/rating"
|
||||
key = "collector"
|
||||
collection_key = "collectors"
|
||||
class CollectorManager(object):
|
||||
def __init__(self, http_client):
|
||||
self.mappings = mapping.MappingManager(http_client)
|
||||
self.states = state.StateManager(http_client)
|
||||
|
|
|
@ -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"
|
|
@ -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())
|
|
@ -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"
|
Loading…
Reference in New Issue