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

Remove the AppDB dependency #391

Merged
merged 8 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions cloud-info/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ RUN curl -s https://dist.eugridpma.info/distribution/igtf/current/GPG-KEY-EUGrid
&& apt-get install -y ca-policy-egi-core \
&& rm -rf /var/lib/apt/lists/*

# Fedcloud client is pinning dependencies strictly so it does not play
# very well with the rest of the available venv. Installing on its own
RUN python -m venv /fedcloud && \
/fedcloud/bin/pip install --no-cache-dir fedcloudclient

WORKDIR /cloud-info

COPY requirements.txt .

RUN python -m venv /cloud-info/venv
ENV PATH="/cloud-info/venv/bin:$PATH"

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt \
&& cat /etc/grid-security/certificates/*.pem >> "$(python -m requests.certs)"

Expand All @@ -37,7 +42,6 @@ RUN apt-get update \
jq rclone \
&& rm -rf /var/lib/apt/lists/*


RUN mkdir /cloud-info \
&& groupadd -g 1999 python \
&& useradd -r -u 1999 -g python python \
Expand All @@ -47,6 +51,7 @@ WORKDIR /cloud-info

# All the python code from the build image above
COPY --chown=python:python --from=build /cloud-info/venv ./venv
COPY --chown=python:python --from=build /fedcloud /fedcloud
# Add the scripts that call the cloud-info-provider as needed for the site
# these create the configuration for the site by discovering the available
# projects for the credentials and will send the output to the AMS queue and
Expand Down
7 changes: 4 additions & 3 deletions cloud-info/ams-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ if test -s cloud-info.json; then
OIDC_ACCESS_TOKEN=$(yq -r '.checkin.access_token' <"$ACCESS_TOKEN_FILE")
export OIDC_ACCESS_TOKEN
export EGI_VO="$SWIFT_VO_NAME"
SWIFT_URL=$(fedcloud openstack \
SWIFT_URL=$(/fedcloud/bin/fedcloud openstack \
--site "$SWIFT_SITE_NAME" \
catalog show swift -f json |
jq -r '(.endpoints[] | select(.interface=="public")).url')
export RCLONE_CONFIG_REMOTE_TYPE="swift"
export RCLONE_CONFIG_REMOTE_ENV_AUTH="false"
export RCLONE_CONFIG_REMOTE_STORAGE_URL="$SWIFT_URL"
eval "$(fedcloud site env --site "$SWIFT_SITE_NAME")"
eval "$(/fedcloud/bin/fedcloud site env --site "$SWIFT_SITE_NAME")"
export RCLONE_CONFIG_REMOTE_AUTH_URL="$OS_AUTH_URL"
OS_AUTH_TOKEN=$(fedcloud openstack --site "$SWIFT_SITE_NAME" token issue -c id -f value)
OS_AUTH_TOKEN=$(/fedcloud/bin/fedcloud openstack \
--site "$SWIFT_SITE_NAME" token issue -c id -f value)
export RCLONE_CONFIG_REMOTE_AUTH_TOKEN="$OS_AUTH_TOKEN"
rclone mkdir "remote:$SWIFT_CONTAINER_NAME"
rclone copy cloud-info.json "remote:$SWIFT_CONTAINER_NAME/$SITE_NAME"
Expand Down
6 changes: 3 additions & 3 deletions cloud-info/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cloud info version is 43cefc204b3e07211c6c37df2ee20eab845c3428
# 43cefc204b3e07211c6c37df2ee20eab845c3428 includes json glue support
git+https://github.com/EGI-Federation/cloud-info-provider.git@43cefc204b3e07211c6c37df2ee20eab845c3428
# Cloud info version is 6fbbf1c24bd32c21d5b8de783d7face6c6c5987e
# 6fbbf1c24bd32c21d5b8de783d7face6c6c5987e includes json glue support and fixes for it
git+https://github.com/EGI-Federation/cloud-info-provider.git@6fbbf1c24bd32c21d5b8de783d7face6c6c5987e
git+https://github.com/ARGOeu/argo-ams-library@devel
python-glanceclient
python-novaclient
Expand Down
62 changes: 59 additions & 3 deletions image-sync/image_sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import tempfile

import requests
import httpx
import yaml
from oslo_config import cfg

Expand All @@ -15,6 +15,13 @@
CONF.register_opts(
[
cfg.StrOpt("site_config_dir", default="."),
cfg.StrOpt(
"cloud_info_url",
default=(
"https://stratus-stor.ncg.ingrid.pt:8080/swift/"
"v1/AUTH_bd5a81e1670b48f18af33b05512a9d77/cloud-info/"
),
),
cfg.StrOpt("graphql_url", default="https://is.appdb.egi.eu/graphql"),
cfg.ListOpt("formats", default=[]),
cfg.StrOpt("appdb_token"),
Expand All @@ -38,7 +45,15 @@
)


def fetch_site_info():
def get_share_vo(share, site_info):
for policy in site_info["MappingPolicy"]:
for assoc, share_id in policy["Associations"].items():
if assoc == "Share" and share_id == share["ID"]:
return policy["Rule"][0].removeprefix("VO:")
return ""


def fetch_site_info_appdb():
logging.debug("Fetching site info from AppDB")
query = """
{
Expand All @@ -58,14 +73,55 @@ def fetch_site_info():
}
"""
params = {"query": query}
r = requests.get(
r = httpx.get(
CONF.sync.graphql_url, params=params, headers={"accept": "application/json"}
)
r.raise_for_status()
data = r.json()["data"]["siteCloudComputingEndpoints"]["items"]
return data


def fetch_site_info_cloud_info():
logging.debug("Fetching site info from cloud-info")
sites = []
# 1 - Get all sites listing
r = httpx.get(CONF.sync.cloud_info_url, headers={"Accept": "application/json"})
r.raise_for_status()
# 2 - Go one by one getting the shares
for file in r.json():
try:
r = httpx.get(os.path.join(CONF.sync.cloud_info_url, file["name"]))
r.raise_for_status()
except httpx.HTTPError as e:
logging.warning(f"Exception while trying to get {file['name']}: {e}")
continue
full_site = r.json()
admin_domain = full_site["CloudComputingService"][0]["Associations"].get(
"AdminDomain", None
)
if not admin_domain:
continue
# Some associations are a list, other directly strings, cloud-info should harmonise
site = admin_domain[0]
enolfc marked this conversation as resolved.
Show resolved Hide resolved
shares = []
for share in full_site["Share"]:
shares.append(
{"projectID": share["ProjectID"], "VO": get_share_vo(share, full_site)}
)
sites.append(
{
"site": {"name": site},
"endpointURL": full_site["CloudComputingEndpoint"][0]["URL"],
"shares": shares,
}
)
return sites


def fetch_site_info():
return fetch_site_info_cloud_info()


def dump_atrope_config(site, share, hepix_file):
config_template = """
[DEFAULT]
Expand Down
2 changes: 1 addition & 1 deletion image-sync/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git+https://github.com/EGI-Federation/atrope@catchall
requests
httpx
oslo.config
PyYAML
Loading