From 50dea9ac4e46ae2157d3d10da6802ac191f77c07 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Thu, 5 Jan 2023 14:08:08 +0100 Subject: [PATCH 01/25] fixes --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d87f25d..8274c25 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -297,7 +297,7 @@ release: script: - echo "Running release-job for $VERSION" release: - name: $CI_PROJECT_TITLE $version + name: $CI_PROJECT_TITLE $VERSION description: Release of $CI_PROJECT_TITLE version $VERSION tag_name: $VERSION ref: $CI_COMMIT_SHA From b551b0e7f95df6b16812bc7c67f4bebde5f0d231 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Sun, 15 Jan 2023 19:47:50 +0100 Subject: [PATCH 02/25] README.md - added sunsupoorted ubuntu version --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c07deb3..e301f67 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,10 @@ Successful tested with: - Debian 12 (Bookworm) (works but not recommended because it is currently in *testing* state) - Ubuntu 22.10 (Kinetic Kudu) +Not working with: +- Debian 11 (Bullseye) and lower (missing `python-jose` dependency) +- Ubuntu 22.04 (Jammy Jellyfish) (not supported as for 15.01.2023 due to [fastapi - uvicorn version missmatch](https://bugs.launchpad.net/ubuntu/+source/fastapi/+bug/1970557)) + **Run this on your server instance** First go to [GitLab-Registry](https://git.collinwebdesigns.de/oscar.krause/fastapi-dls/-/packages) and select your From 5425eec545b2cd59bd39029c0d1ae0ba50bea898 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:23:58 +0100 Subject: [PATCH 03/25] .gitlab-ci.yml simplified --- .gitlab-ci.yml | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8274c25..89db932 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -97,7 +97,7 @@ build:pacman: - "*.pkg.tar.zst" test: - image: python:3.10-slim-bullseye + image: python:3.11-slim-bullseye stage: test rules: - if: $CI_COMMIT_BRANCH @@ -113,6 +113,9 @@ test: - cd test script: - pytest main.py + artifacts: + reports: + dotenv: version.env .test:linux: stage: test @@ -271,24 +274,11 @@ deploy:pacman: - 'echo "EXPORT_NAME: ${EXPORT_NAME}"' - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ${EXPORT_NAME} "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PACKAGE_NAME}/${PACKAGE_VERSION}/${EXPORT_NAME}"' -release:prepare: - stage: .pre - rules: - - if: $CI_COMMIT_TAG - when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - script: - - source version.env - - echo $VERSION - artifacts: - reports: - dotenv: version.env - release: image: registry.gitlab.com/gitlab-org/release-cli:latest stage: .post needs: - - job: release:prepare + - job: test artifacts: true rules: - if: $CI_COMMIT_TAG From ca8a9df54c138080efb03063a1e89b8803b4b3ed Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:24:08 +0100 Subject: [PATCH 04/25] requirements.txt updated --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e505de0..4c25d3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fastapi==0.88.0 +fastapi==0.89.1 uvicorn[standard]==0.20.0 python-jose==3.3.0 pycryptodome==3.16.0 From ed13577e8266477b80fb8c8dfac9b3f1172772ea Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:30:21 +0100 Subject: [PATCH 05/25] Dockerfile - updated to python 3.11 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6ffaee6..e92f5dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-alpine +FROM python:3.11-alpine COPY requirements.txt /tmp/requirements.txt From 3495cc3af55e4fd5e76506b53256ae7e878387eb Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:30:40 +0100 Subject: [PATCH 06/25] typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e301f67..20caf9b 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ volumes: dls-db: ``` -## Debian/Ubuntu (manual method using `git clone`) +## Debian/Ubuntu (manual method using `git clone` and python virtual environment) Tested on `Debian 11 (bullseye)`, Ubuntu may also work. From 20cc984799965a3fec0deec8c4d15886d377a957 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:30:55 +0100 Subject: [PATCH 07/25] FAQ.md --- FAQ.md | 17 +++++++++++++++++ README.md | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 FAQ.md diff --git a/FAQ.md b/FAQ.md new file mode 100644 index 0000000..4ddd379 --- /dev/null +++ b/FAQ.md @@ -0,0 +1,17 @@ +# FAQ + +## `Failed to acquire license from (Info: - Error: The allowed time to process response has expired)` + +- Did your timezone settings are correct on fastapi-dls **and your guest**? + +- Did you download the client-token more than an hour ago? + +Please download a new client-token. The guest have to register within an hour after client-token was created. + + +## `jose.exceptions.JWTError: Signature verification failed.` + +- Did you recreated `instance.public.pem` / `instance.private.pem`? + +Then you have to download a **new** client-token on each of your guests. + diff --git a/README.md b/README.md index 20caf9b..49062da 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,7 @@ Successful tested with: - Ubuntu 22.10 (Kinetic Kudu) Not working with: + - Debian 11 (Bullseye) and lower (missing `python-jose` dependency) - Ubuntu 22.04 (Jammy Jellyfish) (not supported as for 15.01.2023 due to [fastapi - uvicorn version missmatch](https://bugs.launchpad.net/ubuntu/+source/fastapi/+bug/1970557)) @@ -249,6 +250,16 @@ After first success you have to replace `--issue` with `--renew`. every 4.8 hours. If network connectivity is lost, the loss of connectivity is detected during license renewal and the client has 19.2 hours in which to re-establish connectivity before its license expires. +```python +from datetime import timedelta + +LEASE_RENEWAL_PERIOD=0.2 # 20% +delta = timedelta(days=1) +renew = delta.total_seconds() * LEASE_RENEWAL_PERIOD +renew = timedelta(seconds=renew) +expires = delta - renew # 19.2 +``` + \*2 Always use `https`, since guest-drivers only support secure connections! \*3 If you recreate instance keys you need to **recreate client-token for each guest**! From 3e445c80aa256fd300bc0930916a412533d26cd8 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:33:52 +0100 Subject: [PATCH 08/25] fixes --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index 49062da..86f27ce 100644 --- a/README.md +++ b/README.md @@ -250,16 +250,6 @@ After first success you have to replace `--issue` with `--renew`. every 4.8 hours. If network connectivity is lost, the loss of connectivity is detected during license renewal and the client has 19.2 hours in which to re-establish connectivity before its license expires. -```python -from datetime import timedelta - -LEASE_RENEWAL_PERIOD=0.2 # 20% -delta = timedelta(days=1) -renew = delta.total_seconds() * LEASE_RENEWAL_PERIOD -renew = timedelta(seconds=renew) -expires = delta - renew # 19.2 -``` - \*2 Always use `https`, since guest-drivers only support secure connections! \*3 If you recreate instance keys you need to **recreate client-token for each guest**! From a65687a082afd9a55fa9e6329de269815314db71 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Mon, 16 Jan 2023 10:34:20 +0100 Subject: [PATCH 09/25] bump version to 1.3.1 --- version.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.env b/version.env index 5be527b..f406e04 100644 --- a/version.env +++ b/version.env @@ -1 +1 @@ -VERSION=1.3 +VERSION=1.3.1 From a758d9397008f05a0d35fb23734e77471d4ee796 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 11:18:07 +0100 Subject: [PATCH 10/25] main.py - fixed empty lease origin response --- app/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 573cb42..46d8a65 100644 --- a/app/main.py +++ b/app/main.py @@ -170,8 +170,9 @@ async def _leases(request: Request, origin: bool = False): for lease in session.query(Lease).all(): x = lease.serialize() if origin: - # assume that each lease has a valid origin record - x['origin'] = session.query(Origin).filter(Origin.origin_ref == lease.origin_ref).first().serialize() + lease_origin = session.query(Origin).filter(Origin.origin_ref == lease.origin_ref).first() + if lease_origin is not None: + x['origin'] = lease_origin.serialize() response.append(x) session.close() return JSONr(response) From 742fa07ed48d215d67c1e141c83ef6ce20f68efd Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 11:18:25 +0100 Subject: [PATCH 11/25] bump version to 1.3.2 --- version.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.env b/version.env index f406e04..0c794cf 100644 --- a/version.env +++ b/version.env @@ -1 +1 @@ -VERSION=1.3.1 +VERSION=1.3.2 From 3c19fc9d5b51106d01e047304d028e40c5f06a2e Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 11:49:56 +0100 Subject: [PATCH 12/25] implemented "lease_renewal" attribute as calculated value within what period of time the license must be renewed --- app/main.py | 9 ++++++--- app/orm.py | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 46d8a65..204a55a 100644 --- a/app/main.py +++ b/app/main.py @@ -9,7 +9,7 @@ from dotenv import load_dotenv from fastapi import FastAPI from fastapi.requests import Request from json import loads as json_loads -from datetime import datetime +from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from calendar import timegm from jose import jws, jwk, jwt, JWTError @@ -43,6 +43,7 @@ INSTANCE_KEY_PUB = load_key(str(env('INSTANCE_KEY_PUB', join(dirname(__file__), TOKEN_EXPIRE_DELTA = relativedelta(days=int(env('TOKEN_EXPIRE_DAYS', 1)), hours=int(env('TOKEN_EXPIRE_HOURS', 0))) LEASE_EXPIRE_DELTA = relativedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=int(env('LEASE_EXPIRE_HOURS', 0))) LEASE_RENEWAL_PERIOD = float(env('LEASE_RENEWAL_PERIOD', 0.15)) +LEASE_RENEWAL_DELTA = timedelta(days=int(env('LEASE_EXPIRE_DAYS', 90)), hours=int(env('LEASE_EXPIRE_HOURS', 0))) CORS_ORIGINS = str(env('CORS_ORIGINS', '')).split(',') if (env('CORS_ORIGINS')) else [f'https://{DLS_URL}'] jwt_encode_key = jwk.construct(INSTANCE_KEY_RSA.export_key().decode('utf-8'), algorithm=ALGORITHMS.RS256) @@ -151,7 +152,8 @@ async def _origins(request: Request, leases: bool = False): for origin in session.query(Origin).all(): x = origin.serialize() if leases: - x['leases'] = list(map(lambda _: _.serialize(), Lease.find_by_origin_ref(db, origin.origin_ref))) + serialize = dict(renewal_period=LEASE_RENEWAL_PERIOD, renewal_delta=LEASE_RENEWAL_DELTA) + x['leases'] = list(map(lambda _: _.serialize(**serialize), Lease.find_by_origin_ref(db, origin.origin_ref))) response.append(x) session.close() return JSONr(response) @@ -168,7 +170,8 @@ async def _leases(request: Request, origin: bool = False): session = sessionmaker(bind=db)() response = [] for lease in session.query(Lease).all(): - x = lease.serialize() + serialize = dict(renewal_period=LEASE_RENEWAL_PERIOD, renewal_delta=LEASE_RENEWAL_DELTA) + x = lease.serialize(**serialize) if origin: lease_origin = session.query(Origin).filter(Origin.origin_ref == lease.origin_ref).first() if lease_origin is not None: diff --git a/app/orm.py b/app/orm.py index aadc0ef..50ff3ce 100644 --- a/app/orm.py +++ b/app/orm.py @@ -81,7 +81,7 @@ class Lease(Base): def __repr__(self): return f'Lease(origin_ref={self.origin_ref}, lease_ref={self.lease_ref}, expires={self.lease_expires})' - def serialize(self) -> dict: + def serialize(self, renewal_period: float, renewal_delta: datetime.timedelta) -> dict: return { 'lease_ref': self.lease_ref, 'origin_ref': self.origin_ref, @@ -89,6 +89,7 @@ class Lease(Base): 'lease_created': self.lease_created.isoformat(), 'lease_expires': self.lease_expires.isoformat(), 'lease_updated': self.lease_updated.isoformat(), + 'lease_renewal': Lease.calculate_renewal(renewal_period, renewal_delta), } @staticmethod @@ -156,6 +157,19 @@ class Lease(Base): session.close() return deletions + @staticmethod + def calculate_renewal(renewal_period: float, delta: datetime.timedelta): + """ + LEASE_RENEWAL_PERIOD=0.2 # 20% + delta = datetime.timedelta(days=1) + renew = delta.total_seconds() * LEASE_RENEWAL_PERIOD + renew = timedelta(seconds=renew) + expires = delta - renew # 19.2 + """ + renew = delta.total_seconds() * renewal_period + renew = datetime.timedelta(seconds=renew) + return delta - renew + def init(engine: Engine): tables = [Origin, Lease] From 7ef071f92b1de522fb5142cd2ceb54ad558175d3 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 14:57:09 +0100 Subject: [PATCH 13/25] removed fastapi-dls.service from conffiles --- .DEBIAN/conffiles | 1 - 1 file changed, 1 deletion(-) diff --git a/.DEBIAN/conffiles b/.DEBIAN/conffiles index cd8fdd7..008d731 100644 --- a/.DEBIAN/conffiles +++ b/.DEBIAN/conffiles @@ -1,2 +1 @@ /etc/fastapi-dls/env -/etc/systemd/system/fastapi-dls.service From d69d83392316cb1286a76bab2aeb96baa473ad77 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 14:57:39 +0100 Subject: [PATCH 14/25] migrated "[[ ]]" if statements to "[ ]" --- .DEBIAN/postinst | 8 ++++---- .DEBIAN/postrm | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.DEBIAN/postinst b/.DEBIAN/postinst index fbf9b82..8213736 100644 --- a/.DEBIAN/postinst +++ b/.DEBIAN/postinst @@ -3,7 +3,7 @@ WORKING_DIR=/usr/share/fastapi-dls CONFIG_DIR=/etc/fastapi-dls -if [[ ! -f $CONFIG_DIR/instance.private.pem ]]; then +if [ ! -f $CONFIG_DIR/instance.private.pem ]; then echo "> Create dls-instance keypair ..." openssl genrsa -out $CONFIG_DIR/instance.private.pem 2048 openssl rsa -in $CONFIG_DIR/instance.private.pem -outform PEM -pubout -out $CONFIG_DIR/instance.public.pem @@ -12,8 +12,8 @@ else fi while true; do - [[ -f $CONFIG_DIR/webserver.key ]] && default_answer="N" || default_answer="Y" - [[ $default_answer == "Y" ]] && V="Y/n" || V="y/N" + [ -f $CONFIG_DIR/webserver.key ] && default_answer="N" || default_answer="Y" + [ $default_answer == "Y" ] && V="Y/n" || V="y/N" read -p "> Do you wish to create self-signed webserver certificate? [${V}]" yn yn=${yn:-$default_answer} # ${parameter:-word} If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. case $yn in @@ -27,7 +27,7 @@ while true; do esac done -if [[ -f $CONFIG_DIR/webserver.key ]]; then +if [ -f $CONFIG_DIR/webserver.key ]; then echo "> Starting service ..." systemctl start fastapi-dls.service diff --git a/.DEBIAN/postrm b/.DEBIAN/postrm index b99d0fa..7c21ae7 100755 --- a/.DEBIAN/postrm +++ b/.DEBIAN/postrm @@ -1,6 +1,6 @@ #!/bin/bash -if [[ -f /etc/systemd/system/fastapi-dls.service ]]; then +if [ -f /etc/systemd/system/fastapi-dls.service ]; then echo "> Removing service file." rm /etc/systemd/system/fastapi-dls.service fi From 1e4070a1bacb3e31f75ae94328fb69888dba3309 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 14:57:54 +0100 Subject: [PATCH 15/25] added remove "/usr/share/fastapi-dls" to "postrm" --- .DEBIAN/postrm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.DEBIAN/postrm b/.DEBIAN/postrm index 7c21ae7..63ca44f 100755 --- a/.DEBIAN/postrm +++ b/.DEBIAN/postrm @@ -5,4 +5,9 @@ if [ -f /etc/systemd/system/fastapi-dls.service ]; then rm /etc/systemd/system/fastapi-dls.service fi +if [ -d /usr/share/fastapi-dls ]; then + echo "> Removing app." + rm -r /usr/share/fastapi-dls +fi + # todo From 70f7d3f48336282a4abab8f62b14f332cd53ad4d Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 15:36:38 +0100 Subject: [PATCH 16/25] mark Let's Encrypt section as optional --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86f27ce..b2ae198 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ pacman -U --noconfirm fastapi-dls.pkg.tar.zst Start with `systemctl start fastapi-dls.service` and enable autostart with `systemctl enable fastapi-dls.service`. -## Let's Encrypt Certificate +## Let's Encrypt Certificate (optional) If you're using installation via docker, you can use `traefik`. Please refer to their documentation. From 651af4cc8277a84e30eb12d7567d4ecd628e07ef Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 16:29:21 +0100 Subject: [PATCH 17/25] fixed client-token url and added wget als alternative to curl --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2ae198..22aed43 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,11 @@ Packages are available here: ```shell pacman -Sy FILENAME=/opt/fastapi-dls.pkg.tar.zst -url -o $FILENAME + +curl -o $FILENAME +# or +wget -O $FILENAME + pacman -U --noconfirm fastapi-dls.pkg.tar.zst ``` @@ -267,7 +271,10 @@ Successfully tested with this package versions: ## Linux ```shell -curl --insecure -L -X GET https:///client-token -o /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok +curl --insecure -L -X GET https:///-/client-token -o /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok +# or +wget --no-check-certificate -O /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok https:///-/client-token + service nvidia-gridd restart nvidia-smi -q | grep "License" ``` @@ -280,7 +287,7 @@ Now restart `NvContainerLocalSystem` service. **Power-Shell** ```Shell -curl.exe --insecure -L -X GET https:///client-token -o "C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken\client_configuration_token_$($(Get-Date).tostring('dd-MM-yy-hh-mm-ss')).tok" +curl.exe --insecure -L -X GET https:///-/client-token -o "C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken\client_configuration_token_$($(Get-Date).tostring('dd-MM-yy-hh-mm-ss')).tok" Restart-Service NVDisplay.ContainerLocalSystem 'C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' -q | Select-String "License" ``` From b09bb091a5e2c306c8abda2866a57cedfc52ad05 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 16:29:32 +0100 Subject: [PATCH 18/25] bump version to 1.3.3 --- version.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.env b/version.env index 0c794cf..93176fc 100644 --- a/version.env +++ b/version.env @@ -1 +1 @@ -VERSION=1.3.2 +VERSION=1.3.3 From b2e6fab294614c3e94b4a2e2929f33f6b1cf9cd2 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 16:37:45 +0100 Subject: [PATCH 19/25] fixes --- app/orm.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/orm.py b/app/orm.py index 50ff3ce..bbabbbc 100644 --- a/app/orm.py +++ b/app/orm.py @@ -1,4 +1,5 @@ -import datetime +from datetime import datetime, timedelta +from dateutil.relativedelta import relativedelta from sqlalchemy import Column, VARCHAR, CHAR, ForeignKey, DATETIME, update, and_, inspect from sqlalchemy.ext.declarative import declarative_base @@ -81,7 +82,10 @@ class Lease(Base): def __repr__(self): return f'Lease(origin_ref={self.origin_ref}, lease_ref={self.lease_ref}, expires={self.lease_expires})' - def serialize(self, renewal_period: float, renewal_delta: datetime.timedelta) -> dict: + def serialize(self, renewal_period: float, renewal_delta: timedelta) -> dict: + lease_renewal = int(Lease.calculate_renewal(renewal_period, renewal_delta).total_seconds()) + lease_renewal = self.lease_created + relativedelta(seconds=lease_renewal) + return { 'lease_ref': self.lease_ref, 'origin_ref': self.origin_ref, @@ -89,7 +93,7 @@ class Lease(Base): 'lease_created': self.lease_created.isoformat(), 'lease_expires': self.lease_expires.isoformat(), 'lease_updated': self.lease_updated.isoformat(), - 'lease_renewal': Lease.calculate_renewal(renewal_period, renewal_delta), + 'lease_renewal': lease_renewal.isoformat(), } @staticmethod @@ -134,7 +138,7 @@ class Lease(Base): return entity @staticmethod - def renew(engine: Engine, lease: "Lease", lease_expires: datetime.datetime, lease_updated: datetime.datetime): + def renew(engine: Engine, lease: "Lease", lease_expires: datetime, lease_updated: datetime): session = sessionmaker(bind=engine)() x = dict(lease_expires=lease_expires, lease_updated=lease_updated) session.execute(update(Lease).where(and_(Lease.origin_ref == lease.origin_ref, Lease.lease_ref == lease.lease_ref)).values(**x)) @@ -158,16 +162,17 @@ class Lease(Base): return deletions @staticmethod - def calculate_renewal(renewal_period: float, delta: datetime.timedelta): + def calculate_renewal(renewal_period: float, delta: timedelta) -> timedelta: """ + import datetime LEASE_RENEWAL_PERIOD=0.2 # 20% delta = datetime.timedelta(days=1) renew = delta.total_seconds() * LEASE_RENEWAL_PERIOD - renew = timedelta(seconds=renew) + renew = datetime.timedelta(seconds=renew) expires = delta - renew # 19.2 """ renew = delta.total_seconds() * renewal_period - renew = datetime.timedelta(seconds=renew) + renew = timedelta(seconds=renew) return delta - renew From f60f08d543e71c8ed0256be567c1f12fd27e79ae Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 16:57:15 +0100 Subject: [PATCH 20/25] run powershell as administrator --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22aed43..ca067ca 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,7 @@ nvidia-smi -q | grep "License" Download file and place it into `C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken`. Now restart `NvContainerLocalSystem` service. -**Power-Shell** +**Power-Shell** (run as administrator!) ```Shell curl.exe --insecure -L -X GET https:///-/client-token -o "C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken\client_configuration_token_$($(Get-Date).tostring('dd-MM-yy-hh-mm-ss')).tok" From bf858b38f4cabca29b63e9aa6b508ecc588aa4aa Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 17:09:13 +0100 Subject: [PATCH 21/25] fixes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca067ca..6028bfd 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ nvidia-smi -q | grep "License" ## Windows -Download file and place it into `C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken`. +Download *client-token* and place it into `C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken`. Now restart `NvContainerLocalSystem` service. **Power-Shell** (run as administrator!) @@ -292,7 +292,7 @@ Restart-Service NVDisplay.ContainerLocalSystem 'C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' -q | Select-String "License" ``` -## Endpoints +# Endpoints ### `GET /` From 059a51fe74a8017389919f3ada3ddcbbaf74fe61 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 17:25:48 +0100 Subject: [PATCH 22/25] refactored commands --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6028bfd..28a7bdc 100644 --- a/README.md +++ b/README.md @@ -270,28 +270,66 @@ Successfully tested with this package versions: ## Linux +Download *client-token* and place it into `/etc/nvidia/ClientConfigToken`: + ```shell curl --insecure -L -X GET https:///-/client-token -o /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok # or wget --no-check-certificate -O /etc/nvidia/ClientConfigToken/client_configuration_token_$(date '+%d-%m-%Y-%H-%M-%S').tok https:///-/client-token +``` +Restart `nvidia-gridd` service: + +```shell service nvidia-gridd restart +``` + +Check licensing status: + +```shell nvidia-smi -q | grep "License" ``` -## Windows +Output should be something like: -Download *client-token* and place it into `C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken`. -Now restart `NvContainerLocalSystem` service. +```text +vGPU Software Licensed Product + License Status : Licensed (Expiry: YYYY-M-DD hh:mm:ss GMT) +``` + +Done. For more information check [troubleshoot section](#troubleshoot). + +## Windows **Power-Shell** (run as administrator!) -```Shell +Download *client-token* and place it into `C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken`: + +```shell curl.exe --insecure -L -X GET https:///-/client-token -o "C:\Program Files\NVIDIA Corporation\vGPU Licensing\ClientConfigToken\client_configuration_token_$($(Get-Date).tostring('dd-MM-yy-hh-mm-ss')).tok" -Restart-Service NVDisplay.ContainerLocalSystem -'C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' -q | Select-String "License" ``` +Restart `NvContainerLocalSystem` service: + +```Shell +Restart-Service NVDisplay.ContainerLocalSystem +``` + +Check licensing status: + +```shell +& 'C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe' -q | Select-String "License" +``` + +Output should be something like: + +```text +vGPU Software Licensed Product + License Status : Licensed (Expiry: YYYY-M-DD hh:mm:ss GMT) +``` + +Done. For more information check [troubleshoot section](#troubleshoot). + # Endpoints ### `GET /` From 0ab5969d3a1d5a82bd81109d962a72d55f7af20a Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Tue, 17 Jan 2023 17:27:26 +0100 Subject: [PATCH 23/25] fixes --- app/orm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/orm.py b/app/orm.py index bbabbbc..bfd6557 100644 --- a/app/orm.py +++ b/app/orm.py @@ -84,7 +84,7 @@ class Lease(Base): def serialize(self, renewal_period: float, renewal_delta: timedelta) -> dict: lease_renewal = int(Lease.calculate_renewal(renewal_period, renewal_delta).total_seconds()) - lease_renewal = self.lease_created + relativedelta(seconds=lease_renewal) + lease_renewal = self.lease_updated + relativedelta(seconds=lease_renewal) return { 'lease_ref': self.lease_ref, @@ -173,7 +173,7 @@ class Lease(Base): """ renew = delta.total_seconds() * renewal_period renew = timedelta(seconds=renew) - return delta - renew + return renew def init(engine: Engine): From de17b0f1b5202c76fa1027f03260736474c01c88 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 18 Jan 2023 07:58:30 +0100 Subject: [PATCH 24/25] fixes --- .DEBIAN/postrm | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.DEBIAN/postrm b/.DEBIAN/postrm index 63ca44f..c3a4023 100755 --- a/.DEBIAN/postrm +++ b/.DEBIAN/postrm @@ -1,13 +1,9 @@ #!/bin/bash -if [ -f /etc/systemd/system/fastapi-dls.service ]; then - echo "> Removing service file." - rm /etc/systemd/system/fastapi-dls.service -fi - -if [ -d /usr/share/fastapi-dls ]; then - echo "> Removing app." - rm -r /usr/share/fastapi-dls -fi +# is removed automatically +#if [ "$1" = purge ] && [ -d /usr/share/fastapi-dls ]; then +# echo "> Removing app." +# rm -r /usr/share/fastapi-dls +#fi # todo From 5bb8f17679e83290bf8591c56beec7a7c1d71a58 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 18 Jan 2023 08:07:55 +0100 Subject: [PATCH 25/25] improvements --- .DEBIAN/postrm | 2 +- .DEBIAN/prerm | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.DEBIAN/postrm b/.DEBIAN/postrm index c3a4023..9c715dd 100755 --- a/.DEBIAN/postrm +++ b/.DEBIAN/postrm @@ -6,4 +6,4 @@ # rm -r /usr/share/fastapi-dls #fi -# todo +echo -e "> Done." diff --git a/.DEBIAN/prerm b/.DEBIAN/prerm index 296c995..3678725 100755 --- a/.DEBIAN/prerm +++ b/.DEBIAN/prerm @@ -1,5 +1,3 @@ #!/bin/bash echo -e "> Starting uninstallation of 'fastapi-dls'!" - -# todo