mirror of
https://github.com/clearml/clearml-agent
synced 2025-01-31 00:56:53 +00:00
Support creating queue with tags
This commit is contained in:
parent
5419fd84ae
commit
26d748a4d8
@ -19,8 +19,19 @@ class Request(ApiModel):
|
||||
_method = ENV_API_DEFAULT_REQ_METHOD.get(default="get")
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
if kwargs:
|
||||
allow_extra_fields = kwargs.pop("_allow_extra_fields_", False)
|
||||
if not allow_extra_fields and kwargs:
|
||||
raise ValueError('Unsupported keyword arguments: %s' % ', '.join(kwargs.keys()))
|
||||
elif allow_extra_fields and kwargs:
|
||||
self._extra_fields = kwargs
|
||||
else:
|
||||
self._extra_fields = {}
|
||||
|
||||
def to_dict(self, *args, **kwargs):
|
||||
res = super(Request, self).to_dict(*args, **kwargs)
|
||||
if self._extra_fields:
|
||||
res.update(self._extra_fields)
|
||||
return res
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
|
@ -327,7 +327,7 @@ class ServiceCommandSection(BaseCommandSection):
|
||||
def get_service(self, service_class):
|
||||
return service_class(config=self._session.config)
|
||||
|
||||
def _resolve_name(self, name, service=None):
|
||||
def _resolve_name(self, name, service=None, search_hidden=False):
|
||||
"""
|
||||
Resolve an object name to an object ID.
|
||||
Operation:
|
||||
@ -349,7 +349,11 @@ class ServiceCommandSection(BaseCommandSection):
|
||||
except AttributeError:
|
||||
raise NameResolutionError('Name resolution unavailable for {}'.format(service))
|
||||
|
||||
request = request_cls.from_dict(dict(name=re.escape(name), only_fields=['name', 'id']))
|
||||
req_dict = {"name": re.escape(name), "only_fields": ['name', 'id']}
|
||||
if search_hidden:
|
||||
req_dict["_allow_extra_fields_"] = True
|
||||
req_dict["search_hidden"] = True
|
||||
request = request_cls.from_dict(req_dict)
|
||||
# from_dict will ignore unrecognised keyword arguments - not all GetAll's have only_fields
|
||||
response = getattr(self._session.send_api(request), service)
|
||||
matches = [db_object for db_object in response if name.lower() == db_object.name.lower()]
|
||||
|
@ -4837,7 +4837,7 @@ class Worker(ServiceCommandSection):
|
||||
worker_name = '{}:cpu'.format(worker_name)
|
||||
return worker_id, worker_name
|
||||
|
||||
def _resolve_queue_names(self, queues, create_if_missing=False):
|
||||
def _resolve_queue_names(self, queues, create_if_missing=False, create_system_tags=None):
|
||||
if not queues:
|
||||
# try to look for queues with "default" tag
|
||||
try:
|
||||
@ -4849,15 +4849,25 @@ class Worker(ServiceCommandSection):
|
||||
|
||||
queues = return_list(queues)
|
||||
if not create_if_missing:
|
||||
return [self._resolve_name(q if isinstance(q, str) else q.name, "queues") for q in queues]
|
||||
return [
|
||||
self._resolve_name(q if isinstance(q, str) else q.name, service="queues", search_hidden=True)
|
||||
for q in queues
|
||||
]
|
||||
|
||||
queue_ids = []
|
||||
for q in queues:
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
q_id = self._resolve_name(q if isinstance(q, str) else q.name, "queues")
|
||||
q_id = self._resolve_name(
|
||||
q if isinstance(q, str) else q.name, service="queues", search_hidden=True
|
||||
)
|
||||
except:
|
||||
self._session.send_api(queues_api.CreateRequest(name=q if isinstance(q, str) else q.name))
|
||||
q_id = self._resolve_name(q if isinstance(q, str) else q.name, "queues")
|
||||
self._session.send_api(
|
||||
queues_api.CreateRequest(name=q if isinstance(q, str) else q.name, system_tags=create_system_tags)
|
||||
)
|
||||
q_id = self._resolve_name(
|
||||
q if isinstance(q, str) else q.name, service="queues", search_hidden=True
|
||||
)
|
||||
queue_ids.append(q_id)
|
||||
return queue_ids
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user