Merge "Allow specifying name of related resource when creation"

This commit is contained in:
Zuul 2018-06-20 02:22:46 +00:00 committed by Gerrit Code Review
commit 927c4a2117
8 changed files with 67 additions and 18 deletions

View File

@ -18,6 +18,7 @@ import zipfile
from osc_lib.command import command
from osc_lib import utils
from oslo_utils import uuidutils
from qinlingclient.common import exceptions
from qinlingclient.osc.v1 import base
@ -164,12 +165,18 @@ class Create(command.ShowOne):
elif parsed_args.image:
parsed_args.code_type = 'image'
runtime = parsed_args.runtime
if runtime and not uuidutils.is_uuid_like(runtime):
# Try to find the runtime id with name
runtime = q_utils.find_resource_id_by_name(
client.runtimes, runtime)
if parsed_args.code_type == 'package':
if not (parsed_args.file or parsed_args.package):
raise exceptions.QinlingClientException(
'Package or file needs to be specified.'
)
if not parsed_args.runtime:
if not runtime:
raise exceptions.QinlingClientException(
'Runtime needs to be specified for package type function.'
)
@ -181,7 +188,7 @@ class Create(command.ShowOne):
with open(zip_file, 'rb') as package:
function = client.functions.create(
name=parsed_args.name,
runtime=parsed_args.runtime,
runtime=runtime,
code=code,
package=package,
entry=parsed_args.entry,
@ -198,7 +205,7 @@ class Create(command.ShowOne):
raise exceptions.QinlingClientException(
'Container name and object name need to be specified.'
)
if not parsed_args.runtime:
if not runtime:
raise exceptions.QinlingClientException(
'Runtime needs to be specified for package type function.'
)
@ -213,7 +220,7 @@ class Create(command.ShowOne):
function = client.functions.create(
name=parsed_args.name,
runtime=parsed_args.runtime,
runtime=runtime,
code=code,
entry=parsed_args.entry,
cpu=parsed_args.cpu,

View File

@ -14,8 +14,10 @@
from osc_lib.command import command
from osc_lib import utils
from oslo_utils import uuidutils
from qinlingclient.osc.v1 import base
from qinlingclient import utils as q_utils
class List(base.QinlingLister):
@ -35,8 +37,8 @@ class Create(command.ShowOne):
parser.add_argument(
"function",
metavar='FUNCTION_ID',
help="Function ID.",
metavar='FUNCTION',
help="Function name or ID.",
)
parser.add_argument(
"--function-version",
@ -69,8 +71,14 @@ class Create(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.function_engine
function = parsed_args.function
if not uuidutils.is_uuid_like(function):
# Try to find the function id with name
function = q_utils.find_resource_id_by_name(
client.functions, function)
execution = client.function_executions.create(
function=parsed_args.function,
function=function,
version=parsed_args.function_version,
sync=parsed_args.sync,
input=parsed_args.input

View File

@ -14,9 +14,11 @@
from osc_lib.command import command
from osc_lib import utils
from oslo_utils import uuidutils
from qinlingclient.common import exceptions
from qinlingclient.osc.v1 import base
from qinlingclient import utils as q_utils
class List(base.QinlingLister):
@ -45,8 +47,8 @@ class Create(command.ShowOne):
parser = super(Create, self).get_parser(prog_name)
parser.add_argument(
"function_id",
help="Function ID.",
"function",
help="Function name or ID.",
)
parser.add_argument(
"--description",
@ -58,8 +60,14 @@ class Create(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.function_engine
function_id = parsed_args.function
if not uuidutils.is_uuid_like(function_id):
# Try to find the function id with name
function_id = q_utils.find_resource_id_by_name(
client.functions, function_id)
version = client.function_versions.create(
parsed_args.function_id,
function_id,
description=parsed_args.description,
)

View File

@ -14,8 +14,10 @@
from osc_lib.command import command
from osc_lib import utils as osc_utils
from oslo_utils import uuidutils
from qinlingclient.osc.v1 import base
from qinlingclient import utils as q_utils
class List(base.QinlingLister):
@ -34,8 +36,9 @@ class Create(command.ShowOne):
parser = super(Create, self).get_parser(prog_name)
parser.add_argument(
"function_id",
help="Function ID.",
"function",
metavar='FUNCTION',
help="Function name or ID.",
)
parser.add_argument(
@ -64,8 +67,15 @@ class Create(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.function_engine
function_id = parsed_args.function
if not uuidutils.is_uuid_like(function_id):
# Try to find the function id with name
function_id = q_utils.find_resource_id_by_name(
client.functions, function_id)
job = client.jobs.create(
function_id=parsed_args.function_id,
function_id=function_id,
name=parsed_args.name,
first_execution_time=parsed_args.first_execution_time,
pattern=parsed_args.pattern,

View File

@ -14,8 +14,10 @@
from osc_lib.command import command
from osc_lib import utils
from oslo_utils import uuidutils
from qinlingclient.osc.v1 import base
from qinlingclient import utils as q_utils
class List(base.QinlingLister):
@ -34,8 +36,9 @@ class Create(command.ShowOne):
parser = super(Create, self).get_parser(prog_name)
parser.add_argument(
"function_id",
help="Function ID.",
"function",
metavar='FUNCTION',
help="Function name or ID.",
)
parser.add_argument(
"--description",
@ -47,8 +50,14 @@ class Create(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.function_engine
function_id = parsed_args.function
if not uuidutils.is_uuid_like(function_id):
# Try to find the function id with name
function_id = q_utils.find_resource_id_by_name(
client.functions, function_id)
webhook = client.webhooks.create(
function_id=parsed_args.function_id,
function_id=function_id,
description=parsed_args.description,
)

View File

@ -26,3 +26,10 @@ def md5(file=None, content=None):
hash_md5.update(content)
return hash_md5.hexdigest()
def find_resource_id_by_name(manager, name):
# An exception will be raised when resource is not found or multiple
# resources for the name are found.
resource = manager.find(name=name)
return resource.id

View File

@ -21,7 +21,7 @@ class Function(base.Resource):
pass
class FunctionManager(base.Manager):
class FunctionManager(base.ManagerWithFind):
resource_class = Function
def list(self, **kwargs):

View File

@ -19,7 +19,7 @@ class Runtime(base.Resource):
pass
class RuntimeManager(base.Manager):
class RuntimeManager(base.ManagerWithFind):
resource_class = Runtime
def list(self, **kwargs):