Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
faf5c656af | ||
|
|
fc425e741d | ||
|
|
74a382ecb6 | ||
|
|
59ef5ebda0 | ||
|
|
e273aa5b55 | ||
|
|
fae4ef7a03 | ||
|
|
f3ca2e6944 | ||
|
|
ac61ea3499 | ||
|
|
e689b3233e | ||
|
|
1f422f4c5c | ||
|
|
fda6cdfb7b | ||
|
|
448bb4468f | ||
|
|
ce263ecc9e | ||
|
|
d2d3a475e2 | ||
|
|
e0a2b0edcd | ||
|
|
49aae96f22 | ||
|
|
6113f97d2f | ||
|
|
b7ceed787e | ||
|
|
f18cf64f9d | ||
|
|
c0bddb93d5 | ||
|
|
25beeb0819 | ||
|
|
4c6a252b76 | ||
|
|
7c3ab24bf1 | ||
|
|
b304d5978d | ||
|
|
bfc9c63952 | ||
|
|
51e14a5231 | ||
|
|
7e81c138ec |
@@ -9,10 +9,12 @@
|
||||
# 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 karborclient.common import utils
|
||||
from oslo_utils import importutils
|
||||
|
||||
|
||||
def Client(version, *args, **kwargs):
|
||||
module = utils.import_versioned_module(version, 'client')
|
||||
module = importutils.import_versioned_module(
|
||||
'karborclient', version, 'client'
|
||||
)
|
||||
client_class = getattr(module, 'Client')
|
||||
return client_class(*args, **kwargs)
|
||||
|
||||
@@ -24,7 +24,7 @@ import os
|
||||
import six
|
||||
from stevedore import extension
|
||||
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
from karborclient.common.apiclient import exceptions
|
||||
|
||||
|
||||
_discovered_plugins = {}
|
||||
@@ -41,7 +41,7 @@ def discover_auth_systems():
|
||||
def add_plugin(ext):
|
||||
_discovered_plugins[ext.name] = ext.plugin
|
||||
|
||||
ep_namespace = "karborclient.openstack.common.apiclient.auth"
|
||||
ep_namespace = "karborclient.common.apiclient.auth"
|
||||
mgr = extension.ExtensionManager(ep_namespace)
|
||||
mgr.map(add_plugin)
|
||||
|
||||
@@ -143,8 +143,7 @@ class BaseAuthPlugin(object):
|
||||
|
||||
@classmethod
|
||||
def add_opts(cls, parser):
|
||||
"""Populate the parser with the options for this plugin.
|
||||
"""
|
||||
"""Populate the parser with the options for this plugin."""
|
||||
for opt in cls.opt_names:
|
||||
# use `BaseAuthPlugin.common_opt_names` since it is never
|
||||
# changed in child classes
|
||||
@@ -153,8 +152,7 @@ class BaseAuthPlugin(object):
|
||||
|
||||
@classmethod
|
||||
def add_common_opts(cls, parser):
|
||||
"""Add options that are common for several plugins.
|
||||
"""
|
||||
"""Add options that are common for several plugins."""
|
||||
for opt in cls.common_opt_names:
|
||||
cls._parser_add_opt(parser, opt)
|
||||
|
||||
@@ -191,8 +189,7 @@ class BaseAuthPlugin(object):
|
||||
|
||||
@abc.abstractmethod
|
||||
def _do_authenticate(self, http_client):
|
||||
"""Protected method for authentication.
|
||||
"""
|
||||
"""Protected method for authentication."""
|
||||
|
||||
def sufficient_options(self):
|
||||
"""Check if all required options are present.
|
||||
@@ -31,8 +31,8 @@ from oslo_utils import uuidutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from karborclient.common.apiclient import exceptions
|
||||
from karborclient.i18n import _
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
|
||||
|
||||
def getid(obj):
|
||||
@@ -462,8 +462,7 @@ class Resource(object):
|
||||
|
||||
@property
|
||||
def human_id(self):
|
||||
"""Human-readable ID which can be used for bash completion.
|
||||
"""
|
||||
"""Human-readable ID which can be used for bash completion."""
|
||||
if self.HUMAN_ID:
|
||||
name = getattr(self, self.NAME_ATTR, None)
|
||||
if name is not None:
|
||||
@@ -481,7 +480,7 @@ class Resource(object):
|
||||
|
||||
def __getattr__(self, k):
|
||||
if k not in self.__dict__:
|
||||
#NOTE(bcwaldon): disallow lazy-loading if already loaded once
|
||||
# NOTE(bcwaldon): disallow lazy-loading if already loaded once
|
||||
if not self.is_loaded():
|
||||
self.get()
|
||||
return self.__getattr__(k)
|
||||
@@ -40,7 +40,6 @@ from karborclient.i18n import _
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -63,7 +62,7 @@ class HTTPClient(object):
|
||||
into terminal and send the same request with curl.
|
||||
"""
|
||||
|
||||
user_agent = "karborclient.openstack.common.apiclient"
|
||||
user_agent = "karborclient.common.apiclient"
|
||||
|
||||
def __init__(self,
|
||||
auth_plugin,
|
||||
@@ -272,7 +271,7 @@ class HTTPClient(object):
|
||||
|
||||
>>> def test_clients():
|
||||
... from keystoneclient.auth import keystone
|
||||
... from openstack.common.apiclient import client
|
||||
... from karborclient.common.apiclient import client
|
||||
... auth = keystone.KeystoneAuthPlugin(
|
||||
... username="user", password="pass", tenant_name="tenant",
|
||||
... auth_url="http://auth:5000/v2.0")
|
||||
@@ -358,8 +357,7 @@ class BaseClient(object):
|
||||
"Must be one of: %(version_map)s") % {
|
||||
'api_name': api_name,
|
||||
'version': version,
|
||||
'version_map': ', '.join(version_map.keys())
|
||||
}
|
||||
'version_map': ', '.join(version_map.keys())}
|
||||
raise exceptions.UnsupportedVersion(msg)
|
||||
|
||||
return importutils.import_class(client_path)
|
||||
@@ -28,8 +28,7 @@ from karborclient.i18n import _
|
||||
|
||||
|
||||
class ClientException(Exception):
|
||||
"""The base exception class for all exceptions this library raises.
|
||||
"""
|
||||
"""The base exception class for all exceptions this library raises."""
|
||||
pass
|
||||
|
||||
|
||||
@@ -107,8 +106,7 @@ class AmbiguousEndpoints(EndpointException):
|
||||
|
||||
|
||||
class HttpError(ClientException):
|
||||
"""The base exception class for all HTTP exceptions.
|
||||
"""
|
||||
"""The base exception class for all HTTP exceptions."""
|
||||
http_status = 0
|
||||
message = _("HTTP Error")
|
||||
|
||||
@@ -426,7 +424,7 @@ def from_response(response, method, url):
|
||||
"""
|
||||
|
||||
req_id = response.headers.get("x-openstack-request-id")
|
||||
#NOTE(hdd) true for older versions of nova and cinder
|
||||
# NOTE(hdd) true for older versions of nova and cinder
|
||||
if not req_id:
|
||||
req_id = response.headers.get("x-compute-request-id")
|
||||
kwargs = {
|
||||
@@ -30,7 +30,7 @@ import requests
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from karborclient.openstack.common.apiclient import client
|
||||
from karborclient.common.apiclient import client
|
||||
|
||||
|
||||
def assert_has_keys(dct, required=None, optional=None):
|
||||
@@ -48,8 +48,7 @@ def assert_has_keys(dct, required=None, optional=None):
|
||||
|
||||
|
||||
class TestResponse(requests.Response):
|
||||
"""Wrap requests.Response and provide a convenient initialization.
|
||||
"""
|
||||
"""Wrap requests.Response and provide a convenient initialization."""
|
||||
|
||||
def __init__(self, data):
|
||||
super(TestResponse, self).__init__()
|
||||
@@ -86,13 +85,12 @@ class FakeHTTPClient(client.HTTPClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.callstack = []
|
||||
self.fixtures = kwargs.pop("fixtures", None) or {}
|
||||
if not args and not "auth_plugin" in kwargs:
|
||||
if not args and "auth_plugin" not in kwargs:
|
||||
args = (None, )
|
||||
super(FakeHTTPClient, self).__init__(*args, **kwargs)
|
||||
|
||||
def assert_called(self, method, url, body=None, pos=-1):
|
||||
"""Assert than an API method was just called.
|
||||
"""
|
||||
"""Assert than an API method was just called."""
|
||||
expected = (method, url)
|
||||
called = self.callstack[pos][0:2]
|
||||
assert self.callstack, \
|
||||
@@ -107,8 +105,7 @@ class FakeHTTPClient(client.HTTPClient):
|
||||
(self.callstack[pos][3], body))
|
||||
|
||||
def assert_called_anytime(self, method, url, body=None):
|
||||
"""Assert than an API method was called anytime in the test.
|
||||
"""
|
||||
"""Assert than an API method was called anytime in the test."""
|
||||
expected = (method, url)
|
||||
|
||||
assert self.callstack, \
|
||||
@@ -20,8 +20,9 @@ import copy
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from karborclient.common.apiclient import exceptions
|
||||
from karborclient.common import http
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
|
||||
|
||||
SORT_DIR_VALUES = ('asc', 'desc')
|
||||
SORT_KEY_VALUES = ('id', 'status', 'name', 'created_at')
|
||||
|
||||
@@ -26,7 +26,7 @@ import requests
|
||||
import six
|
||||
from six.moves import urllib
|
||||
|
||||
from karborclient.openstack.common.apiclient import exceptions as exc
|
||||
from karborclient.common.apiclient import exceptions as exc
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
USER_AGENT = 'python-karborclient'
|
||||
|
||||
@@ -19,11 +19,10 @@ import six
|
||||
import uuid
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import importutils
|
||||
|
||||
import prettytable
|
||||
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
from karborclient.common.apiclient import exceptions
|
||||
|
||||
|
||||
# Decorator for cli-args
|
||||
@@ -49,13 +48,6 @@ def env(*vars, **kwargs):
|
||||
return kwargs.get('default', '')
|
||||
|
||||
|
||||
def import_versioned_module(version, submodule=None):
|
||||
module = 'karborclient.v%s' % version
|
||||
if submodule:
|
||||
module = '.'.join((module, submodule))
|
||||
return importutils.import_module(module)
|
||||
|
||||
|
||||
def _print(pt, order):
|
||||
if sys.version_info >= (3, 0):
|
||||
print(pt.get_string(sortby=order))
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#
|
||||
# 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.
|
||||
|
||||
import six
|
||||
|
||||
|
||||
six.add_move(six.MovedModule('mox', 'mox', 'mox3.mox'))
|
||||
@@ -28,13 +28,16 @@ from keystoneclient import session as ksession
|
||||
from oslo_log import handlers
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import importutils
|
||||
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
import karborclient
|
||||
from karborclient import client as karbor_client
|
||||
from karborclient.common.apiclient import exceptions as exc
|
||||
from karborclient.common import utils
|
||||
from karborclient.openstack.common.apiclient import exceptions as exc
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -149,7 +152,9 @@ class KarborShell(object):
|
||||
|
||||
self.subcommands = {}
|
||||
subparsers = parser.add_subparsers(metavar='<subcommand>')
|
||||
submodule = utils.import_versioned_module(version, 'shell')
|
||||
submodule = importutils.import_versioned_module(
|
||||
'karborclient', version, 'shell'
|
||||
)
|
||||
self._find_actions(subparsers, submodule)
|
||||
self._find_actions(subparsers, self)
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ import socket
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from karborclient.common.apiclient import exceptions as exc
|
||||
from karborclient.common import http
|
||||
from karborclient.openstack.common.apiclient import exceptions as exc
|
||||
from karborclient.tests.unit import fakes
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from oslo_log import log
|
||||
import six
|
||||
from testtools import matchers
|
||||
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
from karborclient.common.apiclient import exceptions
|
||||
import karborclient.shell
|
||||
from karborclient.tests.unit import base
|
||||
|
||||
|
||||
@@ -88,5 +88,5 @@ class CheckpointsTest(base.TestCaseShell):
|
||||
'checkpoints'.format(
|
||||
provider_id=FAKE_PROVIDER_ID),
|
||||
data={
|
||||
'checkpoint': {'plan_id': FAKE_PLAN_ID}},
|
||||
'checkpoint': {'plan_id': FAKE_PLAN_ID, 'extra-info': None}},
|
||||
headers={})
|
||||
|
||||
@@ -48,7 +48,7 @@ class PlansTest(base.TestCaseShell):
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
def test_create_plan(self, mock_request):
|
||||
mock_request.return_value = mock_request_return
|
||||
cs.plans.create('Plan name', 'provider_id', '', "")
|
||||
cs.plans.create('Plan name', 'provider_id', '', "", '')
|
||||
mock_request.assert_called_with(
|
||||
'POST',
|
||||
'/plans',
|
||||
@@ -56,7 +56,8 @@ class PlansTest(base.TestCaseShell):
|
||||
'plan': {'provider_id': 'provider_id',
|
||||
'name': 'Plan name',
|
||||
'resources': '',
|
||||
'parameters': ''}},
|
||||
'parameters': '',
|
||||
'description': ''}},
|
||||
headers={})
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.raw_request')
|
||||
|
||||
@@ -49,7 +49,9 @@ class RestoresTest(base.TestCaseShell):
|
||||
cs.restores.create('586cc6ce-e286-40bd-b2b5-dd32694d9944',
|
||||
'2220f8b1-975d-4621-a872-fa9afb43cb6c',
|
||||
'192.168.1.2:35357/v2.0',
|
||||
'{"username": "admin"}')
|
||||
'{}',
|
||||
'{"type": "password", "username": "admin", '
|
||||
'"password": "test"}')
|
||||
mock_request.assert_called_with(
|
||||
'POST',
|
||||
'/restores',
|
||||
@@ -57,9 +59,11 @@ class RestoresTest(base.TestCaseShell):
|
||||
'restore':
|
||||
{
|
||||
'checkpoint_id': '2220f8b1-975d-4621-a872-fa9afb43cb6c',
|
||||
'parameters': '{"username": "admin"}',
|
||||
'parameters': '{}',
|
||||
'provider_id': '586cc6ce-e286-40bd-b2b5-dd32694d9944',
|
||||
'restore_target': '192.168.1.2:35357/v2.0'
|
||||
'restore_target': '192.168.1.2:35357/v2.0',
|
||||
'restore_auth': '{"type": "password", "username": '
|
||||
'"admin", "password": "test"}'
|
||||
}}, headers={})
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
|
||||
@@ -66,7 +66,7 @@ class TriggersTest(base.TestCaseShell):
|
||||
headers={})
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
def test_show_plan(self, mock_request):
|
||||
def test_show_trigger(self, mock_request):
|
||||
mock_request.return_value = mock_request_return
|
||||
cs.triggers.get('1')
|
||||
mock_request.assert_called_with(
|
||||
@@ -82,3 +82,18 @@ class TriggersTest(base.TestCaseShell):
|
||||
'GET',
|
||||
'/triggers/1',
|
||||
headers={'X-Configuration-Session': 'fake_session_id'})
|
||||
|
||||
@mock.patch('karborclient.common.http.HTTPClient.json_request')
|
||||
def test_update_trigger(self, mock_request):
|
||||
mock_request.return_value = mock_request_return
|
||||
trigger_id = '123'
|
||||
data = {"name": "My Trigger",
|
||||
"properties": {"pattern": "0 10 * * *", "format": "crontab"}}
|
||||
body = {"trigger_info": data}
|
||||
cs.triggers.update(trigger_id, data)
|
||||
mock_request.assert_called_with(
|
||||
'PUT',
|
||||
'/triggers/123',
|
||||
data=body,
|
||||
headers={}
|
||||
)
|
||||
|
||||
@@ -26,8 +26,9 @@ class Checkpoint(base.Resource):
|
||||
class CheckpointManager(base.ManagerWithFind):
|
||||
resource_class = Checkpoint
|
||||
|
||||
def create(self, provider_id, plan_id):
|
||||
body = {'checkpoint': {'plan_id': plan_id}}
|
||||
def create(self, provider_id, plan_id, checkpoint_extra_info=None):
|
||||
body = {'checkpoint': {'plan_id': plan_id,
|
||||
'extra-info': checkpoint_extra_info}}
|
||||
url = "/providers/{provider_id}/" \
|
||||
"checkpoints" .format(provider_id=provider_id)
|
||||
return self._create(url, body, 'checkpoint')
|
||||
|
||||
@@ -24,8 +24,10 @@ class Plan(base.Resource):
|
||||
class PlanManager(base.ManagerWithFind):
|
||||
resource_class = Plan
|
||||
|
||||
def create(self, name, provider_id, resources, parameters):
|
||||
def create(self, name, provider_id, resources, parameters,
|
||||
description=None):
|
||||
body = {'plan': {'name': name,
|
||||
'description': description,
|
||||
'provider_id': provider_id,
|
||||
'resources': resources,
|
||||
'parameters': parameters
|
||||
|
||||
@@ -77,14 +77,27 @@ class ProtectableManager(base.ManagerWithFind):
|
||||
sort_dir=sort_dir, sort=sort)
|
||||
return self._list(url, response_key='instances', obj_class=Instances)
|
||||
|
||||
def get_instance(self, type, id, session_id=None):
|
||||
def get_instance(self, type, id, search_opts=None, session_id=None):
|
||||
if session_id:
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
else:
|
||||
headers = {}
|
||||
url = "/protectables/{protectable_type}/" \
|
||||
"instances/{protectable_id}".format(protectable_type=type,
|
||||
protectable_id=id)
|
||||
|
||||
if search_opts is None:
|
||||
search_opts = {}
|
||||
query_params = {}
|
||||
for key, val in search_opts.items():
|
||||
if val:
|
||||
query_params[key] = val
|
||||
query_string = ""
|
||||
if query_params:
|
||||
params = sorted(query_params.items(), key=lambda x: x[0])
|
||||
query_string = "?%s" % parse.urlencode(params)
|
||||
|
||||
url = ("/protectables/{protectable_type}/instances/"
|
||||
"{protectable_id}{query_string}").format(
|
||||
protectable_type=type, protectable_id=id,
|
||||
query_string=query_string)
|
||||
return self._get(url, response_key="instance", headers=headers)
|
||||
|
||||
def _build_instances_list_url(self, protectable_type,
|
||||
|
||||
@@ -24,13 +24,17 @@ class Restore(base.Resource):
|
||||
class RestoreManager(base.ManagerWithFind):
|
||||
resource_class = Restore
|
||||
|
||||
def create(self, provider_id, checkpoint_id, restore_target, parameters):
|
||||
body = {'restore': {'provider_id': provider_id,
|
||||
'checkpoint_id': checkpoint_id,
|
||||
'restore_target': restore_target,
|
||||
'parameters': parameters,
|
||||
}
|
||||
}
|
||||
def create(self, provider_id, checkpoint_id, restore_target, parameters,
|
||||
restore_auth):
|
||||
body = {
|
||||
'restore': {
|
||||
'provider_id': provider_id,
|
||||
'checkpoint_id': checkpoint_id,
|
||||
'restore_target': restore_target,
|
||||
'restore_auth': restore_auth,
|
||||
'parameters': parameters,
|
||||
}
|
||||
}
|
||||
url = "/restores"
|
||||
return self._create(url, body, 'restore')
|
||||
|
||||
|
||||
@@ -11,15 +11,15 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
|
||||
import os
|
||||
|
||||
from karborclient.common import base
|
||||
from karborclient.common import utils
|
||||
from karborclient.openstack.common.apiclient import exceptions
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from karborclient.common.apiclient import exceptions
|
||||
from karborclient.common import base
|
||||
from karborclient.common import utils
|
||||
|
||||
|
||||
@utils.arg('--all-tenants',
|
||||
dest='all_tenants',
|
||||
@@ -94,7 +94,7 @@ def do_plan_list(cs, args):
|
||||
limit=args.limit, sort_key=args.sort_key,
|
||||
sort_dir=args.sort_dir, sort=args.sort)
|
||||
|
||||
key_list = ['Id', 'Name', 'Provider id', 'Status']
|
||||
key_list = ['Id', 'Name', 'Description', 'Provider id', 'Status']
|
||||
|
||||
if args.sort_key or args.sort_dir or args.sort:
|
||||
sortby_index = None
|
||||
@@ -114,20 +114,30 @@ def do_plan_list(cs, args):
|
||||
metavar='<id=type=name,id=type=name>',
|
||||
help='Resource in list must be a dict when creating'
|
||||
' a plan.The keys of resource are id and type.')
|
||||
@utils.arg('--parameters',
|
||||
@utils.arg('--parameters-json',
|
||||
type=str,
|
||||
dest='parameters_json',
|
||||
metavar='<parameters>',
|
||||
default=None,
|
||||
help='The parameters of a plan.')
|
||||
help='Plan parameters in json format.')
|
||||
@utils.arg('--parameters',
|
||||
action='append',
|
||||
metavar='resource_type=<type>[,resource_id=<id>,key=val,...]',
|
||||
default=[],
|
||||
help='Plan parameters, may be specified multiple times. '
|
||||
'resource_type: type of resource to apply parameters. '
|
||||
'resource_id: limit the parameters to a specific resource. '
|
||||
'Other keys and values: according to provider\'s protect schema.'
|
||||
)
|
||||
@utils.arg('--description',
|
||||
metavar='<description>',
|
||||
help='The description of a plan.')
|
||||
def do_plan_create(cs, args):
|
||||
"""Create a plan."""
|
||||
plan_resources = _extract_resources(args)
|
||||
if args.parameters is not None:
|
||||
plan_parameters = jsonutils.loads(args.parameters)
|
||||
else:
|
||||
plan_parameters = {}
|
||||
plan_parameters = _extract_parameters(args)
|
||||
plan = cs.plans.create(args.name, args.provider_id, plan_resources,
|
||||
plan_parameters)
|
||||
plan_parameters, description=args.description)
|
||||
utils.print_dict(plan.to_dict())
|
||||
|
||||
|
||||
@@ -164,7 +174,7 @@ def do_plan_delete(cs, args):
|
||||
help="Id of plan to update.")
|
||||
@utils.arg("--name", metavar="<name>",
|
||||
help="A name to which the plan will be renamed.")
|
||||
@utils.arg("--resources", metavar="<id=type,id=type>",
|
||||
@utils.arg("--resources", metavar="<id=type=name,id=type=name>",
|
||||
help="Resources to which the plan will be updated.")
|
||||
@utils.arg("--status", metavar="<suspended|started>",
|
||||
help="status to which the plan will be updated.")
|
||||
@@ -214,12 +224,29 @@ def _extract_resources(args):
|
||||
@utils.arg('restore_target',
|
||||
metavar='<restore_target>',
|
||||
help='Restore target.')
|
||||
@utils.arg('--parameters',
|
||||
@utils.arg('restore_username',
|
||||
metavar='<restore_username>',
|
||||
default="",
|
||||
help='Username to restore target.')
|
||||
@utils.arg('restore_password',
|
||||
metavar='<restore_password>',
|
||||
default="",
|
||||
help='Password to restore target.')
|
||||
@utils.arg('--parameters-json',
|
||||
type=str,
|
||||
nargs='*',
|
||||
metavar='<key=value>',
|
||||
dest='parameters_json',
|
||||
metavar='<parameters>',
|
||||
default=None,
|
||||
help='The parameters of a restore target.')
|
||||
help='Restore parameters in json format.')
|
||||
@utils.arg('--parameters',
|
||||
action='append',
|
||||
metavar='resource_type=<type>[,resource_id=<id>,key=val,...]',
|
||||
default=[],
|
||||
help='Restore parameters, may be specified multiple times. '
|
||||
'resource_type: type of resource to apply parameters. '
|
||||
'resource_id: limit the parameters to a specific resource. '
|
||||
'Other keys and values: according to provider\'s restore schema.'
|
||||
)
|
||||
def do_restore_create(cs, args):
|
||||
"""Create a restore."""
|
||||
if not uuidutils.is_uuid_like(args.provider_id):
|
||||
@@ -230,27 +257,56 @@ def do_restore_create(cs, args):
|
||||
raise exceptions.CommandError(
|
||||
"Invalid checkpoint id provided.")
|
||||
|
||||
if args.parameters is not None:
|
||||
restore_parameters = _extract_parameters(args)
|
||||
else:
|
||||
raise exceptions.CommandError(
|
||||
"parameters must be provided.")
|
||||
restore_parameters = _extract_parameters(args)
|
||||
restore_auth = {
|
||||
'type': 'password',
|
||||
'username': args.restore_username,
|
||||
'password': args.restore_password,
|
||||
}
|
||||
restore = cs.restores.create(args.provider_id, args.checkpoint_id,
|
||||
args.restore_target, restore_parameters)
|
||||
args.restore_target, restore_parameters,
|
||||
restore_auth)
|
||||
utils.print_dict(restore.to_dict())
|
||||
|
||||
|
||||
def _extract_parameters(args):
|
||||
parameters = {}
|
||||
for data in args.parameters:
|
||||
# unset doesn't require a val, so we have the if/else
|
||||
if '=' in data:
|
||||
(key, value) = data.split('=', 1)
|
||||
else:
|
||||
key = data
|
||||
value = None
|
||||
if all((args.parameters, args.parameters_json)):
|
||||
raise exceptions.CommandError(
|
||||
"Must provide parameters or parameters-json, not both")
|
||||
if not any((args.parameters, args.parameters_json)):
|
||||
return {}
|
||||
|
||||
if args.parameters_json:
|
||||
return jsonutils.loads(args.parameters_json)
|
||||
parameters = {}
|
||||
for resource_params in args.parameters:
|
||||
resource_type = None
|
||||
resource_id = None
|
||||
parameter = {}
|
||||
for param_kv in resource_params.split(','):
|
||||
try:
|
||||
key, value = param_kv.split('=')
|
||||
except Exception:
|
||||
raise exceptions.CommandError(
|
||||
'parameters must be in the form: key1=val1,key2=val2,...'
|
||||
)
|
||||
if key == "resource_type":
|
||||
resource_type = value
|
||||
if key == "resource_id":
|
||||
if not uuidutils.is_uuid_like(value):
|
||||
raise exceptions.CommandError('resource_id must be a uuid')
|
||||
resource_id = value
|
||||
parameters[key] = value
|
||||
if resource_type is None:
|
||||
raise exceptions.CommandError(
|
||||
'Must specify resource_type for parameters'
|
||||
)
|
||||
if resource_id is None:
|
||||
resource_key = resource_type
|
||||
else:
|
||||
resource_key = "%s#%s" % (resource_type, resource_id)
|
||||
parameters[resource_key] = parameter
|
||||
|
||||
parameters[key] = value
|
||||
return parameters
|
||||
|
||||
|
||||
@@ -361,16 +417,28 @@ def do_protectable_show(cs, args):
|
||||
utils.print_dict(protectable.to_dict())
|
||||
|
||||
|
||||
@utils.arg('protectable_id',
|
||||
metavar='<protectable_id>',
|
||||
help='Protectable instance id.')
|
||||
@utils.arg('protectable_type',
|
||||
metavar='<protectable_type>',
|
||||
help='Protectable type.')
|
||||
@utils.arg('protectable_id',
|
||||
metavar='<protectable_id>',
|
||||
help='Protectable instance id.')
|
||||
@utils.arg('--parameters',
|
||||
type=str,
|
||||
nargs='*',
|
||||
metavar='<key=value>',
|
||||
default=None,
|
||||
help='Show a instance by parameters key and value pair. '
|
||||
'Default=None.')
|
||||
def do_protectable_show_instance(cs, args):
|
||||
"""Shows instance details."""
|
||||
search_opts = {
|
||||
'parameters': (_extract_instances_parameters(args)
|
||||
if args.parameters else None),
|
||||
}
|
||||
instance = cs.protectables.get_instance(args.protectable_type,
|
||||
args.protectable_id)
|
||||
args.protectable_id,
|
||||
search_opts=search_opts)
|
||||
utils.print_dict(instance.to_dict())
|
||||
|
||||
|
||||
@@ -406,11 +474,20 @@ def do_protectable_show_instance(cs, args):
|
||||
'form of <key>[:<asc|desc>]. '
|
||||
'Valid keys: %s. '
|
||||
'Default=None.') % ', '.join(base.SORT_KEY_VALUES)))
|
||||
@utils.arg('--parameters',
|
||||
type=str,
|
||||
nargs='*',
|
||||
metavar='<key=value>',
|
||||
default=None,
|
||||
help='List instances by parameters key and value pair. '
|
||||
'Default=None.')
|
||||
def do_protectable_list_instances(cs, args):
|
||||
"""Lists all protectable instances."""
|
||||
|
||||
search_opts = {
|
||||
'type': args.type,
|
||||
'parameters': (_extract_instances_parameters(args)
|
||||
if args.parameters else None),
|
||||
}
|
||||
|
||||
if args.sort and (args.sort_key or args.sort_dir):
|
||||
@@ -434,6 +511,19 @@ def do_protectable_list_instances(cs, args):
|
||||
sortby_index=sortby_index)
|
||||
|
||||
|
||||
def _extract_instances_parameters(args):
|
||||
parameters = {}
|
||||
for parameter in args.parameters:
|
||||
if '=' in parameter:
|
||||
(key, value) = parameter.split('=', 1)
|
||||
else:
|
||||
key = parameter
|
||||
value = None
|
||||
|
||||
parameters[key] = value
|
||||
return parameters
|
||||
|
||||
|
||||
@utils.arg('provider_id',
|
||||
metavar='<provider_id>',
|
||||
help='Id of provider.')
|
||||
@@ -509,12 +599,37 @@ def do_provider_list(cs, args):
|
||||
@utils.arg('plan_id',
|
||||
metavar='<plan_id>',
|
||||
help='ID of plan.')
|
||||
@utils.arg('--extra_info',
|
||||
type=str,
|
||||
nargs='*',
|
||||
metavar='<key=value>',
|
||||
default=None,
|
||||
help='The extra info of a checkpoint.')
|
||||
def do_checkpoint_create(cs, args):
|
||||
"""Create a checkpoint."""
|
||||
checkpoint = cs.checkpoints.create(args.provider_id, args.plan_id)
|
||||
|
||||
checkpoint_extra_info = None
|
||||
if args.extra_info is not None:
|
||||
checkpoint_extra_info = _extract_extra_info(args)
|
||||
checkpoint = cs.checkpoints.create(args.provider_id, args.plan_id,
|
||||
checkpoint_extra_info)
|
||||
utils.print_dict(checkpoint.to_dict())
|
||||
|
||||
|
||||
def _extract_extra_info(args):
|
||||
checkpoint_extra_info = {}
|
||||
for data in args.extra_info:
|
||||
# unset doesn't require a val, so we have the if/else
|
||||
if '=' in data:
|
||||
(key, value) = data.split('=', 1)
|
||||
else:
|
||||
key = data
|
||||
value = None
|
||||
|
||||
checkpoint_extra_info[key] = value
|
||||
return checkpoint_extra_info
|
||||
|
||||
|
||||
@utils.arg('provider_id',
|
||||
metavar='<provider_id>',
|
||||
help='ID of provider.')
|
||||
@@ -569,7 +684,7 @@ def do_checkpoint_list(cs, args):
|
||||
marker=args.marker, limit=args.limit, sort_key=args.sort_key,
|
||||
sort_dir=args.sort_dir, sort=args.sort)
|
||||
|
||||
key_list = ['Id', 'Project id', 'Status', 'Protection plan']
|
||||
key_list = ['Id', 'Project id', 'Status', 'Protection plan', 'Metadata']
|
||||
|
||||
if args.sort_key or args.sort_dir or args.sort:
|
||||
sortby_index = None
|
||||
@@ -732,6 +847,22 @@ def _extract_properties(args):
|
||||
return properties
|
||||
|
||||
|
||||
@utils.arg("trigger_id", metavar="<TRIGGER ID>",
|
||||
help="Id of trigger to update.")
|
||||
@utils.arg("--name", metavar="<name>",
|
||||
help="A new name to which the trigger will be renamed.")
|
||||
@utils.arg("--properties", metavar="<key=value:key=value>",
|
||||
help="Properties of trigger which will be updated.")
|
||||
def do_trigger_update(cs, args):
|
||||
"""Update a trigger."""
|
||||
trigger_info = {}
|
||||
trigger_properties = _extract_properties(args)
|
||||
trigger_info['name'] = args.name
|
||||
trigger_info['properties'] = trigger_properties
|
||||
trigger = cs.triggers.update(args.trigger_id, trigger_info)
|
||||
utils.print_dict(trigger.to_dict())
|
||||
|
||||
|
||||
@utils.arg('trigger',
|
||||
metavar='<trigger>',
|
||||
help='ID of trigger.')
|
||||
@@ -786,6 +917,10 @@ def do_trigger_delete(cs, args):
|
||||
metavar='<trigger_id>',
|
||||
default=None,
|
||||
help='Filters results by a trigger id. Default=None.')
|
||||
@utils.arg('--operation_definition',
|
||||
metavar='<operation_definition>',
|
||||
default=None,
|
||||
help='Filters results by the operation_definition. Default=None.')
|
||||
@utils.arg('--marker',
|
||||
metavar='<marker>',
|
||||
default=None,
|
||||
@@ -828,6 +963,7 @@ def do_scheduledoperation_list(cs, args):
|
||||
'name': args.name,
|
||||
'operation_type': args.operation_type,
|
||||
'trigger_id': args.trigger_id,
|
||||
'operation_definition': args.operation_definition,
|
||||
}
|
||||
|
||||
if args.sort and (args.sort_key or args.sort_dir):
|
||||
|
||||
@@ -46,6 +46,14 @@ class TriggerManager(base.ManagerWithFind):
|
||||
trigger_id=trigger_id)
|
||||
return self._get(url, response_key="trigger_info", headers=headers)
|
||||
|
||||
def update(self, trigger_id, data):
|
||||
|
||||
body = {"trigger_info": data}
|
||||
|
||||
return self._update('/triggers/{trigger_id}'
|
||||
.format(trigger_id=trigger_id),
|
||||
body, "trigger_info")
|
||||
|
||||
def list(self, detailed=False, search_opts=None, marker=None, limit=None,
|
||||
sort_key=None, sort_dir=None, sort=None):
|
||||
"""Lists all triggers."""
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
[DEFAULT]
|
||||
|
||||
# The list of modules to copy from openstack-common
|
||||
module=apiclient.exceptions
|
||||
module=apiclient
|
||||
|
||||
# The base module to hold the copy of openstack.common
|
||||
base=karborclient
|
||||
@@ -1,13 +1,13 @@
|
||||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
pbr>=1.6 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7 # BSD
|
||||
python-keystoneclient!=1.8.0,!=2.1.0,>=1.7.0 # Apache-2.0
|
||||
pbr>=1.8 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7.1 # BSD
|
||||
python-keystoneclient>=3.6.0 # Apache-2.0
|
||||
requests>=2.10.0 # Apache-2.0
|
||||
simplejson>=2.2.0 # MIT
|
||||
Babel>=2.3.4 # BSD
|
||||
six>=1.9.0 # MIT
|
||||
oslo.utils>=3.16.0 # Apache-2.0
|
||||
oslo.log>=1.14.0 # Apache-2.0
|
||||
oslo.utils>=3.18.0 # Apache-2.0
|
||||
oslo.log>=3.11.0 # Apache-2.0
|
||||
oslo.i18n>=2.1.0 # Apache-2.0
|
||||
|
||||
@@ -5,7 +5,7 @@ description-file =
|
||||
README.rst
|
||||
author = OpenStack
|
||||
author-email = openstack-dev@lists.openstack.org
|
||||
home-page = http://www.openstack.org/
|
||||
home-page = http://docs.openstack.org/developer/karbor/
|
||||
classifier =
|
||||
Environment :: OpenStack
|
||||
Intended Audience :: Information Technology
|
||||
@@ -18,6 +18,7 @@ classifier =
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: 3.3
|
||||
Programming Language :: Python :: 3.4
|
||||
Programming Language :: Python :: 3.5
|
||||
|
||||
[global]
|
||||
setup-hooks =
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
hacking<0.11,>=0.10.2 # Apache-2.0
|
||||
|
||||
coverage>=3.6 # Apache-2.0
|
||||
coverage>=4.0 # Apache-2.0
|
||||
python-subunit>=0.0.18 # Apache-2.0/BSD
|
||||
sphinx!=1.3b1,<1.3,>=1.2.1 # BSD
|
||||
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
|
||||
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD
|
||||
oslosphinx>=4.7.0 # Apache-2.0
|
||||
oslotest>=1.10.0 # Apache-2.0
|
||||
testrepository>=0.0.18 # Apache-2.0/BSD
|
||||
testscenarios>=0.4 # Apache-2.0/BSD
|
||||
|
||||
4
tox.ini
4
tox.ini
@@ -1,6 +1,6 @@
|
||||
[tox]
|
||||
minversion = 1.6
|
||||
envlist = py34,py27,pypy,pep8
|
||||
envlist = py35,py34,py27,pypy,pep8
|
||||
skipsdist = True
|
||||
|
||||
[testenv]
|
||||
@@ -37,4 +37,4 @@ commands = oslo_debug_helper {posargs}
|
||||
show-source = True
|
||||
ignore = E123,E125
|
||||
builtins = _
|
||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools
|
||||
|
||||
Reference in New Issue
Block a user