Skip to content

Commit

Permalink
more changes to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
JungleCatSW committed Nov 24, 2023
1 parent a346b00 commit a9dd6c9
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cp -r out/cudo_compute src
cp helpers/* src/cudo_compute
echo "import cudo_compute.auth_config as AuthConfig" >> src/cudo_compute/__init__.py
echo "import cudo_compute.cudo_client as CudoClient" >> src/cudo_compute/__init__.py
echo "import cudo_compute.cudo_api as cudo_api" >> src/cudo_compute/__init__.py
python3 tools/authfix.py
- name: Install pypa/build
run: >-
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
cp -r out/cudo_compute src
cp helpers/* src/cudo_compute
echo "import cudo_compute.auth_config as AuthConfig" >> src/cudo_compute/__init__.py
echo "import cudo_compute.cudo_client as CudoClient" >> src/cudo_compute/__init__.py
echo "import cudo_compute.cudo_api as cudo_api" >> src/cudo_compute/__init__.py
python3 tools/authfix.py
- name: Install pypa/build
run: >-
Expand Down
3 changes: 1 addition & 2 deletions codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ rm -rf swagger-codegen

cp helpers/* docs/src/cudo_compute
echo "import src.cudo_compute.auth_config as AuthConfig" >> src/cudo_compute/__init__.py
echo "import src.cudo_compute.cudo_client as CudoClient" >> src/cudo_compute/__init__.py

echo "import cudo_compute.cudo_api as cudo_api" >> src/cudo_compute/__init__.py

python3 tools/authfix.py
21 changes: 10 additions & 11 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import cudo_compute as cudo
from cudo_compute import cudo_api
import cudo_compute


def machine_types(gpu_model, mem_gib, vcpu_count, gpu_count):
try:
client, e = cudo.CudoClient.get_client()
api = cudo.VirtualMachinesApi(client)
api = cudo_api.virtualmachines()
types = api.list_vm_machine_types(mem_gib, vcpu_count, gpu=gpu_count, gpu_model=gpu_model)
types_dict = types.to_dict()
return types_dict
except Exception as e:
raise e


print(machine_types("",4,4,0))
print(machine_types("", 4, 4, 0))

project_id, e = cudo.AuthConfig.get_project()
print(project_id, e)
print(cudo_api.project_id())

def list_instances():
try:
project_id, e = cudo.AuthConfig.get_project()
client, e = cudo.CudoClient.get_client()
api = cudo.VirtualMachinesApi(client)
vms = api.list_vms(project_id)
api = cudo_api.virtualmachines()
vms = api.list_vms(cudo_api.project_id())
instances = {}
vms_dict = vms.to_dict()
return vms_dict
except Exception as e:
raise e

print(list_instances())

print(list_instances())
15 changes: 1 addition & 14 deletions helpers/auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,4 @@ def load_config(path, context_name):
return key_config, context_config, error


def get_api_key():
key_config, context_config, error = load_config(home + '/.config/cudo/cudo.yml', "")
if not error:
return key_config['key'], None
else:
return None, error


def get_project():
key_config, context_config, error = load_config(home + '/.config/cudo/cudo.yml', "")
if not error:
return context_config['project'], None
else:
return None, error

113 changes: 113 additions & 0 deletions helpers/cudo_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import cudo_compute as cudo
import os

home = os.path.expanduser("~")


def client():
configuration = cudo.Configuration()
key, err = get_api_key()

if err:
return None, err

configuration.api_key['Authorization'] = key
# configuration.debug = True
configuration.api_key_prefix['Authorization'] = 'Bearer'
configuration.host = "https://rest.compute.cudo.org"

client = cudo.ApiClient(configuration)
return client, None


def get_api_key():
key_config, context_config, error = cudo.AuthConfig.load_config(home + '/.config/cudo/cudo.yml', "")
if not error:
return key_config['key'], None
else:
return None, error


def get_project_id():
key_config, context_config, error = cudo.AuthConfig.load_config(home + '/.config/cudo/cudo.yml', "")
if not error:
return context_config['project'], None
else:
return None, error


def project_id():
p, e = get_project_id()
if e is None:
return p
return ''

# APIs
def apikeys():
c, err = client()
if err:
raise Exception(err)
return cudo.APIKeysApi(c)


def disks():
c, err = client()
if err:
raise Exception(err)
return cudo.DisksApi(c)


def networks():
c, err = client()
if err:
raise Exception(err)
return cudo.NetworksApi(c)


def objectstorage():
c, err = client()
if err:
raise Exception(err)
return cudo.ObjectStorageApi(c)


def permissions():
c, err = client()
if err:
raise Exception(err)
return cudo.PermissionsApi(c)


def projects():
c, err = client()
if err:
raise Exception(err)
return cudo.ProjectsApi(c)


def sshkeys():
c, err = client()
if err:
raise Exception(err)
return cudo.SSHKeysApi(c)


def search():
c, err = client()
if err:
raise Exception(err)
return cudo.SearchApi(c)


def user():
c, err = client()
if err:
raise Exception(err)
return cudo.UserApi(c)


def virtualmachines():
c, err = client()
if err:
raise Exception(err)
return cudo.VirtualMachinesApi(c)
16 changes: 0 additions & 16 deletions helpers/cudo_client.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cudo-compute"
version = "0.1.1"
version = "0.1.2"
authors = [
{ name = "Cudo Ventures", email = "[email protected]" },
]
Expand Down

0 comments on commit a9dd6c9

Please sign in to comment.