diff --git a/uncloud/hack/main.py b/uncloud/hack/main.py index 391a5e4..b4717fd 100644 --- a/uncloud/hack/main.py +++ b/uncloud/hack/main.py @@ -55,6 +55,8 @@ def authenticate(username, password, totp_token=None): server = ldap3.Server("ldaps://ldap1.ungleich.ch") dn = "uid={},ou=customer,dc=ungleich,dc=ch".format(username) + log.debug("LDAP: connecting to {} as {}".format(server, dn)) + try: conn = ldap3.Connection(server, dn, password, auto_bind=True) except ldap3.core.exceptions.LDAPBindError as e: @@ -72,12 +74,12 @@ def order(config): if not config.arguments[required_arg]: raise UncloudException("Missing required argument: {}".format(required_arg)) - print(config.arguments) + log.debug(config.arguments) authenticate(config.arguments['username'], config.arguments['password']) # create DB entry for VM vm = VM(config) - vm.schedule() + vm.product.place_order() diff --git a/uncloud/hack/product.py b/uncloud/hack/product.py new file mode 100755 index 0000000..73f140a --- /dev/null +++ b/uncloud/hack/product.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# 2020 Nico Schottelius (nico.schottelius at ungleich.ch) +# +# This file is part of uncloud. +# +# uncloud is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# uncloud is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with uncloud. If not, see . + +import json +import uuid + +from uncloud import UncloudException +from uncloud.hack.db import DB + +# states + + +class Product(object): + def __init__(self, config, product_name, db_entry=None): + self.config = config + self.db = DB(self.config, prefix="/orders") + + self.db_entry = {} + self.db_entry["product_name"] = product_name + self.db_entry["db_version"] = 1 + + # Existing product? Read in db_entry + if db_entry: + self.db_entry = db_entry + + + @staticmethod + def define_feature(self, + name, + feature, + one_time_price, + recurring_price, + recurring_period, + minimum_period): + feature = {} + feature[name] = {} + + def valid_status(self): + if "status" in self.db_entry: + if self.db_entry["status"] in [ "NEW", "CREATED", "DELETED" ]: + return False + return True + + def validate_product(self): + if not "uuid" in self.db_entry: + self.db_entry["uuid"] = str(uuid.uuid4()) + if not "status" in self.db_entry: + self.db_entry["status"] = "NEW" + + def place_order(self): + """ Schedule creating the product in etcd """ + self.validate_product() + + # FIXME: very status + if not self.db_entry["status"] == "NEW": + raise UncloudException("Cannot re-order product") + + + + + + def __str__(self): + return self.features diff --git a/uncloud/hack/vm.py b/uncloud/hack/vm.py index b38d563..695e33b 100755 --- a/uncloud/hack/vm.py +++ b/uncloud/hack/vm.py @@ -41,6 +41,7 @@ import logging from uncloud.hack.db import DB from uncloud.hack.mac import MAC from uncloud.vmm import VMM +from uncloud.hack.product import Product log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) @@ -71,11 +72,15 @@ class VM(object): self.image_format='qcow2' # External components. - self.vmm = VMM(vmm_backend=self.hackprefix) + + # This one is broken: + # TypeError: expected str, bytes or os.PathLike object, not NoneType + # Fix before re-enabling + # self.vmm = VMM(vmm_backend=self.hackprefix) self.mac = MAC(self.config) # Harcoded & generated values. - self.owner = 'uncoud' + self.owner = 'uncloud' self.accel = 'kvm' self.threads = 1 self.ifup = os.path.join(self.hackprefix, "ifup.sh") @@ -84,6 +89,12 @@ class VM(object): self.vm = {} + self.product = Product(config, product_name="dualstack-vm") + + self.features = [] +# self.features.append(self.define_feature( +# self.super().__init__( + def get_qemu_args(self): command = ( "-name {owner}-{name}" @@ -104,6 +115,9 @@ class VM(object): return command.split(" ") + def create_db_entry(self): + pass + def create(self): # New VM: new UUID, new MAC. self.uuid = str(uuid.uuid4())