Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit AYON_SERVER_URL to jobs #42

Merged
merged 26 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c5e67f3
Submit along `AYON_SERVER_URL` with deadline jobs
BigRoy Oct 7, 2024
e0009e8
Merge branch 'develop' into enhancement/submit_ayon_server_url
BigRoy Oct 7, 2024
d718648
Merge branch 'develop' of https://github.com/ynput/ayon-deadline into…
BigRoy Oct 8, 2024
cffab6b
Remove incorrect file docstring
BigRoy Oct 8, 2024
4ce6250
Submit along `AYON_API_KEY`
BigRoy Oct 8, 2024
b17af4b
Merge branch 'enhancement/submit_ayon_server_url' of https://github.c…
BigRoy Oct 8, 2024
5737d4a
Expose plug-in in settings
BigRoy Oct 8, 2024
d1cf912
Submit optional state (mostly for inherited `CollectAYONServerUrlToFa…
BigRoy Oct 9, 2024
4a57ffd
Fix label for optional field
kalisp Oct 9, 2024
86b4900
Removed TODO as already implemented
kalisp Oct 9, 2024
65d82a1
The applying of `AYON_USE_DEV` should already be solved on the farm t…
BigRoy Oct 10, 2024
08fa08f
Set AYON API key from settings
BigRoy Oct 10, 2024
4b21b44
Merge branch 'enhancement/submit_ayon_server_url' of https://github.c…
BigRoy Oct 10, 2024
47d8512
Cosmetics
BigRoy Oct 10, 2024
bc36531
Remove optional/active settings - because it should not be optional +…
BigRoy Oct 11, 2024
67667b6
Update default
BigRoy Oct 11, 2024
741209c
Merge branch 'develop' into enhancement/submit_ayon_server_url
BigRoy Oct 19, 2024
9c6ab87
Move the passing of the AYON_API_KEY to Deadline Repository AYON Plug…
BigRoy Oct 19, 2024
bc5c8d2
Remove plug-in that was moved into other file
BigRoy Oct 19, 2024
02982d5
Cosmetics
BigRoy Oct 19, 2024
7816fce
Remove non-existing default
BigRoy Oct 19, 2024
91e6f92
Update client/ayon_deadline/repository/custom/plugins/GlobalJobPreLoa…
BigRoy Oct 23, 2024
a10e7a3
Merge branch 'develop' into enhancement/submit_ayon_server_url
BigRoy Oct 23, 2024
4bd2db0
Merge branch 'develop' into enhancement/submit_ayon_server_url
MustafaJafar Oct 23, 2024
8642e66
Added casting to list
kalisp Oct 29, 2024
cedf5d6
Merge branch 'develop' into enhancement/submit_ayon_server_url
kalisp Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# -*- coding: utf-8 -*-
"""Collect Deadline servers from instance.

This is resolving index of server lists stored in `deadlineServers` instance
attribute or using default server if that attribute doesn't exists.

"""
import os

import pyblish.api
Expand Down Expand Up @@ -44,6 +37,7 @@ class CollectDeadlineJobEnvVars(pyblish.api.ContextPlugin):
]

def process(self, context):

env = {}
for key in self.ENV_KEYS:
value = os.getenv(key)
Expand All @@ -53,3 +47,15 @@ def process(self, context):

# Transfer some environment variables from current context
context.data.setdefault(JOB_ENV_DATA_KEY, {}).update(env)


class CollectAYONServerToFarmJob(CollectDeadlineJobEnvVars):
label = "Add AYON Server URL to farm job"
settings_category = "deadline"

# Defined via settings
enabled = False

ENV_KEYS = [
"AYON_SERVER_URL"
]
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ CategoryOrder=2
Index=0
Default=
Description=API key for service account on Ayon Server

[AyonAdditionalServerUrls]
Type=multilinestring
Label=Additional AYON Servers
Category=Additional AYON Servers
CategoryOrder=3
Index=0
Default=
Description=An AYON server URL per line suffixed with `@APIKEY` from a service user on that AYON server, e.g. `http://server:5000@veryinsecureapikey`.
76 changes: 67 additions & 9 deletions client/ayon_deadline/repository/custom/plugins/GlobalJobPreLoad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
FileUtils,
DirectoryUtils,
)
__version__ = "1.1.3"
__version__ = "1.1.4"
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
VERSION_REGEX = re.compile(
r"(?P<major>0|[1-9]\d*)"
r"\.(?P<minor>0|[1-9]\d*)"
Expand Down Expand Up @@ -410,6 +410,43 @@ def inject_openpype_environment(deadlinePlugin):
raise


def get_ayon_api_key_from_additional_servers(config, server):
"""Get AYON API key from the list of additional servers.

The additional servers are configured on the DeadlineRepository AYON
Plug-in settings using the `AyonAdditionalServerUrls` param. Each line
represents a server URL with an API key, like:
server1:port@APIKEY1
server2:port@APIKEY2

Returns:
Optional[str]: If the server URL is found in the additional servers
then return the API key for that server.

"""
additional_servers: str = config.GetConfigEntryWithDefault(
"AyonAdditionalServerUrls", "").strip()
if not additional_servers:
return

for line in additional_servers:
line = line.strip()
# Ignore empty lines
if not line:
continue

# Log warning if additional server URL is misconfigured
# without an API key
if "@" not in line:
print("Configured additional server URL lacks "
f"`@APIKEY` suffix: {line}")
continue

additional_server, api_key = line.split("@", 1)
if additional_server == server:
return api_key


def inject_ayon_environment(deadlinePlugin):
""" Pull env vars from AYON and push them to rendering process.

Expand Down Expand Up @@ -439,14 +476,35 @@ def inject_ayon_environment(deadlinePlugin):
)

config = RepositoryUtils.GetPluginConfig("Ayon")
ayon_server_url = (
job.GetJobEnvironmentKeyValue("AYON_SERVER_URL") or
config.GetConfigEntryWithDefault("AyonServerUrl", "")
)
ayon_api_key = (
job.GetJobEnvironmentKeyValue("AYON_API_KEY") or
config.GetConfigEntryWithDefault("AyonApiKey", "")
)

ayon_server_url = config.GetConfigEntryWithDefault("AyonServerUrl", "")
ayon_api_key = config.GetConfigEntryWithDefault("AyonApiKey", "")
job_ayon_server_url = job.GetJobEnvironmentKeyValue("AYON_SERVER_URL")
job_ayon_api_key = job.GetJobEnvironmentKeyValue("AYON_API_KEY")

# API key submitted with job environment will always take priority
if job_ayon_api_key:
ayon_api_key = job_ayon_api_key

# Allow custom AYON API key per server URL if server URL is submitted
# along with the job. The custom API keys can be configured on the
# Deadline Repository AYON Plug-in settings, in the format of
# `SERVER:PORT@APIKEY` per line.
elif job_ayon_server_url and job_ayon_server_url != ayon_server_url:
ayon_server_url = job_ayon_server_url
api_key = get_ayon_api_key_from_additional_servers(
config, job_ayon_server_url)
if api_key:
ayon_api_key = api_key
else:
print(
"AYON Server URL submitted with job"
f" '{job_ayon_server_url}' is not the Deadline AYON"
f" Plug-in default server URL '{ayon_server_url}' but"
" has no API key defined in Additional Server URLs."
" Falling back to default API key configured in"
" Deadline repository for the AYON plug-in."
)

if not all([ayon_server_url, ayon_api_key]):
raise RuntimeError((
Expand Down
16 changes: 16 additions & 0 deletions server/settings/publish_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
)


class CollectAYONServerToFarmJobModel(BaseSettingsModel):
enabled: bool = SettingsField(False, title="Enabled")


class CollectDeadlinePoolsModel(BaseSettingsModel):
"""Settings Deadline default pools."""

Expand Down Expand Up @@ -373,6 +377,15 @@ class PublishPluginsModel(BaseSettingsModel):
CollectDeadlinePools: CollectDeadlinePoolsModel = SettingsField(
default_factory=CollectDeadlinePoolsModel,
title="Default Pools")
CollectAYONServerToFarmJob: CollectAYONServerToFarmJobModel = SettingsField( # noqa
default_factory=CollectAYONServerToFarmJobModel,
title="Add AYON server to farm job",
description=(
"When enabled submit along your `AYON_SERVER_URL` to the farm job."
" On the Deadline AYON Plug-in on the Deadline Repository settings"
" you can specify a custom API key for those server URLs."
)
)
ValidateExpectedFiles: ValidateExpectedFilesModel = SettingsField(
default_factory=ValidateExpectedFilesModel,
title="Validate Expected Files"
Expand Down Expand Up @@ -425,6 +438,9 @@ class PublishPluginsModel(BaseSettingsModel):
"primary_pool": "",
"secondary_pool": ""
},
"CollectAYONServerToFarmJob": {
"enabled": False
},
"ValidateExpectedFiles": {
"enabled": True,
"active": True,
Expand Down