From fc4ec7b0f8438b46b382303b6da6ad9b850613a5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 11:42:15 +0100 Subject: [PATCH] update readme + api --- nicohack202002/uncloud/README.md | 25 +++++++++++++++- nicohack202002/uncloud/requirements.txt | 1 + .../uncloud/uncloud/secrets_sample.py | 11 ++----- nicohack202002/uncloud/uncloud/settings.py | 27 ++++++++--------- nicohack202002/uncloud/uncloud_api/admin.py | 4 +-- nicohack202002/uncloud/uncloud_api/models.py | 30 ++++++++++++------- 6 files changed, 61 insertions(+), 37 deletions(-) diff --git a/nicohack202002/uncloud/README.md b/nicohack202002/uncloud/README.md index eca82d4..9db1c5c 100644 --- a/nicohack202002/uncloud/README.md +++ b/nicohack202002/uncloud/README.md @@ -5,7 +5,7 @@ Alpine: ``` -apk add openldap-dev +apk add openldap-dev postgresql-dev ``` ### Python requirements @@ -22,3 +22,26 @@ Then install the requirements ``` pip install -r requirements.txt ``` + +### Database requirements + +Due to the use of the JSONField, postgresql is required. + +First create a role to be used: + +``` +postgres=# create role nico login; +``` + +Then create the database owner by the new role: + +``` +postgres=# create database uncloud owner nico; +``` + + + +### Secrets + +cp `uncloud/secrets_sample.py` to `uncloud/secrets.py` and replace the +sample values with real values. diff --git a/nicohack202002/uncloud/requirements.txt b/nicohack202002/uncloud/requirements.txt index 11ab309..1b4e05b 100644 --- a/nicohack202002/uncloud/requirements.txt +++ b/nicohack202002/uncloud/requirements.txt @@ -3,3 +3,4 @@ djangorestframework django-auth-ldap stripe xmltodict +psycopg2 diff --git a/nicohack202002/uncloud/uncloud/secrets_sample.py b/nicohack202002/uncloud/uncloud/secrets_sample.py index d145124..b578a8b 100644 --- a/nicohack202002/uncloud/uncloud/secrets_sample.py +++ b/nicohack202002/uncloud/uncloud/secrets_sample.py @@ -1,12 +1,3 @@ - - - - - - - - - # Live/test key from stripe STRIPE_KEY="" @@ -15,3 +6,5 @@ OPENNEBULA_URL='https://opennebula.ungleich.ch:2634/RPC2' # user:pass for accessing opennebula OPENNEBULA_USER_PASS='user:password' + +POSTGRESQL_DB_NAME="uncloud" diff --git a/nicohack202002/uncloud/uncloud/settings.py b/nicohack202002/uncloud/uncloud/settings.py index 1e8f358..0e08750 100644 --- a/nicohack202002/uncloud/uncloud/settings.py +++ b/nicohack202002/uncloud/uncloud/settings.py @@ -74,15 +74,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'uncloud.wsgi.application' -# Database -# https://docs.djangoproject.com/en/3.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} # Password validation @@ -159,8 +150,16 @@ USE_TZ = True STATIC_URL = '/static/' -# Uncommitted file -# import uncloud.secrets -# -# import stripe -# stripe.api_key = uncloud.secrets.STRIPE_KEY +# Uncommitted file with secrets +import uncloud.secrets + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': uncloud.secrets.POSTGRESQL_DB_NAME, + } +} diff --git a/nicohack202002/uncloud/uncloud_api/admin.py b/nicohack202002/uncloud/uncloud_api/admin.py index f9f5589..d242668 100644 --- a/nicohack202002/uncloud/uncloud_api/admin.py +++ b/nicohack202002/uncloud/uncloud_api/admin.py @@ -2,5 +2,5 @@ from django.contrib import admin from .models import Product, Feature -admin.site.register(Product) -admin.site.register(Feature) +#admin.site.register(Product) +#admin.site.register(Feature) diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/nicohack202002/uncloud/uncloud_api/models.py index e4292dc..11a7560 100644 --- a/nicohack202002/uncloud/uncloud_api/models.py +++ b/nicohack202002/uncloud/uncloud_api/models.py @@ -32,7 +32,12 @@ from django.contrib.auth import get_user_model # Should have a log = ... => 1:n field for most models! class Product(models.Model): + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + owner = models.ForeignKey(get_user_model(), + on_delete=models.CASCADE) + # override these fields by default + description = "" recurring_period = "not_recurring" @@ -42,9 +47,13 @@ class Product(models.Model): ('being_created', 'Being created'), ('created_active', 'Created'), ('deleted', 'Deleted') - ) + ), + default='pending' ) + class Meta: + abstract = True + def __str__(self): return "{}".format(self.name) @@ -106,19 +115,18 @@ class Feature(models.Model): # value_str # value_float + class Meta: + abstract = True + def __str__(self): return "'{}' - '{}'".format(self.product, self.name) -class Order(models.Model): - uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) +# class Order(models.Model): +# uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - owner = models.ForeignKey(get_user_model(), - on_delete=models.CASCADE) +# owner = models.ForeignKey(get_user_model(), +# on_delete=models.CASCADE) - product = models.ForeignKey(Product, - on_delete=models.CASCADE) - - -class VMSnapshotOrder(Order): - pass +# product = models.ForeignKey(Product, +# on_delete=models.CASCADE)