def get_op_handler(operation):
""" Import and load the operation handler """
# Patch the unversioned sdk path to include the appropriate API version for the
# resource type in question.
from azure.cli.core._profile import CLOUD
import types
for rt in ResourceType:
if operation.startswith(rt.import_prefix + ".operations."):
subs = operation[len(rt.import_prefix + ".operations."):]
operation_group = subs[:subs.index('_operations')]
operation = operation.replace(
rt.import_prefix,
get_versioned_sdk_path(CLOUD.profile, rt, operation_group=operation_group))
elif operation.startswith(rt.import_prefix):
operation = operation.replace(rt.import_prefix,
get_versioned_sdk_path(CLOUD.profile, rt))
try:
mod_to_import, attr_path = operation.split('#')
op = import_module(mod_to_import)
for part in attr_path.split('.'):
op = getattr(op, part)
if isinstance(op, types.FunctionType):
return op
return six.get_method_function(op)
except (ValueError, AttributeError):
raise ValueError("The operation '{}' is invalid.".format(operation))
评论列表
文章目录