forked from uncloud/uncloud
80 lines
2.2 KiB
Python
Executable file
80 lines
2.2 KiB
Python
Executable file
#!/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 <http://www.gnu.org/licenses/>.
|
|
|
|
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
|