From 0708a1e1fdfa24ac419a2e2fb7a7a8a54607ca62 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 21 Feb 2020 15:05:17 +0100 Subject: [PATCH 01/16] add requirements.txt --- nicohack202002/uncloud/requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 nicohack202002/uncloud/requirements.txt diff --git a/nicohack202002/uncloud/requirements.txt b/nicohack202002/uncloud/requirements.txt new file mode 100644 index 0000000..d81b59b --- /dev/null +++ b/nicohack202002/uncloud/requirements.txt @@ -0,0 +1,4 @@ +django +djangorestframework +django-auth-ldap +stripe From 4df7c761d3040c4a79c274a1ca44855e62c5c480 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 21 Feb 2020 20:51:04 +0100 Subject: [PATCH 02/16] ++stuff --- .../uncloud_api/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/snapshot.py | 29 +++++++++++++++++++ nicohack202002/uncloud/uncloud_api/models.py | 1 + 4 files changed, 30 insertions(+) create mode 100644 nicohack202002/uncloud/uncloud_api/management/__init__.py create mode 100644 nicohack202002/uncloud/uncloud_api/management/commands/__init__.py create mode 100644 nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py diff --git a/nicohack202002/uncloud/uncloud_api/management/__init__.py b/nicohack202002/uncloud/uncloud_api/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/__init__.py b/nicohack202002/uncloud/uncloud_api/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py b/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py new file mode 100644 index 0000000..41d0e38 --- /dev/null +++ b/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py @@ -0,0 +1,29 @@ +import time +from django.conf import settings +from django.core.management.base import BaseCommand + +from uncloud_api import models + + +class Command(BaseCommand): + args = '' + help = 'VM Snapshot support' + + def add_arguments(self, parser): + parser.add_argument('command', type=str, help='Command') + + def handle(self, *args, **options): + print("Snapshotting") + #getattr(self, options['command'])(**options) + + @classmethod + def monitor(cls, **_): + while True: + try: + tweets = models.Reply.get_target_tweets() + responses = models.Reply.objects.values_list('tweet_id', flat=True) + new_tweets = [x for x in tweets if x.id not in responses] + models.Reply.send(new_tweets) + except TweepError as e: + print(e) + time.sleep(60) diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/nicohack202002/uncloud/uncloud_api/models.py index 9d4291a..06e77ed 100644 --- a/nicohack202002/uncloud/uncloud_api/models.py +++ b/nicohack202002/uncloud/uncloud_api/models.py @@ -49,6 +49,7 @@ class Order(models.Model): on_delete=models.CASCADE) + class OrderReference(models.Model): """ An order can references another product / relate to it. From dc5092be71800ce0f1532830eab9b7588771d913 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 21 Feb 2020 21:41:51 +0100 Subject: [PATCH 03/16] Add sample secrets --- nicohack202002/uncloud/uncloud/secrets_sample.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 nicohack202002/uncloud/uncloud/secrets_sample.py diff --git a/nicohack202002/uncloud/uncloud/secrets_sample.py b/nicohack202002/uncloud/uncloud/secrets_sample.py new file mode 100644 index 0000000..a895bc9 --- /dev/null +++ b/nicohack202002/uncloud/uncloud/secrets_sample.py @@ -0,0 +1,11 @@ + + + + + + + + + + +STRIPE_KEY="" From b1bb6bc314c44ac028ae27ce664caec22c7ff3b2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 22 Feb 2020 00:22:42 +0100 Subject: [PATCH 04/16] Make products available via getattr --- .../opennebula/management/commands/syncvm.py | 8 ++- nicohack202002/uncloud/requirements.txt | 1 + .../uncloud/uncloud/secrets_sample.py | 8 ++- nicohack202002/uncloud/uncloud/urls.py | 2 + .../uncloud_api/management/commands/hack.py | 26 +++++++++ nicohack202002/uncloud/uncloud_api/models.py | 54 ++++++++++++++++--- .../uncloud/uncloud_api/serializers.py | 3 ++ nicohack202002/uncloud/uncloud_api/views.py | 45 +++++++++++++++- notes-nico.org | 9 ++++ plan.org | 6 +++ 10 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 nicohack202002/uncloud/uncloud_api/management/commands/hack.py create mode 100644 plan.org diff --git a/nicohack202002/uncloud/opennebula/management/commands/syncvm.py b/nicohack202002/uncloud/opennebula/management/commands/syncvm.py index 5ea451d..205b066 100644 --- a/nicohack202002/uncloud/opennebula/management/commands/syncvm.py +++ b/nicohack202002/uncloud/opennebula/management/commands/syncvm.py @@ -9,8 +9,7 @@ from xmltodict import parse from opennebula.models import VM as VMModel -OCA_SESSION_STRING = os.environ.get('OCASECRETS', '') - +import uncloud.secrets class Command(BaseCommand): help = 'Syncronize VM information from OpenNebula' @@ -19,9 +18,9 @@ class Command(BaseCommand): pass def handle(self, *args, **options): - with RPCClient('https://opennebula.ungleich.ch:2634/RPC2') as rpc_client: + with RPCClient(uncloud.secrets.OPENNEBULA_URL) as rpc_client: success, response, *_ = rpc_client.one.vmpool.infoextended( - OCA_SESSION_STRING, -2, -1, -1, -1 + uncloud.secrets.OPENNEBULA_USER_PASS, -2, -1, -1, -1 ) if success: vms = json.loads(json.dumps(parse(response)))['VM_POOL']['VM'] @@ -37,4 +36,3 @@ class Command(BaseCommand): vm_object.save() else: print(response) - diff --git a/nicohack202002/uncloud/requirements.txt b/nicohack202002/uncloud/requirements.txt index d81b59b..11ab309 100644 --- a/nicohack202002/uncloud/requirements.txt +++ b/nicohack202002/uncloud/requirements.txt @@ -2,3 +2,4 @@ django djangorestframework django-auth-ldap stripe +xmltodict diff --git a/nicohack202002/uncloud/uncloud/secrets_sample.py b/nicohack202002/uncloud/uncloud/secrets_sample.py index a895bc9..d145124 100644 --- a/nicohack202002/uncloud/uncloud/secrets_sample.py +++ b/nicohack202002/uncloud/uncloud/secrets_sample.py @@ -7,5 +7,11 @@ - +# Live/test key from stripe STRIPE_KEY="" + +# XML-RPC interface of opennebula +OPENNEBULA_URL='https://opennebula.ungleich.ch:2634/RPC2' + +# user:pass for accessing opennebula +OPENNEBULA_USER_PASS='user:password' diff --git a/nicohack202002/uncloud/uncloud/urls.py b/nicohack202002/uncloud/uncloud/urls.py index f5804c9..c7ce9b6 100644 --- a/nicohack202002/uncloud/uncloud/urls.py +++ b/nicohack202002/uncloud/uncloud/urls.py @@ -30,7 +30,9 @@ router.register(r'groups', views.GroupViewSet) urlpatterns = [ path('', include(router.urls)), path('admin/', admin.site.urls), + path('products/', views.ProductsView.as_view(), name='products'), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), path('vm/list/', oneviews.VMList.as_view(), name='vm_list'), path('vm/detail//', oneviews.VMDetail.as_view(), name='vm_detail'), + ] diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/hack.py b/nicohack202002/uncloud/uncloud_api/management/commands/hack.py new file mode 100644 index 0000000..e129952 --- /dev/null +++ b/nicohack202002/uncloud/uncloud_api/management/commands/hack.py @@ -0,0 +1,26 @@ +import time +from django.conf import settings +from django.core.management.base import BaseCommand + +import uncloud_api.models + +import inspect +import sys +import re + +class Command(BaseCommand): + args = '' + help = 'hacking - only use if you are Nico' + + def add_arguments(self, parser): + parser.add_argument('command', type=str, help='Command') + + def handle(self, *args, **options): + getattr(self, options['command'])(**options) + + @classmethod + def classtest(cls, **_): + clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass) + for name, c in clsmembers: + if re.match(r'.+Product$', name): + print("{} -> {}".format(name, c)) diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/nicohack202002/uncloud/uncloud_api/models.py index 06e77ed..6df17c4 100644 --- a/nicohack202002/uncloud/uncloud_api/models.py +++ b/nicohack202002/uncloud/uncloud_api/models.py @@ -3,9 +3,38 @@ import uuid from django.db import models from django.contrib.auth import get_user_model +# Product in DB vs. product in code +# DB: +# - need to define params (+param types) in db -> messy? +# - get /products/ is easy / automatic +# +# code +# - can have serializer/verification of fields easily in DRF +# - can have per product side effects / extra code running +# - might (??) make features easier?? +# - how to setup / query the recurring period (?) +# - could get products list via getattr() + re ...Product() classes +# -> this could include the url for ordering => /order/vm_snapshot (params) +# ---> this would work with urlpatterns +# Combination: create specific product in DB (?) +# - a table per product (?) with 1 entry? + +# Orders +# define state in DB +# select a price from a product => product might change, order stays +# params: +# - the product uuid or name (?) => productuuid +# - the product parameters => for each feature +# + +# logs +# Should have a log = ... => 1:n field for most models! class Product(models.Model): + + description = "" + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=256) @@ -21,10 +50,18 @@ class Product(models.Model): default="not_recurring" ) + # params = [ vmuuid, ... ] + # features -> required as defined + def __str__(self): return "{}".format(self.name) +class VMSnapshotProduct(Product): + # need to setup recurring_periodd + + description = "Create snapshot of a VM" + class Feature(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) @@ -35,6 +72,15 @@ class Feature(models.Model): product = models.ForeignKey(Product, on_delete=models.CASCADE) + # params for "cpu": cpu_count -> int + # each feature can only have one parameters + # could call this "value" and set whether it is user usable + # has_value = True/False + # value = string -> int (?) + # value_int + # value_str + # value_float + def __str__(self): return "'{}' - '{}'".format(self.product, self.name) @@ -49,11 +95,5 @@ class Order(models.Model): on_delete=models.CASCADE) - -class OrderReference(models.Model): - """ - An order can references another product / relate to it. - This model is used for the relation - """ - +class VMSnapshotOrder(Order): pass diff --git a/nicohack202002/uncloud/uncloud_api/serializers.py b/nicohack202002/uncloud/uncloud_api/serializers.py index 57532f2..1573bf0 100644 --- a/nicohack202002/uncloud/uncloud_api/serializers.py +++ b/nicohack202002/uncloud/uncloud_api/serializers.py @@ -14,3 +14,6 @@ class GroupSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Group fields = ['url', 'name'] + +class VMSnapshotSerializer(serializers.Serializer): + pass diff --git a/nicohack202002/uncloud/uncloud_api/views.py b/nicohack202002/uncloud/uncloud_api/views.py index 88e0543..8cf76f2 100644 --- a/nicohack202002/uncloud/uncloud_api/views.py +++ b/nicohack202002/uncloud/uncloud_api/views.py @@ -2,9 +2,11 @@ from django.shortcuts import render from django.contrib.auth import get_user_model from django.contrib.auth.models import Group -from rest_framework import viewsets, permissions - +from rest_framework import viewsets, permissions, generics from .serializers import UserSerializer, GroupSerializer +from rest_framework.views import APIView +from rest_framework.response import Response + class CreditCardViewSet(viewsets.ModelViewSet): @@ -35,3 +37,42 @@ class GroupViewSet(viewsets.ModelViewSet): serializer_class = GroupSerializer permission_classes = [permissions.IsAuthenticated] + +class GroupViewSet(viewsets.ModelViewSet): + """ + API endpoint that allows groups to be viewed or edited. + """ + queryset = Group.objects.all() + serializer_class = GroupSerializer + + permission_classes = [permissions.IsAuthenticated] + + +# POST /vm/snapshot/ vmuuid=... => create snapshot, returns snapshot uuid +# GET /vm/snapshot => list +# DEL /vm/snapshot/ => delete +# create-list -> get, post => ListCreateAPIView +# del on other! +class VMSnapshotView(generics.ListCreateAPIView): + #lookup_field = 'uuid' + permission_classes = [permissions.IsAuthenticated] + +import inspect +import sys +import re + +class ProductsView(APIView): + def get(self, request, format=None): + clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass) + products = [] + for name, c in clsmembers: + # Include everything that ends in Product, but not Product itself + if re.search(r'.+Product$', name): + products.append({ + 'name': name, + 'description': c.description + } + ) + + + return Response(products) diff --git a/notes-nico.org b/notes-nico.org index 21102f9..93e0c00 100644 --- a/notes-nico.org +++ b/notes-nico.org @@ -1,5 +1,14 @@ * snapshot feature ** product: vm-snapshot +** flow +*** list all my VMs +**** get the uuid of the VM I want to take a snapshot of +*** request a snapshot +``` +vmuuid=$(http nicocustomer +http -a nicocustomer:xxx http://uncloud.ch/vm/create_snapshot uuid= +password=... +``` * steps ** DONE authenticate via ldap CLOSED: [2020-02-20 Thu 19:05] diff --git a/plan.org b/plan.org new file mode 100644 index 0000000..9f172c2 --- /dev/null +++ b/plan.org @@ -0,0 +1,6 @@ +* TODO register CC +* TODO list products +* ahmed +** schemas +*** field: is_valid? - used by schemas +*** definition of a "schema" From 4f4a4be8396316df064f4acd8f61a4dc184e3fb0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 22 Feb 2020 00:50:06 +0100 Subject: [PATCH 05/16] good night commit - introducing status --- nicohack202002/uncloud/uncloud_api/models.py | 62 ++++++++++++++------ nicohack202002/uncloud/uncloud_api/views.py | 11 +++- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/nicohack202002/uncloud/uncloud_api/models.py index 6df17c4..fafefe6 100644 --- a/nicohack202002/uncloud/uncloud_api/models.py +++ b/nicohack202002/uncloud/uncloud_api/models.py @@ -32,35 +32,59 @@ from django.contrib.auth import get_user_model # Should have a log = ... => 1:n field for most models! class Product(models.Model): - + # override these fields by default description = "" + recurring_period = "not_recurring" - uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - name = models.CharField(max_length=256) - - recurring_period = models.CharField(max_length=256, - choices = ( - ("per_year", "Per Year"), - ("per_month", "Per Month"), - ("per_week", "Per Week"), - ("per_day", "Per Day"), - ("per_hour", "Per Hour"), - ("not_recurring", "Not recurring") - ), - default="not_recurring" - ) - - # params = [ vmuuid, ... ] - # features -> required as defined + status = models.CharField(max_length=256, + choices = ( + ('pending', 'Pending'), + ('being_created', 'Being created'), + ('created_active', 'Created'), + ('deleted', 'Deleted') + ) def __str__(self): return "{}".format(self.name) class VMSnapshotProduct(Product): - # need to setup recurring_periodd + price_per_gb_ssd = 0.35 + price_per_gb_hdd = 1.5/100 + + sample_ssd = 10 + sample_hdd = 100 + + def recurring_price(self): + return 0 + + def one_time_price(self): + return 0 + + @classmethod + def sample_price(cls): + return cls.sample_ssd * cls.price_per_gb_ssd + cls.sample_hdd * cls.price_per_gb_hdd description = "Create snapshot of a VM" + recurring_period = "monthly" + + @classmethod + def pricing_model(cls): + return """ +Pricing is on monthly basis and storage prices are equivalent to the storage +price in the VM. + +Price per GB SSD is: {} +Price per GB HDD is: {} + + +Sample price for a VM with {} GB SSD and {} GB HDD VM is: {}. +""".format(cls.price_per_gb_ssd, cls.price_per_gb_hdd, + cls.sample_ssd, cls.sample_hdd, cls.sample_price()) + + gb_ssd = models.FloatField() + gb_hdd = models.FloatField() + class Feature(models.Model): diff --git a/nicohack202002/uncloud/uncloud_api/views.py b/nicohack202002/uncloud/uncloud_api/views.py index 8cf76f2..68963ff 100644 --- a/nicohack202002/uncloud/uncloud_api/views.py +++ b/nicohack202002/uncloud/uncloud_api/views.py @@ -61,16 +61,21 @@ import inspect import sys import re +# Next: create /order/ urls +# Next: strip off "Product" at the end class ProductsView(APIView): def get(self, request, format=None): clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass) products = [] for name, c in clsmembers: # Include everything that ends in Product, but not Product itself - if re.search(r'.+Product$', name): + m = re.match(r'(?P.+)Product$', name) + if m: products.append({ - 'name': name, - 'description': c.description + 'name': m.group('pname'), + 'description': c.description, + 'recurring_period': c.recurring_period, + 'pricing_model': c.pricing_model() } ) From 26449d31590c28b730b1371b6afe2936d9c7722f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 09:18:16 +0100 Subject: [PATCH 06/16] ++snapshot ideas --- .../uncloud/uncloud_api/management/commands/snapshot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py b/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py index 41d0e38..1a021aa 100644 --- a/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py +++ b/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py @@ -16,6 +16,13 @@ class Command(BaseCommand): print("Snapshotting") #getattr(self, options['command'])(**options) + + def get_disks_of_vm(self, vmuuid): + """ Returns the disks used by a VM in the format + ( ceph_name, size ) + """ + pass + @classmethod def monitor(cls, **_): while True: From ce0da4b827ff06238f2e5ace73bf1246024fd868 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 09:44:55 +0100 Subject: [PATCH 07/16] + bracket --- nicohack202002/uncloud/uncloud_api/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/nicohack202002/uncloud/uncloud_api/models.py index fafefe6..e4292dc 100644 --- a/nicohack202002/uncloud/uncloud_api/models.py +++ b/nicohack202002/uncloud/uncloud_api/models.py @@ -43,6 +43,7 @@ class Product(models.Model): ('created_active', 'Created'), ('deleted', 'Deleted') ) + ) def __str__(self): return "{}".format(self.name) From 7f821b4d5a374053b66d7616d286edbc2ccb7af2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 10:31:28 +0100 Subject: [PATCH 08/16] add readme --- nicohack202002/uncloud/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 nicohack202002/uncloud/README.md diff --git a/nicohack202002/uncloud/README.md b/nicohack202002/uncloud/README.md new file mode 100644 index 0000000..eca82d4 --- /dev/null +++ b/nicohack202002/uncloud/README.md @@ -0,0 +1,24 @@ +## Install + +### OS package requirements + +Alpine: + +``` +apk add openldap-dev +``` + +### Python requirements + +If you prefer using a venv, use: + +``` +python -m venv venv +. ./venv/bin/activate +``` + +Then install the requirements + +``` +pip install -r requirements.txt +``` From 581865460b16448641e78bb90d950960ece20786 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 11:41:51 +0100 Subject: [PATCH 09/16] Mess with migrations --- .../opennebula/migrations/0001_initial.py | 13 ++++--- .../migrations/0002_auto_20200221_1024.py | 23 ------------ .../migrations/0003_auto_20200221_1113.py | 21 ----------- .../uncloud_api/migrations/0001_initial.py | 35 +++++-------------- .../uncloud_auth/migrations/0001_initial.py | 2 +- 5 files changed, 17 insertions(+), 77 deletions(-) delete mode 100644 nicohack202002/uncloud/opennebula/migrations/0002_auto_20200221_1024.py delete mode 100644 nicohack202002/uncloud/opennebula/migrations/0003_auto_20200221_1113.py diff --git a/nicohack202002/uncloud/opennebula/migrations/0001_initial.py b/nicohack202002/uncloud/opennebula/migrations/0001_initial.py index e2c6a1f..f1d3d6b 100644 --- a/nicohack202002/uncloud/opennebula/migrations/0001_initial.py +++ b/nicohack202002/uncloud/opennebula/migrations/0001_initial.py @@ -1,6 +1,9 @@ -# Generated by Django 3.0.3 on 2020-02-21 10:22 +# Generated by Django 3.0.3 on 2020-02-23 10:02 +from django.conf import settings +import django.contrib.postgres.fields.jsonb from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -8,16 +11,16 @@ class Migration(migrations.Migration): initial = True dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] operations = [ migrations.CreateModel( name='VM', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('vmid', models.IntegerField()), - ('owner', models.CharField(max_length=128)), - ('data', models.CharField(max_length=65536)), + ('vmid', models.IntegerField(primary_key=True, serialize=False)), + ('data', django.contrib.postgres.fields.jsonb.JSONField()), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), ] diff --git a/nicohack202002/uncloud/opennebula/migrations/0002_auto_20200221_1024.py b/nicohack202002/uncloud/opennebula/migrations/0002_auto_20200221_1024.py deleted file mode 100644 index 43b7442..0000000 --- a/nicohack202002/uncloud/opennebula/migrations/0002_auto_20200221_1024.py +++ /dev/null @@ -1,23 +0,0 @@ -# Generated by Django 3.0.3 on 2020-02-21 10:24 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('opennebula', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='vm', - name='data', - field=models.CharField(max_length=65536, null=True), - ), - migrations.AlterField( - model_name='vm', - name='owner', - field=models.CharField(max_length=128, null=True), - ), - ] diff --git a/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200221_1113.py b/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200221_1113.py deleted file mode 100644 index 9ccc22e..0000000 --- a/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200221_1113.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 3.0.3 on 2020-02-21 11:13 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('opennebula', '0002_auto_20200221_1024'), - ] - - operations = [ - migrations.AlterField( - model_name='vm', - name='owner', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), - ), - ] diff --git a/nicohack202002/uncloud/uncloud_api/migrations/0001_initial.py b/nicohack202002/uncloud/uncloud_api/migrations/0001_initial.py index 33be28d..d8d9630 100644 --- a/nicohack202002/uncloud/uncloud_api/migrations/0001_initial.py +++ b/nicohack202002/uncloud/uncloud_api/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.3 on 2020-02-21 10:42 +# Generated by Django 3.0.3 on 2020-02-23 10:16 from django.conf import settings from django.db import migrations, models @@ -16,35 +16,16 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='OrderReference', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ], - ), - migrations.CreateModel( - name='Product', - fields=[ - ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('name', models.CharField(max_length=256)), - ('recurring_period', models.CharField(choices=[('per_year', 'Per Year'), ('per_month', 'Per Month'), ('per_week', 'Per Week'), ('per_day', 'Per Day'), ('per_hour', 'Per Hour'), ('not_recurring', 'Not recurring')], default='not_recurring', max_length=256)), - ], - ), - migrations.CreateModel( - name='Order', + name='VMSnapshotProduct', fields=[ ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('status', models.CharField(choices=[('pending', 'Pending'), ('being_created', 'Being created'), ('created_active', 'Created'), ('deleted', 'Deleted')], default='pending', max_length=256)), + ('gb_ssd', models.FloatField()), + ('gb_hdd', models.FloatField()), ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), - ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_api.Product')), - ], - ), - migrations.CreateModel( - name='Feature', - fields=[ - ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('name', models.CharField(max_length=256)), - ('recurring_price', models.FloatField(default=0)), - ('one_time_price', models.FloatField()), - ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uncloud_api.Product')), ], + options={ + 'abstract': False, + }, ), ] diff --git a/nicohack202002/uncloud/uncloud_auth/migrations/0001_initial.py b/nicohack202002/uncloud/uncloud_auth/migrations/0001_initial.py index 267adf2..a3ade55 100644 --- a/nicohack202002/uncloud/uncloud_auth/migrations/0001_initial.py +++ b/nicohack202002/uncloud/uncloud_auth/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.0.3 on 2020-02-21 10:41 +# Generated by Django 3.0.3 on 2020-02-23 10:02 import django.contrib.auth.models import django.contrib.auth.validators From f588691f0d9bebf08e775334fddeceeb1b695fa7 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 11:42:03 +0100 Subject: [PATCH 10/16] [opennebula] add json, add helper functions --- .../opennebula/management/commands/syncvm.py | 8 ++++-- nicohack202002/uncloud/opennebula/models.py | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/nicohack202002/uncloud/opennebula/management/commands/syncvm.py b/nicohack202002/uncloud/opennebula/management/commands/syncvm.py index 205b066..136e145 100644 --- a/nicohack202002/uncloud/opennebula/management/commands/syncvm.py +++ b/nicohack202002/uncloud/opennebula/management/commands/syncvm.py @@ -32,7 +32,11 @@ class Command(BaseCommand): except get_user_model().DoesNotExist: user = get_user_model().objects.create_user(username=vm_owner) - vm_object = VMModel.objects.create(vmid=vm_id, owner=user, data=vm) - vm_object.save() + VMModel.objects.update_or_create( + defaults= { 'data': vm, + 'owner': user }, + vmid=vm_id + ) + else: print(response) diff --git a/nicohack202002/uncloud/opennebula/models.py b/nicohack202002/uncloud/opennebula/models.py index cd1a044..babba26 100644 --- a/nicohack202002/uncloud/opennebula/models.py +++ b/nicohack202002/uncloud/opennebula/models.py @@ -1,8 +1,32 @@ from django.db import models from django.contrib.auth import get_user_model +from django.contrib.postgres.fields import JSONField class VM(models.Model): - vmid = models.IntegerField() + vmid = models.IntegerField(primary_key=True) owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) - data = models.CharField(max_length=65536, null=True) + data = JSONField() + + + def cores(self): + return self.data['TEMPLATE']['VCPU'] + + def ram_in_gb(self): + return (int(self.data['TEMPLATE']['MEMORY'])/1024.) + + def disks(self): + """ + If there is no disk then the key DISK does not exist. + + If there is only one disk, we have a dictionary in the database. + + If there are multiple disks, we have a list of dictionaries in the database. + """ + + if not 'DISK' in self.data['TEMPLATE']['DISK']: + return [] + elif type(self.data['TEMPLATE']['DISK']) is dict: + return [ self.data['TEMPLATE']['DISK'] ] + else: + return self.data['TEMPLATE']['DISK'] From fc4ec7b0f8438b46b382303b6da6ad9b850613a5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 11:42:15 +0100 Subject: [PATCH 11/16] 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) From f8c29aa1d63073b2e05dafbc89d2edcea9acfc09 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 11:55:57 +0100 Subject: [PATCH 12/16] add uuid() to opennebula VM --- .../opennebula/migrations/0002_vm_uuid.py | 19 +++++++++++++++++++ nicohack202002/uncloud/opennebula/models.py | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py diff --git a/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py b/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py new file mode 100644 index 0000000..595fd05 --- /dev/null +++ b/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.3 on 2020-02-23 10:55 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('opennebula', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='vm', + name='uuid', + field=models.UUIDField(default=uuid.uuid4, editable=False), + ), + ] diff --git a/nicohack202002/uncloud/opennebula/models.py b/nicohack202002/uncloud/opennebula/models.py index babba26..0f93b78 100644 --- a/nicohack202002/uncloud/opennebula/models.py +++ b/nicohack202002/uncloud/opennebula/models.py @@ -1,3 +1,4 @@ +import uuid from django.db import models from django.contrib.auth import get_user_model @@ -5,16 +6,20 @@ from django.contrib.postgres.fields import JSONField class VM(models.Model): vmid = models.IntegerField(primary_key=True) + uuid = models.UUIDField(default=uuid.uuid4, editable=False) owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) data = JSONField() + @property def cores(self): - return self.data['TEMPLATE']['VCPU'] + return int(self.data['TEMPLATE']['VCPU']) + @property def ram_in_gb(self): return (int(self.data['TEMPLATE']['MEMORY'])/1024.) + @property def disks(self): """ If there is no disk then the key DISK does not exist. From 1d1ae6fb3e113583f3926bd4f54306979497429f Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 11:59:09 +0100 Subject: [PATCH 13/16] Force uniqueness on uuid --- .../migrations/0003_auto_20200223_1058.py | 19 +++++++++++++++++++ nicohack202002/uncloud/opennebula/models.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 nicohack202002/uncloud/opennebula/migrations/0003_auto_20200223_1058.py diff --git a/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200223_1058.py b/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200223_1058.py new file mode 100644 index 0000000..d2173da --- /dev/null +++ b/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200223_1058.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.3 on 2020-02-23 10:58 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('opennebula', '0002_vm_uuid'), + ] + + operations = [ + migrations.AlterField( + model_name='vm', + name='uuid', + field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True), + ), + ] diff --git a/nicohack202002/uncloud/opennebula/models.py b/nicohack202002/uncloud/opennebula/models.py index 0f93b78..ff0e49c 100644 --- a/nicohack202002/uncloud/opennebula/models.py +++ b/nicohack202002/uncloud/opennebula/models.py @@ -6,7 +6,7 @@ from django.contrib.postgres.fields import JSONField class VM(models.Model): vmid = models.IntegerField(primary_key=True) - uuid = models.UUIDField(default=uuid.uuid4, editable=False) + uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) data = JSONField() From 94633d6cc8ec579573632d150294e5ccd3e7ba8b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 14:07:37 +0100 Subject: [PATCH 14/16] move uncloud a layer up Signed-off-by: Nico Schottelius --- README-penguinpay.md | 42 ---------------- README.md => meow-payv1/README.md | 0 config.py => meow-payv1/config.py | 0 hack-a-vpn.py => meow-payv1/hack-a-vpn.py | 0 helper.py => meow-payv1/helper.py | 0 ldaptest.py => meow-payv1/ldaptest.py | 0 .../products}/ipv6-only-django.json | 0 .../products}/ipv6-only-vm.json | 0 .../products}/ipv6-only-vpn.json | 0 .../products}/ipv6box.json | 0 .../products}/membership.json | 0 .../requirements.txt | 0 sample-pay.conf => meow-payv1/sample-pay.conf | 0 schemas.py => meow-payv1/schemas.py | 0 stripe_hack.py => meow-payv1/stripe_hack.py | 0 stripe_utils.py => meow-payv1/stripe_utils.py | 0 ucloud_pay.py => meow-payv1/ucloud_pay.py | 0 notes-nico.org | 49 +++++++++++++++++++ notes.org | 1 - plan.org | 6 --- .../uncloud => uncloud}/.gitignore | 0 {nicohack202002/uncloud => uncloud}/README.md | 0 {nicohack202002/uncloud => uncloud}/manage.py | 0 .../opennebula/__init__.py | 0 .../uncloud => uncloud}/opennebula/admin.py | 0 .../uncloud => uncloud}/opennebula/apps.py | 0 .../opennebula/management/commands/syncvm.py | 0 .../opennebula/migrations/0001_initial.py | 0 .../opennebula/migrations/0002_vm_uuid.py | 0 .../migrations/0003_auto_20200223_1058.py | 0 .../opennebula/migrations/__init__.py | 0 .../uncloud => uncloud}/opennebula/models.py | 2 +- .../opennebula/serializers.py | 0 .../uncloud => uncloud}/opennebula/tests.py | 0 .../uncloud => uncloud}/opennebula/views.py | 2 + .../uncloud => uncloud}/requirements.txt | 0 .../uncloud => uncloud}/uncloud/.gitignore | 0 .../uncloud => uncloud}/uncloud/__init__.py | 0 .../uncloud => uncloud}/uncloud/asgi.py | 0 .../uncloud/secrets_sample.py | 0 .../uncloud => uncloud}/uncloud/settings.py | 0 .../uncloud => uncloud}/uncloud/stripe.py | 0 .../uncloud => uncloud}/uncloud/urls.py | 0 .../uncloud => uncloud}/uncloud/wsgi.py | 0 .../uncloud_api/__init__.py | 0 .../uncloud => uncloud}/uncloud_api/admin.py | 0 .../uncloud => uncloud}/uncloud_api/apps.py | 0 .../uncloud_api/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../uncloud_api/management/commands/hack.py | 0 .../management/commands/snapshot.py | 0 .../uncloud_api/migrations/0001_initial.py | 0 .../uncloud_api/migrations/__init__.py | 0 .../uncloud => uncloud}/uncloud_api/models.py | 0 .../uncloud_api/serializers.py | 0 .../uncloud => uncloud}/uncloud_api/tests.py | 0 .../uncloud => uncloud}/uncloud_api/views.py | 0 .../uncloud_auth/__init__.py | 0 .../uncloud => uncloud}/uncloud_auth/admin.py | 0 .../uncloud => uncloud}/uncloud_auth/apps.py | 0 .../uncloud_auth/migrations/0001_initial.py | 0 .../uncloud_auth/migrations/__init__.py | 0 .../uncloud_auth/models.py | 0 uncloud/uncloud_vm/__init__.py | 0 uncloud/uncloud_vm/admin.py | 3 ++ uncloud/uncloud_vm/apps.py | 5 ++ uncloud/uncloud_vm/migrations/__init__.py | 0 uncloud/uncloud_vm/models.py | 12 +++++ uncloud/uncloud_vm/tests.py | 3 ++ uncloud/uncloud_vm/views.py | 24 +++++++++ 70 files changed, 99 insertions(+), 50 deletions(-) delete mode 100644 README-penguinpay.md rename README.md => meow-payv1/README.md (100%) rename config.py => meow-payv1/config.py (100%) rename hack-a-vpn.py => meow-payv1/hack-a-vpn.py (100%) rename helper.py => meow-payv1/helper.py (100%) rename ldaptest.py => meow-payv1/ldaptest.py (100%) rename {products => meow-payv1/products}/ipv6-only-django.json (100%) rename {products => meow-payv1/products}/ipv6-only-vm.json (100%) rename {products => meow-payv1/products}/ipv6-only-vpn.json (100%) rename {products => meow-payv1/products}/ipv6box.json (100%) rename {products => meow-payv1/products}/membership.json (100%) rename requirements.txt => meow-payv1/requirements.txt (100%) rename sample-pay.conf => meow-payv1/sample-pay.conf (100%) rename schemas.py => meow-payv1/schemas.py (100%) rename stripe_hack.py => meow-payv1/stripe_hack.py (100%) rename stripe_utils.py => meow-payv1/stripe_utils.py (100%) rename ucloud_pay.py => meow-payv1/ucloud_pay.py (100%) delete mode 100644 notes.org delete mode 100644 plan.org rename {nicohack202002/uncloud => uncloud}/.gitignore (100%) rename {nicohack202002/uncloud => uncloud}/README.md (100%) rename {nicohack202002/uncloud => uncloud}/manage.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/admin.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/apps.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/management/commands/syncvm.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/migrations/0001_initial.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/migrations/0002_vm_uuid.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/migrations/0003_auto_20200223_1058.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/migrations/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/models.py (98%) rename {nicohack202002/uncloud => uncloud}/opennebula/serializers.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/tests.py (100%) rename {nicohack202002/uncloud => uncloud}/opennebula/views.py (95%) rename {nicohack202002/uncloud => uncloud}/requirements.txt (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/.gitignore (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/asgi.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/secrets_sample.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/settings.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/stripe.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/urls.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud/wsgi.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/admin.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/apps.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/management/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/management/commands/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/management/commands/hack.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/management/commands/snapshot.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/migrations/0001_initial.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/migrations/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/models.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/serializers.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/tests.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_api/views.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_auth/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_auth/admin.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_auth/apps.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_auth/migrations/0001_initial.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_auth/migrations/__init__.py (100%) rename {nicohack202002/uncloud => uncloud}/uncloud_auth/models.py (100%) create mode 100644 uncloud/uncloud_vm/__init__.py create mode 100644 uncloud/uncloud_vm/admin.py create mode 100644 uncloud/uncloud_vm/apps.py create mode 100644 uncloud/uncloud_vm/migrations/__init__.py create mode 100644 uncloud/uncloud_vm/models.py create mode 100644 uncloud/uncloud_vm/tests.py create mode 100644 uncloud/uncloud_vm/views.py diff --git a/README-penguinpay.md b/README-penguinpay.md deleted file mode 100644 index 3229bc5..0000000 --- a/README-penguinpay.md +++ /dev/null @@ -1,42 +0,0 @@ -## How to place a order with penguin pay - -### Requirements - -* An ungleich account - can be registered for free on - https://account.ungleich.ch -* httpie installed (provides the http command) - -## Get a membership - - -## Registering a payment method - -To be able to pay for the membership, you will need to register a -credit card or apply for payment on bill (TO BE IMPLEMENTED). - -### Register credit card - -``` -http POST https://api.ungleich.ch/membership \ - username=nico password=yourpassword \ - cc_number=.. \ - cc_ - -``` - - - -### Request payment via bill - - - - -## Create the membership - - -``` -http POST https://api.ungleich.ch/membership username=nico password=yourpassword - -``` - -## List available products diff --git a/README.md b/meow-payv1/README.md similarity index 100% rename from README.md rename to meow-payv1/README.md diff --git a/config.py b/meow-payv1/config.py similarity index 100% rename from config.py rename to meow-payv1/config.py diff --git a/hack-a-vpn.py b/meow-payv1/hack-a-vpn.py similarity index 100% rename from hack-a-vpn.py rename to meow-payv1/hack-a-vpn.py diff --git a/helper.py b/meow-payv1/helper.py similarity index 100% rename from helper.py rename to meow-payv1/helper.py diff --git a/ldaptest.py b/meow-payv1/ldaptest.py similarity index 100% rename from ldaptest.py rename to meow-payv1/ldaptest.py diff --git a/products/ipv6-only-django.json b/meow-payv1/products/ipv6-only-django.json similarity index 100% rename from products/ipv6-only-django.json rename to meow-payv1/products/ipv6-only-django.json diff --git a/products/ipv6-only-vm.json b/meow-payv1/products/ipv6-only-vm.json similarity index 100% rename from products/ipv6-only-vm.json rename to meow-payv1/products/ipv6-only-vm.json diff --git a/products/ipv6-only-vpn.json b/meow-payv1/products/ipv6-only-vpn.json similarity index 100% rename from products/ipv6-only-vpn.json rename to meow-payv1/products/ipv6-only-vpn.json diff --git a/products/ipv6box.json b/meow-payv1/products/ipv6box.json similarity index 100% rename from products/ipv6box.json rename to meow-payv1/products/ipv6box.json diff --git a/products/membership.json b/meow-payv1/products/membership.json similarity index 100% rename from products/membership.json rename to meow-payv1/products/membership.json diff --git a/requirements.txt b/meow-payv1/requirements.txt similarity index 100% rename from requirements.txt rename to meow-payv1/requirements.txt diff --git a/sample-pay.conf b/meow-payv1/sample-pay.conf similarity index 100% rename from sample-pay.conf rename to meow-payv1/sample-pay.conf diff --git a/schemas.py b/meow-payv1/schemas.py similarity index 100% rename from schemas.py rename to meow-payv1/schemas.py diff --git a/stripe_hack.py b/meow-payv1/stripe_hack.py similarity index 100% rename from stripe_hack.py rename to meow-payv1/stripe_hack.py diff --git a/stripe_utils.py b/meow-payv1/stripe_utils.py similarity index 100% rename from stripe_utils.py rename to meow-payv1/stripe_utils.py diff --git a/ucloud_pay.py b/meow-payv1/ucloud_pay.py similarity index 100% rename from ucloud_pay.py rename to meow-payv1/ucloud_pay.py diff --git a/notes-nico.org b/notes-nico.org index 93e0c00..03c1b97 100644 --- a/notes-nico.org +++ b/notes-nico.org @@ -49,3 +49,52 @@ password=... * Django rest framework ** viewset: .list and .create ** view: .get .post +* TODO register CC +* TODO list products +* ahmed +** schemas +*** field: is_valid? - used by schemas +*** definition of a "schema" +* penguin pay +## How to place a order with penguin pay + +### Requirements + +* An ungleich account - can be registered for free on + https://account.ungleich.ch +* httpie installed (provides the http command) + +## Get a membership + + +## Registering a payment method + +To be able to pay for the membership, you will need to register a +credit card or apply for payment on bill (TO BE IMPLEMENTED). + +### Register credit card + +``` +http POST https://api.ungleich.ch/membership \ + username=nico password=yourpassword \ + cc_number=.. \ + cc_ + +``` + + + +### Request payment via bill + + + + +## Create the membership + + +``` +http POST https://api.ungleich.ch/membership username=nico password=yourpassword + +``` + +## List available products diff --git a/notes.org b/notes.org deleted file mode 100644 index 72e8ffc..0000000 --- a/notes.org +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/plan.org b/plan.org deleted file mode 100644 index 9f172c2..0000000 --- a/plan.org +++ /dev/null @@ -1,6 +0,0 @@ -* TODO register CC -* TODO list products -* ahmed -** schemas -*** field: is_valid? - used by schemas -*** definition of a "schema" diff --git a/nicohack202002/uncloud/.gitignore b/uncloud/.gitignore similarity index 100% rename from nicohack202002/uncloud/.gitignore rename to uncloud/.gitignore diff --git a/nicohack202002/uncloud/README.md b/uncloud/README.md similarity index 100% rename from nicohack202002/uncloud/README.md rename to uncloud/README.md diff --git a/nicohack202002/uncloud/manage.py b/uncloud/manage.py similarity index 100% rename from nicohack202002/uncloud/manage.py rename to uncloud/manage.py diff --git a/nicohack202002/uncloud/opennebula/__init__.py b/uncloud/opennebula/__init__.py similarity index 100% rename from nicohack202002/uncloud/opennebula/__init__.py rename to uncloud/opennebula/__init__.py diff --git a/nicohack202002/uncloud/opennebula/admin.py b/uncloud/opennebula/admin.py similarity index 100% rename from nicohack202002/uncloud/opennebula/admin.py rename to uncloud/opennebula/admin.py diff --git a/nicohack202002/uncloud/opennebula/apps.py b/uncloud/opennebula/apps.py similarity index 100% rename from nicohack202002/uncloud/opennebula/apps.py rename to uncloud/opennebula/apps.py diff --git a/nicohack202002/uncloud/opennebula/management/commands/syncvm.py b/uncloud/opennebula/management/commands/syncvm.py similarity index 100% rename from nicohack202002/uncloud/opennebula/management/commands/syncvm.py rename to uncloud/opennebula/management/commands/syncvm.py diff --git a/nicohack202002/uncloud/opennebula/migrations/0001_initial.py b/uncloud/opennebula/migrations/0001_initial.py similarity index 100% rename from nicohack202002/uncloud/opennebula/migrations/0001_initial.py rename to uncloud/opennebula/migrations/0001_initial.py diff --git a/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py b/uncloud/opennebula/migrations/0002_vm_uuid.py similarity index 100% rename from nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py rename to uncloud/opennebula/migrations/0002_vm_uuid.py diff --git a/nicohack202002/uncloud/opennebula/migrations/0003_auto_20200223_1058.py b/uncloud/opennebula/migrations/0003_auto_20200223_1058.py similarity index 100% rename from nicohack202002/uncloud/opennebula/migrations/0003_auto_20200223_1058.py rename to uncloud/opennebula/migrations/0003_auto_20200223_1058.py diff --git a/nicohack202002/uncloud/opennebula/migrations/__init__.py b/uncloud/opennebula/migrations/__init__.py similarity index 100% rename from nicohack202002/uncloud/opennebula/migrations/__init__.py rename to uncloud/opennebula/migrations/__init__.py diff --git a/nicohack202002/uncloud/opennebula/models.py b/uncloud/opennebula/models.py similarity index 98% rename from nicohack202002/uncloud/opennebula/models.py rename to uncloud/opennebula/models.py index ff0e49c..6dbc576 100644 --- a/nicohack202002/uncloud/opennebula/models.py +++ b/uncloud/opennebula/models.py @@ -15,7 +15,7 @@ class VM(models.Model): def cores(self): return int(self.data['TEMPLATE']['VCPU']) - @property + @propertyx def ram_in_gb(self): return (int(self.data['TEMPLATE']['MEMORY'])/1024.) diff --git a/nicohack202002/uncloud/opennebula/serializers.py b/uncloud/opennebula/serializers.py similarity index 100% rename from nicohack202002/uncloud/opennebula/serializers.py rename to uncloud/opennebula/serializers.py diff --git a/nicohack202002/uncloud/opennebula/tests.py b/uncloud/opennebula/tests.py similarity index 100% rename from nicohack202002/uncloud/opennebula/tests.py rename to uncloud/opennebula/tests.py diff --git a/nicohack202002/uncloud/opennebula/views.py b/uncloud/opennebula/views.py similarity index 95% rename from nicohack202002/uncloud/opennebula/views.py rename to uncloud/opennebula/views.py index f706815..7f2b537 100644 --- a/nicohack202002/uncloud/opennebula/views.py +++ b/uncloud/opennebula/views.py @@ -12,3 +12,5 @@ class VMDetail(generics.RetrieveAPIView): lookup_field = 'vmid' queryset = VM.objects.all() serializer_class = VMSerializer + +class VMViewSet( diff --git a/nicohack202002/uncloud/requirements.txt b/uncloud/requirements.txt similarity index 100% rename from nicohack202002/uncloud/requirements.txt rename to uncloud/requirements.txt diff --git a/nicohack202002/uncloud/uncloud/.gitignore b/uncloud/uncloud/.gitignore similarity index 100% rename from nicohack202002/uncloud/uncloud/.gitignore rename to uncloud/uncloud/.gitignore diff --git a/nicohack202002/uncloud/uncloud/__init__.py b/uncloud/uncloud/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud/__init__.py rename to uncloud/uncloud/__init__.py diff --git a/nicohack202002/uncloud/uncloud/asgi.py b/uncloud/uncloud/asgi.py similarity index 100% rename from nicohack202002/uncloud/uncloud/asgi.py rename to uncloud/uncloud/asgi.py diff --git a/nicohack202002/uncloud/uncloud/secrets_sample.py b/uncloud/uncloud/secrets_sample.py similarity index 100% rename from nicohack202002/uncloud/uncloud/secrets_sample.py rename to uncloud/uncloud/secrets_sample.py diff --git a/nicohack202002/uncloud/uncloud/settings.py b/uncloud/uncloud/settings.py similarity index 100% rename from nicohack202002/uncloud/uncloud/settings.py rename to uncloud/uncloud/settings.py diff --git a/nicohack202002/uncloud/uncloud/stripe.py b/uncloud/uncloud/stripe.py similarity index 100% rename from nicohack202002/uncloud/uncloud/stripe.py rename to uncloud/uncloud/stripe.py diff --git a/nicohack202002/uncloud/uncloud/urls.py b/uncloud/uncloud/urls.py similarity index 100% rename from nicohack202002/uncloud/uncloud/urls.py rename to uncloud/uncloud/urls.py diff --git a/nicohack202002/uncloud/uncloud/wsgi.py b/uncloud/uncloud/wsgi.py similarity index 100% rename from nicohack202002/uncloud/uncloud/wsgi.py rename to uncloud/uncloud/wsgi.py diff --git a/nicohack202002/uncloud/uncloud_api/__init__.py b/uncloud/uncloud_api/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/__init__.py rename to uncloud/uncloud_api/__init__.py diff --git a/nicohack202002/uncloud/uncloud_api/admin.py b/uncloud/uncloud_api/admin.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/admin.py rename to uncloud/uncloud_api/admin.py diff --git a/nicohack202002/uncloud/uncloud_api/apps.py b/uncloud/uncloud_api/apps.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/apps.py rename to uncloud/uncloud_api/apps.py diff --git a/nicohack202002/uncloud/uncloud_api/management/__init__.py b/uncloud/uncloud_api/management/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/management/__init__.py rename to uncloud/uncloud_api/management/__init__.py diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/__init__.py b/uncloud/uncloud_api/management/commands/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/management/commands/__init__.py rename to uncloud/uncloud_api/management/commands/__init__.py diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/hack.py b/uncloud/uncloud_api/management/commands/hack.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/management/commands/hack.py rename to uncloud/uncloud_api/management/commands/hack.py diff --git a/nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py b/uncloud/uncloud_api/management/commands/snapshot.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/management/commands/snapshot.py rename to uncloud/uncloud_api/management/commands/snapshot.py diff --git a/nicohack202002/uncloud/uncloud_api/migrations/0001_initial.py b/uncloud/uncloud_api/migrations/0001_initial.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/migrations/0001_initial.py rename to uncloud/uncloud_api/migrations/0001_initial.py diff --git a/nicohack202002/uncloud/uncloud_api/migrations/__init__.py b/uncloud/uncloud_api/migrations/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/migrations/__init__.py rename to uncloud/uncloud_api/migrations/__init__.py diff --git a/nicohack202002/uncloud/uncloud_api/models.py b/uncloud/uncloud_api/models.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/models.py rename to uncloud/uncloud_api/models.py diff --git a/nicohack202002/uncloud/uncloud_api/serializers.py b/uncloud/uncloud_api/serializers.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/serializers.py rename to uncloud/uncloud_api/serializers.py diff --git a/nicohack202002/uncloud/uncloud_api/tests.py b/uncloud/uncloud_api/tests.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/tests.py rename to uncloud/uncloud_api/tests.py diff --git a/nicohack202002/uncloud/uncloud_api/views.py b/uncloud/uncloud_api/views.py similarity index 100% rename from nicohack202002/uncloud/uncloud_api/views.py rename to uncloud/uncloud_api/views.py diff --git a/nicohack202002/uncloud/uncloud_auth/__init__.py b/uncloud/uncloud_auth/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud_auth/__init__.py rename to uncloud/uncloud_auth/__init__.py diff --git a/nicohack202002/uncloud/uncloud_auth/admin.py b/uncloud/uncloud_auth/admin.py similarity index 100% rename from nicohack202002/uncloud/uncloud_auth/admin.py rename to uncloud/uncloud_auth/admin.py diff --git a/nicohack202002/uncloud/uncloud_auth/apps.py b/uncloud/uncloud_auth/apps.py similarity index 100% rename from nicohack202002/uncloud/uncloud_auth/apps.py rename to uncloud/uncloud_auth/apps.py diff --git a/nicohack202002/uncloud/uncloud_auth/migrations/0001_initial.py b/uncloud/uncloud_auth/migrations/0001_initial.py similarity index 100% rename from nicohack202002/uncloud/uncloud_auth/migrations/0001_initial.py rename to uncloud/uncloud_auth/migrations/0001_initial.py diff --git a/nicohack202002/uncloud/uncloud_auth/migrations/__init__.py b/uncloud/uncloud_auth/migrations/__init__.py similarity index 100% rename from nicohack202002/uncloud/uncloud_auth/migrations/__init__.py rename to uncloud/uncloud_auth/migrations/__init__.py diff --git a/nicohack202002/uncloud/uncloud_auth/models.py b/uncloud/uncloud_auth/models.py similarity index 100% rename from nicohack202002/uncloud/uncloud_auth/models.py rename to uncloud/uncloud_auth/models.py diff --git a/uncloud/uncloud_vm/__init__.py b/uncloud/uncloud_vm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/uncloud_vm/admin.py b/uncloud/uncloud_vm/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/uncloud/uncloud_vm/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/uncloud/uncloud_vm/apps.py b/uncloud/uncloud_vm/apps.py new file mode 100644 index 0000000..c5e94a5 --- /dev/null +++ b/uncloud/uncloud_vm/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UncloudVmConfig(AppConfig): + name = 'uncloud_vm' diff --git a/uncloud/uncloud_vm/migrations/__init__.py b/uncloud/uncloud_vm/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uncloud/uncloud_vm/models.py b/uncloud/uncloud_vm/models.py new file mode 100644 index 0000000..b1aab40 --- /dev/null +++ b/uncloud/uncloud_vm/models.py @@ -0,0 +1,12 @@ +from django.db import models + + +class VM(models.Model): + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) + + cores = models.IntegerField() + ram = models.FloatField() + + +class VMDisk(models.Model): diff --git a/uncloud/uncloud_vm/tests.py b/uncloud/uncloud_vm/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/uncloud/uncloud_vm/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/uncloud/uncloud_vm/views.py b/uncloud/uncloud_vm/views.py new file mode 100644 index 0000000..aa5855c --- /dev/null +++ b/uncloud/uncloud_vm/views.py @@ -0,0 +1,24 @@ +from django.shortcuts import render + + +from django.contrib.auth.models import User +from django.shortcuts import get_object_or_404 +from myapps.serializers import UserSerializer +from rest_framework import viewsets +from rest_framework.response import Response + +from opennebula.models import VM as OpenNebulaVM + +class VMViewSet(viewsets.ViewSet): + def list(self, request): + queryset = User.objects.all() + serializer = UserSerializer(queryset, many=True) + return Response(serializer.data) + + def retrieve(self, request, pk=None): + queryset = User.objects.all() + user = get_object_or_404(queryset, pk=pk) + serializer = UserSerializer(user) + return Response(serializer.data) + + permission_classes = [permissions.IsAuthenticated] From cee45b5227c6c0067c633e3ee8075f61a67ec59a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 15:09:58 +0100 Subject: [PATCH 15/16] -typo --- uncloud/opennebula/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uncloud/opennebula/models.py b/uncloud/opennebula/models.py index 6dbc576..ff0e49c 100644 --- a/uncloud/opennebula/models.py +++ b/uncloud/opennebula/models.py @@ -15,7 +15,7 @@ class VM(models.Model): def cores(self): return int(self.data['TEMPLATE']['VCPU']) - @propertyx + @property def ram_in_gb(self): return (int(self.data['TEMPLATE']['MEMORY'])/1024.) From e2b5b5d102aa64736833148ddc670d837404fd6d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 23 Feb 2020 15:33:26 +0100 Subject: [PATCH 16/16] opennebula -> router --- uncloud/opennebula/models.py | 25 +++++++++++++++++++------ uncloud/opennebula/serializers.py | 6 ++++++ uncloud/opennebula/views.py | 20 +++++++++++++------- uncloud/uncloud/urls.py | 8 +++++--- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/uncloud/opennebula/models.py b/uncloud/opennebula/models.py index ff0e49c..0b0f307 100644 --- a/uncloud/opennebula/models.py +++ b/uncloud/opennebula/models.py @@ -29,9 +29,22 @@ class VM(models.Model): If there are multiple disks, we have a list of dictionaries in the database. """ - if not 'DISK' in self.data['TEMPLATE']['DISK']: - return [] - elif type(self.data['TEMPLATE']['DISK']) is dict: - return [ self.data['TEMPLATE']['DISK'] ] - else: - return self.data['TEMPLATE']['DISK'] + disks = [] + + if 'DISK' in self.data['TEMPLATE']: + + if type(self.data['TEMPLATE']['DISK']) is dict: + disks = [ self.data['TEMPLATE']['DISK'] ] + else: + disks = self.data['TEMPLATE']['DISK'] + + disks = [ + { + 'size_in_gb': int(d['SIZE'])/1024. , + 'opennebula_source': d['SOURCE'], + 'opennebula_name': d['IMAGE'], + } + for d in disks + ] + + return disks diff --git a/uncloud/opennebula/serializers.py b/uncloud/opennebula/serializers.py index c84f2ab..30bd20a 100644 --- a/uncloud/opennebula/serializers.py +++ b/uncloud/opennebula/serializers.py @@ -6,3 +6,9 @@ class VMSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = VM fields = ['vmid', 'owner', 'data'] + + +class OpenNebulaVMSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = VM + fields = ['vmid', 'owner', 'cores', 'ram_in_gb', 'disks' ] diff --git a/uncloud/opennebula/views.py b/uncloud/opennebula/views.py index 7f2b537..5505b32 100644 --- a/uncloud/opennebula/views.py +++ b/uncloud/opennebula/views.py @@ -1,16 +1,22 @@ -from rest_framework import viewsets, generics +from rest_framework import viewsets, generics, permissions from .models import VM -from .serializers import VMSerializer +from .serializers import VMSerializer, OpenNebulaVMSerializer -class VMList(generics.ListAPIView): +#class VMList(generics.ListAPIView): +# queryset = VM.objects.all() +# serializer_class = VMSerializer + + +class RawVMViewSet(viewsets.ModelViewSet): +# lookup_field = 'vmid' queryset = VM.objects.all() serializer_class = VMSerializer + permission_classes = [permissions.IsAuthenticated] -class VMDetail(generics.RetrieveAPIView): - lookup_field = 'vmid' +class VMViewSet(viewsets.ModelViewSet): queryset = VM.objects.all() - serializer_class = VMSerializer + serializer_class = OpenNebulaVMSerializer -class VMViewSet( + permission_classes = [permissions.IsAuthenticated] diff --git a/uncloud/uncloud/urls.py b/uncloud/uncloud/urls.py index c7ce9b6..0291b7f 100644 --- a/uncloud/uncloud/urls.py +++ b/uncloud/uncloud/urls.py @@ -24,6 +24,8 @@ from opennebula import views as oneviews router = routers.DefaultRouter() router.register(r'users', views.UserViewSet) router.register(r'groups', views.GroupViewSet) +router.register(r'opennebula', oneviews.VMViewSet) +router.register(r'opennebula_raw', oneviews.RawVMViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. @@ -31,8 +33,8 @@ urlpatterns = [ path('', include(router.urls)), path('admin/', admin.site.urls), path('products/', views.ProductsView.as_view(), name='products'), - path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), - path('vm/list/', oneviews.VMList.as_view(), name='vm_list'), - path('vm/detail//', oneviews.VMDetail.as_view(), name='vm_detail'), + path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) +# path('vm/list/', oneviews.VMList.as_view(), name='vm_list'), +# path('vm/detail//', oneviews.VMDetail.as_view(), name='vm_detail'), ]