Move django-based uncloud to top-level
This commit is contained in:
parent
0560063326
commit
95d43f002f
265 changed files with 0 additions and 0 deletions
55
archive/uncloud_django_based/hacks/abk-hacks.py
Normal file
55
archive/uncloud_django_based/hacks/abk-hacks.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""
|
||||
investigate into a simple python function that maps an ldap user to a vat percentage. Basically you need to
|
||||
lookup the customer address, check if she is a business/registered tax number and if not apply the local
|
||||
vat
|
||||
"""
|
||||
|
||||
import iso3166
|
||||
import datetime
|
||||
|
||||
from csv import DictReader
|
||||
|
||||
|
||||
def get_vat(street_address, city, postal_code, country, vat_number=None):
|
||||
vat = {
|
||||
'Austria': [
|
||||
{'period': '1984-01-01/', 'rate': 0.2},
|
||||
{'period': '1976-01-01/1984-01-01', 'rate': 0.18},
|
||||
{'period': '1973-01-01/1976-01-01', 'rate': 0.16},
|
||||
]
|
||||
}
|
||||
return iso3166.countries.get(country)
|
||||
|
||||
# return iso3166.countries_by_name[country]
|
||||
|
||||
|
||||
def main():
|
||||
# vat = get_vat(
|
||||
# street_address='82 Nasheman-e-Iqbal near Wapda Town',
|
||||
# city='Lahore',
|
||||
# postal_code=53700,
|
||||
# country='Pakistan',
|
||||
# )
|
||||
# print(vat)
|
||||
vat_rates = {}
|
||||
with open('vat_rates.csv', newline='') as csvfile:
|
||||
reader = DictReader(csvfile)
|
||||
for row in reader:
|
||||
territory_codes = row['territory_codes'].split('\n')
|
||||
for code in territory_codes:
|
||||
if code not in vat_rates:
|
||||
vat_rates[code] = {}
|
||||
|
||||
start_date = row['start_date']
|
||||
stop_data = row['stop_date']
|
||||
time_period = f'{start_date}|{stop_data}'
|
||||
r = row.copy()
|
||||
del r['start_date']
|
||||
del r['stop_date']
|
||||
del r['territory_codes']
|
||||
vat_rates[code][time_period] = r
|
||||
print(vat_rates)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
import importlib
|
||||
import sys
|
||||
import os
|
||||
|
||||
from os.path import join as join_path
|
||||
from xmlrpc.client import ServerProxy as RPCClient
|
||||
|
||||
root = os.path.dirname(os.getcwd())
|
||||
sys.path.append(join_path(root, 'uncloud'))
|
||||
secrets = importlib.import_module('uncloud.secrets')
|
||||
|
||||
|
||||
class OpenNebula:
|
||||
def __init__(self, url, session_string):
|
||||
self.session_string = session_string
|
||||
self.client = RPCClient(secrets.OPENNEBULA_URL)
|
||||
|
||||
def create_user(self, username, password, authentication_driver='', group_id=None):
|
||||
# https://docs.opennebula.org/5.10/integration/system_interfaces/api.html#one-user-allocate
|
||||
|
||||
if group_id is None:
|
||||
group_id = []
|
||||
|
||||
return self.client.one.user.allocate(
|
||||
self.session_string,
|
||||
username,
|
||||
password,
|
||||
authentication_driver,
|
||||
group_id
|
||||
)
|
||||
|
||||
def chmod(self, vm_id, user_id=-1, group_id=-1):
|
||||
# https://docs.opennebula.org/5.10/integration/system_interfaces/api.html#one-vm-chown
|
||||
|
||||
return self.client.one.vm.chown(self.session_string, vm_id, user_id, group_id)
|
||||
|
||||
|
||||
one = OpenNebula(secrets.OPENNEBULA_URL, secrets.OPENNEBULA_USER_PASS)
|
||||
|
||||
# Create User in OpenNebula
|
||||
# success, response, *_ = one.create_user(username='meow12345', password='hello_world')
|
||||
# print(success, response)
|
||||
|
||||
# Change owner of a VM
|
||||
# success, response, *_ = one.chmod(vm_id=25589, user_id=706)
|
||||
# print(success, response)
|
||||
18
archive/uncloud_django_based/hacks/command-wrapper.sh
Normal file
18
archive/uncloud_django_based/hacks/command-wrapper.sh
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
dbhost=$1; shift
|
||||
|
||||
ssh -L5432:localhost:5432 "$dbhost" &
|
||||
|
||||
python manage.py "$@"
|
||||
|
||||
|
||||
|
||||
# command only needs to be active while manage command is running
|
||||
|
||||
# -T no pseudo terminal
|
||||
|
||||
|
||||
# alternatively: commands output shell code
|
||||
|
||||
# ssh uncloud@dbhost "python manage.py --hostname xxx ..."
|
||||
Loading…
Add table
Add a link
Reference in a new issue