class K8s(Base): id = fields.Integer() size = fields.Integer() network_id = fields.String(default="") ipaddress = fields.IPAddress() cluster_secret = fields.String(default="") master_ips = fields.List(fields.IPAddress()) ssh_keys = fields.List(fields.String()) public_ip = fields.Integer() stats_aggregator = fields.List(fields.Object(Statsaggregator)) info = fields.Object(ReservationInfo) datastore_endpoint = fields.String(default="") disable_default_ingress = fields.Boolean(default=True) SIZES = VMSIZES def resource_units(self): resource_units = ResourceUnitAmount() size = VMSIZES.get(self.size) if not size: raise j.exceptions.Input(f"kubernetes size {self.size} not supported") resource_units.cru += size["cru"] resource_units.mru += size["mru"] resource_units.sru += size["sru"] return resource_units
class Network(Base): name = fields.String(default="") workload_id = fields.Integer() iprange = fields.IPRange(default="10.10.0.0/16") stats_aggregator = fields.List(fields.Object(Statsaggregator)) network_resources = fields.List(fields.Object(NetworkResource)) farmer_tid = fields.Integer()
class PoolCreateData(Base): pool_id = fields.Integer() cus = fields.Integer() sus = fields.Integer() ipv4us = fields.Integer() node_ids = fields.List(fields.String()) currencies = fields.List(fields.String())
class VirtualMachine(Base): id = fields.Integer() name = fields.String(default="") hub_url = fields.String(default="") description = fields.String(default="") network_connection = fields.List(fields.Object(ContainerNetworkConnection)) network_id = fields.String() farmer_tid = fields.Integer() size = fields.Integer() info = fields.Object(ReservationInfo) ssh_keys = fields.List(fields.String()) public_ip = fields.Integer() ipaddress = fields.IPAddress() SIZES = VMSIZES def resource_units(self): resource_units = ResourceUnitAmount() size = VMSIZES.get(self.size) if not size: raise j.exceptions.Input(f"VM size {self.size} not supported") resource_units.cru += size["cru"] resource_units.mru += size["mru"] resource_units.sru += size["sru"] return resource_units
class Container(Base): id = fields.Integer() flist = fields.String(default="") hub_url = fields.String(default="") storage_url = fields.String(default="") environment = fields.Typed(dict) secret_environment = fields.Typed(dict) entrypoint = fields.String(default="") interactive = fields.Boolean(default=True) volumes = fields.List(fields.Object(ContainerMount)) network_connection = fields.List(fields.Object(ContainerNetworkConnection)) stats = fields.List(fields.Object(ContainerStats)) farmer_tid = fields.Integer() logs = fields.List(fields.Object(ContainerLogs)) capacity = fields.Object(ContainerCapacity) info = fields.Object(ReservationInfo) def resource_units(self): cap = self.capacity resource_units = ResourceUnitAmount() resource_units.cru = cap.cpu resource_units.mru = round(cap.memory / 1024 * 10000) / 10000 storage_size = round(cap.disk_size / 1024 * 10000) / 10000 storage_size = max(0, storage_size - 50) # we offer the 50 first GB of storage for container root filesystem if cap.disk_type == DiskType.HDD: resource_units.hru += storage_size elif cap.disk_type == DiskType.SSD: resource_units.sru += storage_size return resource_units
class User(Base): emails = fields.List(fields.String()) permissions = fields.List(fields.Object(Permission)) custom_config = fields.Typed(dict) type = fields.Enum(UserType) password = fields.Secret() first_name = fields.String(default="") last_name = fields.String(default="") def get_full_name(self): name = self.first_name if self.last_name: name += " " + self.last_name return name def get_unique_name(self): return self.full_name.replace(" ", "") + ".user" full_name = fields.String(compute=get_full_name) unique_name = fields.String(compute=get_unique_name) def get_my_greeter(self): return Greeter(self.full_name) my_greeter = fields.Typed(Greeter, stored=False, compute=get_my_greeter) ahmed_greeter = fields.Typed(Greeter, stored=False, default=Greeter("ahmed"))
class K8s(Base): id = fields.Integer() size = fields.Integer() network_id = fields.String(default="") ipaddress = fields.IPAddress() cluster_secret = fields.String(default="") master_ips = fields.List(fields.IPAddress()) ssh_keys = fields.List(fields.String()) stats_aggregator = fields.List(fields.Object(Statsaggregator)) info = fields.Object(ReservationInfo)
class User(Base): user_code = fields.String(default="") poll_name = fields.String(default="") wallets_addresses = fields.List(fields.String()) transaction_hashes = fields.List(fields.String()) tokens = fields.Float(default=0.0) vote_data = fields.Typed(dict, default={}) extra_data = fields.Typed(dict, default={}) vote_data_weighted = fields.Typed(dict, default={}) has_voted = fields.Boolean(default=False) manifesto_version = fields.String(default="2.0.0")
class Pool(Base): pool_id = fields.Integer() cus = fields.Float() sus = fields.Float() node_ids = fields.List(fields.String()) last_updated = fields.DateTime() active_cu = fields.Float() active_su = fields.Float() empty_at = fields.Integer() # can't be set to date because of max int64 value customer_tid = fields.Integer() active_workload_ids = fields.List(fields.Integer())
class Farm(Base): id = fields.Integer() threebot_id = fields.Integer() iyo_organization = fields.String(default="") name = fields.String(default="") wallet_addresses = fields.List(fields.Object(WalletAddress)) location = fields.Object(Location) email = fields.Email() resource_prices = fields.List(fields.Object(ResourceUnitPrice)) prefix_zero = fields.IPRange() def __str__(self): return " - ".join([x for x in [self.name, str(self.location)] if x])
class Reservation(Base): id = fields.Integer() json = fields.String(default="") data_reservation = fields.Object(ReservationData) customer_tid = fields.Integer() customer_signature = fields.String(default="") next_action = fields.Enum(NextAction) signatures_provision = fields.List(fields.Object(Signature)) signatures_farmer = fields.List(fields.Object(Signature)) signatures_delete = fields.List(fields.Object(Signature)) epoch = fields.DateTime(default=datetime.utcnow) metadata = fields.String(default="") results = fields.List(fields.Object(ReservationResult))
class Gateway(Base): node_id = fields.String(default="") os_version = fields.String(default="") farm_id = fields.Integer() created = fields.DateTime() updated = fields.DateTime() uptime = fields.Integer() address = fields.String(default="") location = fields.Object(Location) public_key_hex = fields.String(default="") workloads = fields.Object(WorkloadsAmount) managed_domains = fields.List(fields.String()) tcp_router_port = fields.Integer() dns_nameserver = fields.List(fields.String()) free_to_use = fields.Boolean()
class HardwareProof(Base): created = fields.DateTime() hardware_hash = fields.String(default="") disk_hash = fields.String(default="") hardware = fields.Typed(dict) disks = fields.Typed(dict) hypervisor = fields.List(fields.String())
class Container(Base): id = fields.Integer() flist = fields.String(default="") hub_url = fields.String(default="") storage_url = fields.String(default="") environment = fields.Typed(dict) secret_environment = fields.Typed(dict) entrypoint = fields.String(default="") interactive = fields.Boolean(default=True) volumes = fields.List(fields.Object(ContainerMount)) network_connection = fields.List(fields.Object(ContainerNetworkConnection)) stats_aggregator = fields.List(fields.Object(Statsaggregator)) farmer_tid = fields.Integer() logs = fields.List(fields.Object(ContainerLogs)) capacity = fields.Object(ContainerCapacity) info = fields.Object(ReservationInfo)
class Farm(Base): id = fields.Integer() threebot_id = fields.Integer() iyo_organization = fields.String(default="") name = fields.String(default="") wallet_addresses = fields.List(fields.Object(WalletAddress)) location = fields.Object(Location) email = fields.Email() resource_prices = fields.List(fields.Object(ResourceUnitPrice)) prefix_zero = fields.IPRange() ipaddresses = fields.List(fields.Object(FarmerIP)) enable_custom_pricing = fields.Boolean(default=False) farm_cloudunits_price = fields.Object(CloudUnitMonthPrice) is_grid3_compliant = fields.Boolean(default=False) def __str__(self): return " - ".join([x for x in [self.name, str(self.location)] if x])
class GatewaySubdomain(Base): id = fields.Integer() domain = fields.String(default="") ips = fields.List(fields.String()) info = fields.Object(ReservationInfo) def resource_units(self): return ResourceUnitAmount()
class ReservationInfo(Base): workload_id = fields.Integer() node_id = fields.String() pool_id = fields.Integer() description = fields.String(default="") reference = fields.String(default="") customer_tid = fields.Integer() customer_signature = fields.String() next_action = fields.Enum(NextAction) signatures_provision = fields.List(fields.Object(Signature)) signing_request_provision = fields.Object(SigningRequest) signing_request_delete = fields.Object(SigningRequest) signatures_farmer = fields.List(fields.Object(Signature)) signatures_delete = fields.List(fields.Object(Signature)) epoch = fields.DateTime(default=datetime.utcnow) metadata = fields.String(default="") result = fields.Object(ReservationResult) workload_type = fields.Enum(WorkloadType)
class K8s(Base): id = fields.Integer() size = fields.Integer() network_id = fields.String(default="") ipaddress = fields.IPAddress() cluster_secret = fields.String(default="") master_ips = fields.List(fields.IPAddress()) ssh_keys = fields.List(fields.String()) public_ip = fields.Integer() stats_aggregator = fields.List(fields.Object(Statsaggregator)) info = fields.Object(ReservationInfo) def resource_units(self): size_table = { 1: {"cru": 1, "mru": 2, "sru": 50}, 2: {"cru": 2, "mru": 4, "sru": 100}, 3: {"cru": 2, "mru": 8, "sru": 25}, 4: {"cru": 2, "mru": 5, "sru": 50}, 5: {"cru": 2, "mru": 8, "sru": 200}, 6: {"cru": 4, "mru": 16, "sru": 50}, 7: {"cru": 4, "mru": 16, "sru": 100}, 8: {"cru": 4, "mru": 16, "sru": 400}, 9: {"cru": 8, "mru": 32, "sru": 100}, 10: {"cru": 8, "mru": 32, "sru": 200}, 11: {"cru": 8, "mru": 32, "sru": 800}, 12: {"cru": 16, "mru": 64, "sru": 200}, 13: {"cru": 16, "mru": 64, "sru": 400}, 14: {"cru": 16, "mru": 64, "sru": 800}, 15: {"cru": 1, "mru": 2, "sru": 25}, 16: {"cru": 2, "mru": 4, "sru": 50}, 17: {"cru": 4, "mru": 8, "sru": 50}, 18: {"cru": 1, "mru": 1, "sru": 25}, } resource_units = ResourceUnitAmount() size = size_table.get(self.size) if not size: raise j.exceptions.Input(f"kubernetes size {self.size} not supported") resource_units.cru += size["cru"] resource_units.mru += size["mru"] resource_units.sru += size["sru"] return resource_units
class NetworkResource(Base): id = fields.Integer() name = fields.String(default="") network_iprange = fields.IPRange(default="10.10.0.0/16") wireguard_private_key_encrypted = fields.String(default="") wireguard_public_key = fields.String(default="") wireguard_listen_port = fields.Integer() iprange = fields.IPRange(default="10.10.10.0/24") peers = fields.List(fields.Object(WireguardPeer)) info = fields.Object(ReservationInfo)
class ZdbNamespace(Base): id = fields.Integer() node_id = fields.String(default="") size = fields.Integer() mode = fields.Enum(ZDBMode) password = fields.String(default="") disk_type = fields.Enum(DiskType) public = fields.Boolean(default=False) stats_aggregator = fields.List(fields.Object(Statsaggregator)) info = fields.Object(ReservationInfo)
class User(Base): id = fields.Integer() first_name = fields.String(default="") last_name = fields.String(default="") emails = fields.List(fields.String()) permissions = fields.List(fields.Object(Permission)) custom_config = fields.Typed(dict) rating = fields.Float() time = fields.DateTime(default=datetime.datetime.now) def get_full_name(self): name = self.first_name if self.last_name: name += " " + self.last_name return name def get_unique_name(self): return self.full_name.replace(" ", "") + ".user" full_name = fields.String(compute=get_full_name) unique_name = fields.String(compute=get_unique_name)
class Node(Base): node_id = fields.String(default="") node_id_v1 = fields.String(default="") farm_id = fields.Integer() os_version = fields.String(default="") created = fields.DateTime() updated = fields.DateTime() uptime = fields.Integer() address = fields.String(default="") location = fields.Object(Location) total_resources = fields.Object(ResourceUnitAmount) used_resources = fields.Object(ResourceUnitAmount) reserved_resources = fields.Object(ResourceUnitAmount) workloads = fields.Object(WorkloadsAmount) proofs = fields.List(fields.Object(HardwareProof)) ifaces = fields.List(fields.Object(NodeIface)) public_config = fields.Object(NodePublicIface) exit_node = fields.Boolean() approved = fields.Boolean(default=False) public_key_hex = fields.String(default="") wg_ports = fields.List(fields.Integer()) free_to_use = fields.Boolean()
class Volume(Base): id = fields.Integer() size = fields.Integer() type = fields.Enum(DiskType) stats_aggregator = fields.List(fields.Object(Statsaggregator)) info = fields.Object(ReservationInfo) def resource_units(self): resource_units = ResourceUnitAmount() if self.type == DiskType.HDD: resource_units.hru += self.size elif self.type == DiskType.SSD: resource_units.sru += self.size return resource_units
class ZdbNamespace(Base): id = fields.Integer() node_id = fields.String(default="") size = fields.Integer() mode = fields.Enum(ZDBMode) password = fields.String(default="") disk_type = fields.Enum(DiskType) public = fields.Boolean(default=False) stats_aggregator = fields.List(fields.Object(Statsaggregator)) info = fields.Object(ReservationInfo) def resource_units(self): resource_units = ResourceUnitAmount() if self.disk_type == DiskType.HDD: resource_units.hru += self.size elif self.disk_type == DiskType.SSD: resource_units.sru += self.size return resource_units
class PaymentResult(Base): success = fields.Boolean(default=False) extra_paid = fields.Boolean(default=False) transactions = fields.List(fields.Object(PaymentTransaction)) def refund_extra(self): if self.extra_paid and self.parent.refund_extra: for transaction in self.transactions: if transaction.success: trans_amount = transaction.get_amount(self.parent.wallet) diff = float(trans_amount) - self.parent.amount if diff <= TRANSACTION_FEES: self.extra_paid = False break sender_address = self.parent.wallet.get_sender_wallet_address( transaction.transaction_hash) amount = round(diff - TRANSACTION_FEES, 6) try: j.logger.info( f"refunding extra amount: {amount} of transaction {transaction.transaction_hash} to address: {sender_address}" ) a = self.parent.wallet._get_asset() refund_hash = self.parent.wallet.transfer( sender_address, amount=amount, asset=f"{a.code}:{a.issuer}") self.extra_paid = False j.logger.info( f"extra amount: {amount} of transaction {transaction.transaction_hash} refunded successfully in transaction: {refund_hash} to address: {sender_address}" ) except Exception as e: j.logger.critical( f"failed to refund extra amount {amount} for payment: {self.parent.payment_id} due to error: {str(e)}" ) self.parent.save() return self.extra_paid
class S3(Base): minio = fields.Object(S3Container) zdbs = fields.List(fields.Object(S3ZDB)) domain = fields.String() domain_wid = fields.Integer()
class SigningRequest(Base): signers = fields.List(fields.Integer()) quorum_min = fields.Integer()
class Escrow(Base): address = fields.String(default="") asset = fields.String(default="") details = fields.List(fields.Object(EscrowDetail))
class WireguardPeer(Base): public_key = fields.String(default="") allowed_iprange = fields.List(fields.IPRange()) endpoint = fields.String(default="") iprange = fields.IPRange(default="10.10.11.0/24")
class ReservationData(Base): description = fields.String(default="") signing_request_provision = fields.Object(SigningRequest) signing_request_delete = fields.Object(SigningRequest) containers = fields.List(fields.Object(Container)) volumes = fields.List(fields.Object(Volume)) zdbs = fields.List(fields.Object(ZdbNamespace)) networks = fields.List(fields.Object(Network)) kubernetes = fields.List(fields.Object(K8s)) proxies = fields.List(fields.Object(GatewayProxy)) reverse_proxies = fields.List(fields.Object(GatewayReverseProxy)) subdomains = fields.List(fields.Object(GatewaySubdomain)) domain_delegates = fields.List(fields.Object(GatewayDelegate)) gateway4to6 = fields.List(fields.Object(Gateway4to6)) expiration_provisioning = fields.DateTime() expiration_reservation = fields.DateTime() currencies = fields.List(fields.String())