From 3f3e158aad8e50b95afae6f7b97e1ad9bd43ce5a Mon Sep 17 00:00:00 2001 From: jungle Date: Thu, 16 Nov 2023 14:16:50 +0000 Subject: [PATCH] client helpers --- README.md | 276 +----------------- codegen.sh | 4 + exp/example.py | 29 ++ helpers/{config.py => auth_config.py} | 0 helpers/cudo_client.py | 9 +- pyproject.toml | 3 +- src/cudo_compute/__init__.py | 2 + src/cudo_compute/auth_config.py | 59 ++++ src/cudo_compute/cudo_client.py | 16 + {helpers => src/cudo_compute}/print_config.py | 0 10 files changed, 121 insertions(+), 277 deletions(-) create mode 100644 exp/example.py rename helpers/{config.py => auth_config.py} (100%) create mode 100644 src/cudo_compute/auth_config.py create mode 100644 src/cudo_compute/cudo_client.py rename {helpers => src/cudo_compute}/print_config.py (100%) diff --git a/README.md b/README.md index df35d8a..f2722d9 100644 --- a/README.md +++ b/README.md @@ -1,274 +1,6 @@ -# src.cudo-compute -No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) - -This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: - -- API version: 1.0.0 -- Package version: 1.0.0 -- Build package: io.swagger.codegen.languages.PythonClientCodegen - -## Requirements. - -Python 2.7 and 3.4+ - -## Installation & Usage -### pip install - -If the python package is hosted on Github, you can install directly from Github - -```sh -pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git -``` -(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git`) - -Then import the package: -```python -import src.cudo_compute -``` - -### Setuptools - -Install via [Setuptools](http://pypi.python.org/pypi/setuptools). - -```sh -python setup.py install --user -``` -(or `sudo python setup.py install` to install the package for all users) - -Then import the package: -```python -import src.cudo_compute -``` - -## Getting Started - -Please follow the [installation procedure](#installation--usage) and then run the following: - -```python -from __future__ import print_function -import time -import src.cudo_compute -from src.cudo_compute.rest import ApiException -from pprint import pprint - -# create an instance of the API class -api_instance = src.cudo_compute.APIKeysApi(src.cudo_compute.ApiClient(configuration)) -name = 'name_example' # str | - -try: - # Delete - api_response = api_instance.delete_api_key(name) - pprint(api_response) -except ApiException as e: - print("Exception when calling APIKeysApi->delete_api_key: %s\n" % e) - -``` - -## Documentation for API Endpoints - -All URIs are relative to *https://rest.compute.cudo.org* - -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -*APIKeysApi* | [**delete_api_key**](docs/APIKeysApi.md#delete_api_key) | **DELETE** /v1/api-keys/{name} | Delete -*APIKeysApi* | [**generate_api_key**](docs/APIKeysApi.md#generate_api_key) | **POST** /v1/api-keys | Generate -*APIKeysApi* | [**list_api_keys**](docs/APIKeysApi.md#list_api_keys) | **GET** /v1/api-keys | List -*DisksApi* | [**attach_storage_disk**](docs/DisksApi.md#attach_storage_disk) | **PATCH** /v1/projects/{projectId}/disk/{id}/attach | Attach storage disk to VM -*DisksApi* | [**create_disk_snapshot**](docs/DisksApi.md#create_disk_snapshot) | **POST** /v1/projects/{projectId}/disks/{id}/snapshots | Create Disk Snapshot -*DisksApi* | [**create_storage_disk**](docs/DisksApi.md#create_storage_disk) | **POST** /v1/projects/{projectId}/disks | Create storage disk -*DisksApi* | [**delete_disk_snapshot**](docs/DisksApi.md#delete_disk_snapshot) | **DELETE** /v1/projects/{projectId}/disks/{id}/snapshots | Delete Disk Snapshots -*DisksApi* | [**delete_storage_disk**](docs/DisksApi.md#delete_storage_disk) | **DELETE** /v1/projects/{projectId}/disks/{id} | Delete storage disk -*DisksApi* | [**detach_storage_disk**](docs/DisksApi.md#detach_storage_disk) | **PUT** /v1/projects/{projectId}/disk/{id}/detach | Detach storage disk from VM -*DisksApi* | [**get_disk**](docs/DisksApi.md#get_disk) | **GET** /v1/projects/{projectId}/disks/{id} | List disks -*DisksApi* | [**list_disk_snapshots**](docs/DisksApi.md#list_disk_snapshots) | **GET** /v1/projects/{projectId}/disks/{id}/snapshots | List Disk Snapshots -*DisksApi* | [**list_disks**](docs/DisksApi.md#list_disks) | **GET** /v1/projects/{projectId}/disks | List disks -*DisksApi* | [**revert_disk**](docs/DisksApi.md#revert_disk) | **POST** /v1/projects/{projectId}/disks/{id}/revert | Revert Disk to Snapshot -*NetworksApi* | [**create_network**](docs/NetworksApi.md#create_network) | **POST** /v1/projects/{projectId}/networks | Create network -*NetworksApi* | [**create_security_group**](docs/NetworksApi.md#create_security_group) | **POST** /v1/projects/{securityGroup.projectId}/networks/security-groups | Create security group -*NetworksApi* | [**delete_network**](docs/NetworksApi.md#delete_network) | **DELETE** /v1/projects/{projectId}/networks/{id} | Delete network -*NetworksApi* | [**delete_security_group**](docs/NetworksApi.md#delete_security_group) | **DELETE** /v1/projects/{projectId}/networks/security-groups/{id} | Delete security group -*NetworksApi* | [**get_network**](docs/NetworksApi.md#get_network) | **GET** /v1/projects/{projectId}/networks/{id} | Get network -*NetworksApi* | [**get_security_group**](docs/NetworksApi.md#get_security_group) | **GET** /v1/projects/{projectId}/networks/security-groups/{id} | Get a security group -*NetworksApi* | [**list_networks**](docs/NetworksApi.md#list_networks) | **GET** /v1/projects/{projectId}/networks | List networks -*NetworksApi* | [**list_security_groups**](docs/NetworksApi.md#list_security_groups) | **GET** /v1/projects/{projectId}/networks/security-groups | List security groups -*NetworksApi* | [**start_network**](docs/NetworksApi.md#start_network) | **POST** /v1/projects/{projectId}/networks/{id}/start | Start network -*NetworksApi* | [**stop_network**](docs/NetworksApi.md#stop_network) | **POST** /v1/projects/{projectId}/networks/{id}/stop | Stop network -*NetworksApi* | [**update_security_group**](docs/NetworksApi.md#update_security_group) | **PATCH** /v1/projects/{securityGroup.projectId}/networks/security-groups/{securityGroup.id} | Update security group -*ObjectStorageApi* | [**activate**](docs/ObjectStorageApi.md#activate) | **POST** /v1/projects/{projectId}/object-storage/activate | Allow the use of S3 compatible storage in a project -*ObjectStorageApi* | [**create_object_storage_user**](docs/ObjectStorageApi.md#create_object_storage_user) | **POST** /v1/projects/{projectId}/object-storage/users | Create user that stores keys for storage buckets -*ObjectStorageApi* | [**delete_object_storage_key**](docs/ObjectStorageApi.md#delete_object_storage_key) | **POST** /v1/projects/{projectId}/object-storage/users/{id}/keys | Delete object storage user -*ObjectStorageApi* | [**delete_object_storage_user**](docs/ObjectStorageApi.md#delete_object_storage_user) | **DELETE** /v1/projects/{projectId}/object-storage/users/{id} | Delete object storage user -*ObjectStorageApi* | [**generate_object_storage_key**](docs/ObjectStorageApi.md#generate_object_storage_key) | **POST** /v1/projects/{projectId}/object-storage/users/{id} | Generate access key for storage buckets -*ObjectStorageApi* | [**get_object_storage_bucket**](docs/ObjectStorageApi.md#get_object_storage_bucket) | **GET** /v1/projects/{projectId}/object-storage/buckets/{id} | Get details for a bucket -*ObjectStorageApi* | [**get_object_storage_session_key**](docs/ObjectStorageApi.md#get_object_storage_session_key) | **GET** /v1/projects/{projectId}/object-storage/session-key | Generate temporary key for storage bucket access -*ObjectStorageApi* | [**list_object_storage_buckets**](docs/ObjectStorageApi.md#list_object_storage_buckets) | **GET** /v1/projects/{projectId}/object-storage/buckets | List buckets -*ObjectStorageApi* | [**list_object_storage_keys**](docs/ObjectStorageApi.md#list_object_storage_keys) | **GET** /v1/projects/{projectId}/object-storage/users/{id}/keys | List storage user keys -*ObjectStorageApi* | [**list_object_storage_users**](docs/ObjectStorageApi.md#list_object_storage_users) | **GET** /v1/projects/{projectId}/object-storage/users | List storage users -*PermissionsApi* | [**add_billing_account_user_permission**](docs/PermissionsApi.md#add_billing_account_user_permission) | **POST** /v1/billing-accounts/{billingAccountId}/add-user-permission | Add billing account user -*PermissionsApi* | [**add_data_center_user_permission**](docs/PermissionsApi.md#add_data_center_user_permission) | **POST** /v1/data-centers/{dataCenterId}/add-user-permission | Add data center user -*PermissionsApi* | [**add_project_user_permission**](docs/PermissionsApi.md#add_project_user_permission) | **POST** /v1/projects/{projectId}/add-user-permission | Add project user -*PermissionsApi* | [**list_user_permissions**](docs/PermissionsApi.md#list_user_permissions) | **GET** /v1/auth/permissions | List -*PermissionsApi* | [**remove_billing_account_user_permission**](docs/PermissionsApi.md#remove_billing_account_user_permission) | **POST** /v1/billing-accounts/{billingAccountId}/remove-user-permission | Remove billing account user -*PermissionsApi* | [**remove_data_center_user_permission**](docs/PermissionsApi.md#remove_data_center_user_permission) | **POST** /v1/data-centers/{dataCenterId}/remove-user-permission | Remove data center user -*PermissionsApi* | [**remove_project_user_permission**](docs/PermissionsApi.md#remove_project_user_permission) | **POST** /v1/projects/{projectId}/remove-user-permission | Remove project user -*ProjectsApi* | [**create_project**](docs/ProjectsApi.md#create_project) | **POST** /v1/projects | Create -*ProjectsApi* | [**delete_project**](docs/ProjectsApi.md#delete_project) | **DELETE** /v1/projects/{id} | Delete -*ProjectsApi* | [**get_project**](docs/ProjectsApi.md#get_project) | **GET** /v1/projects/{id} | Get -*ProjectsApi* | [**list_project_ssh_keys**](docs/ProjectsApi.md#list_project_ssh_keys) | **GET** /v1/project/{projectId}/ssh-keys | List SSH keys -*ProjectsApi* | [**list_projects**](docs/ProjectsApi.md#list_projects) | **GET** /v1/projects | List -*ProjectsApi* | [**update_project**](docs/ProjectsApi.md#update_project) | **PATCH** /v1/projects/{project.id} | Update -*SSHKeysApi* | [**create_ssh_key**](docs/SSHKeysApi.md#create_ssh_key) | **POST** /v1/ssh-keys | Create -*SSHKeysApi* | [**delete_ssh_key**](docs/SSHKeysApi.md#delete_ssh_key) | **DELETE** /v1/ssh-keys/{id} | Delete -*SSHKeysApi* | [**get_ssh_key**](docs/SSHKeysApi.md#get_ssh_key) | **GET** /v1/ssh-keys/{id} | Get -*SSHKeysApi* | [**list_ssh_keys**](docs/SSHKeysApi.md#list_ssh_keys) | **GET** /v1/ssh-keys | List -*SearchApi* | [**list_regions**](docs/SearchApi.md#list_regions) | **GET** /v1/regions | Regions -*UserApi* | [**create_identity_verification_session**](docs/UserApi.md#create_identity_verification_session) | **GET** /v1/auth/create-identity-verification-session | Get identity verification session -*UserApi* | [**delete_user**](docs/UserApi.md#delete_user) | **DELETE** /v1/auth | Delete -*UserApi* | [**get**](docs/UserApi.md#get) | **GET** /v1/auth | Get -*VirtualMachinesApi* | [**connect_vm**](docs/VirtualMachinesApi.md#connect_vm) | **GET** /v1/projects/{projectId}/vms/{id}/connect | Connect via VNC -*VirtualMachinesApi* | [**count_vms**](docs/VirtualMachinesApi.md#count_vms) | **GET** /v1/projects/{projectId}/count-vms | Count -*VirtualMachinesApi* | [**create_private_vm_image**](docs/VirtualMachinesApi.md#create_private_vm_image) | **POST** /v1/projects/{projectId}/images | Create private VM image -*VirtualMachinesApi* | [**create_vm**](docs/VirtualMachinesApi.md#create_vm) | **POST** /v1/projects/{projectId}/vm | Create virtual machine -*VirtualMachinesApi* | [**delete_private_vm_image**](docs/VirtualMachinesApi.md#delete_private_vm_image) | **DELETE** /v1/projects/{projectId}/images/{id} | Delete private VM image -*VirtualMachinesApi* | [**get_private_vm_image**](docs/VirtualMachinesApi.md#get_private_vm_image) | **GET** /v1/projects/{projectId}/images/{id} | Get private VM image -*VirtualMachinesApi* | [**get_vm**](docs/VirtualMachinesApi.md#get_vm) | **GET** /v1/projects/{projectId}/vms/{id} | Get -*VirtualMachinesApi* | [**list_private_vm_images**](docs/VirtualMachinesApi.md#list_private_vm_images) | **GET** /v1/projects/{projectId}/images | List private VM images -*VirtualMachinesApi* | [**list_public_vm_images**](docs/VirtualMachinesApi.md#list_public_vm_images) | **GET** /v1/vms/public-images | List public VM images -*VirtualMachinesApi* | [**list_vm_data_centers**](docs/VirtualMachinesApi.md#list_vm_data_centers) | **GET** /v1/vms/data-centers | List data centers -*VirtualMachinesApi* | [**list_vm_disks**](docs/VirtualMachinesApi.md#list_vm_disks) | **GET** /v1/projects/{projectId}/vms/{id}/disks | List disks attached to VM -*VirtualMachinesApi* | [**list_vm_machine_types**](docs/VirtualMachinesApi.md#list_vm_machine_types) | **GET** /v1/vms/machine-types | List machine types -*VirtualMachinesApi* | [**list_vms**](docs/VirtualMachinesApi.md#list_vms) | **GET** /v1/projects/{projectId}/vms | List -*VirtualMachinesApi* | [**monitor_vm**](docs/VirtualMachinesApi.md#monitor_vm) | **GET** /v1/projects/{projectId}/vms/{id}/monitor | Monitor -*VirtualMachinesApi* | [**reboot_vm**](docs/VirtualMachinesApi.md#reboot_vm) | **POST** /v1/projects/{projectId}/vms/{id}/reboot | Reboot -*VirtualMachinesApi* | [**resize_vm**](docs/VirtualMachinesApi.md#resize_vm) | **POST** /v1/projects/{projectId}/vms/{id}/resize | Resize vCPU and memory of VM -*VirtualMachinesApi* | [**resize_vm_disk**](docs/VirtualMachinesApi.md#resize_vm_disk) | **PATCH** /v1/projects/{projectId}/vms/{id}/disks | Resize a VM's disk -*VirtualMachinesApi* | [**start_vm**](docs/VirtualMachinesApi.md#start_vm) | **POST** /v1/projects/{projectId}/vms/{id}/start | Start -*VirtualMachinesApi* | [**stop_vm**](docs/VirtualMachinesApi.md#stop_vm) | **POST** /v1/projects/{projectId}/vms/{id}/stop | Stop -*VirtualMachinesApi* | [**terminate_vm**](docs/VirtualMachinesApi.md#terminate_vm) | **POST** /v1/projects/{projectId}/vms/{id}/terminate | Terminate -*VirtualMachinesApi* | [**update_private_vm_image**](docs/VirtualMachinesApi.md#update_private_vm_image) | **POST** /v1/projects/{projectId}/images/{id} | Update private VM image - - -## Documentation For Models - - - [Any](docs/Any.md) - - [ApiKey](docs/ApiKey.md) - - [AttachStorageDiskResponse](docs/AttachStorageDiskResponse.md) - - [Body](docs/Body.md) - - [Body1](docs/Body1.md) - - [Body10](docs/Body10.md) - - [Body11](docs/Body11.md) - - [Body2](docs/Body2.md) - - [Body3](docs/Body3.md) - - [Body4](docs/Body4.md) - - [Body5](docs/Body5.md) - - [Body6](docs/Body6.md) - - [Body7](docs/Body7.md) - - [Body8](docs/Body8.md) - - [Body9](docs/Body9.md) - - [ConnectVMResponse](docs/ConnectVMResponse.md) - - [CountVMsResponse](docs/CountVMsResponse.md) - - [CpuModelCategory](docs/CpuModelCategory.md) - - [CreateDiskSnapshotResponse](docs/CreateDiskSnapshotResponse.md) - - [CreateNetworkResponse](docs/CreateNetworkResponse.md) - - [CreatePrivateVMImageResponse](docs/CreatePrivateVMImageResponse.md) - - [CreateSecurityGroupResponse](docs/CreateSecurityGroupResponse.md) - - [CreateStorageDiskResponse](docs/CreateStorageDiskResponse.md) - - [CreateVMRequestNIC](docs/CreateVMRequestNIC.md) - - [CreateVMResponse](docs/CreateVMResponse.md) - - [DataCenterCategory](docs/DataCenterCategory.md) - - [Decimal](docs/Decimal.md) - - [DeleteDiskSnapshotResponse](docs/DeleteDiskSnapshotResponse.md) - - [DeleteNetworkResponse](docs/DeleteNetworkResponse.md) - - [DeleteObjectStorageKeyResponse](docs/DeleteObjectStorageKeyResponse.md) - - [DeleteObjectStorageUserResponse](docs/DeleteObjectStorageUserResponse.md) - - [DeletePrivateVMImageResponse](docs/DeletePrivateVMImageResponse.md) - - [DeleteSecurityGroupResponse](docs/DeleteSecurityGroupResponse.md) - - [DeleteStorageDiskResponse](docs/DeleteStorageDiskResponse.md) - - [DetachStorageDiskResponse](docs/DetachStorageDiskResponse.md) - - [Disk](docs/Disk.md) - - [DiskState](docs/DiskState.md) - - [DiskStorageClass](docs/DiskStorageClass.md) - - [DiskStoragePriceHr](docs/DiskStoragePriceHr.md) - - [DiskType](docs/DiskType.md) - - [GenerateApiKeyRequest](docs/GenerateApiKeyRequest.md) - - [GetDiskResponse](docs/GetDiskResponse.md) - - [GetNetworkResponse](docs/GetNetworkResponse.md) - - [GetObjectStorageSessionKeyResponse](docs/GetObjectStorageSessionKeyResponse.md) - - [GetPrivateVMImageResponse](docs/GetPrivateVMImageResponse.md) - - [GetSecurityGroupResponse](docs/GetSecurityGroupResponse.md) - - [GetVMResponse](docs/GetVMResponse.md) - - [GpuModelCategory](docs/GpuModelCategory.md) - - [HostConfigCategory](docs/HostConfigCategory.md) - - [IdentityVerificationSession](docs/IdentityVerificationSession.md) - - [Image](docs/Image.md) - - [ListApiKeysResponse](docs/ListApiKeysResponse.md) - - [ListDiskSnapshotsResponse](docs/ListDiskSnapshotsResponse.md) - - [ListDisksResponse](docs/ListDisksResponse.md) - - [ListNetworksResponse](docs/ListNetworksResponse.md) - - [ListObjectStorageBucketsResponse](docs/ListObjectStorageBucketsResponse.md) - - [ListObjectStorageKeysResponse](docs/ListObjectStorageKeysResponse.md) - - [ListObjectStorageUsersResponse](docs/ListObjectStorageUsersResponse.md) - - [ListPrivateVMImagesResponse](docs/ListPrivateVMImagesResponse.md) - - [ListPrivateVMImagesResponsePrivateImage](docs/ListPrivateVMImagesResponsePrivateImage.md) - - [ListProjectSshKeysResponse](docs/ListProjectSshKeysResponse.md) - - [ListProjectsResponse](docs/ListProjectsResponse.md) - - [ListPublicVMImagesResponse](docs/ListPublicVMImagesResponse.md) - - [ListRegionsResponse](docs/ListRegionsResponse.md) - - [ListSecurityGroupsResponse](docs/ListSecurityGroupsResponse.md) - - [ListSshKeysResponse](docs/ListSshKeysResponse.md) - - [ListUserPermissionsResponse](docs/ListUserPermissionsResponse.md) - - [ListVMDataCentersResponse](docs/ListVMDataCentersResponse.md) - - [ListVMDisksResponse](docs/ListVMDisksResponse.md) - - [ListVMMachineTypesRequest](docs/ListVMMachineTypesRequest.md) - - [ListVMMachineTypesResponse](docs/ListVMMachineTypesResponse.md) - - [ListVMsResponse](docs/ListVMsResponse.md) - - [MonitorVMResponse](docs/MonitorVMResponse.md) - - [Network](docs/Network.md) - - [NetworkPriceHr](docs/NetworkPriceHr.md) - - [ObjectStorageBucket](docs/ObjectStorageBucket.md) - - [ObjectStorageKey](docs/ObjectStorageKey.md) - - [ObjectStorageUser](docs/ObjectStorageUser.md) - - [Profile](docs/Profile.md) - - [Project](docs/Project.md) - - [Protocol](docs/Protocol.md) - - [RebootVMResponse](docs/RebootVMResponse.md) - - [Region](docs/Region.md) - - [ResizeVMDiskResponse](docs/ResizeVMDiskResponse.md) - - [ResizeVMResponse](docs/ResizeVMResponse.md) - - [RevertDiskResponse](docs/RevertDiskResponse.md) - - [Role](docs/Role.md) - - [Rule](docs/Rule.md) - - [RuleType](docs/RuleType.md) - - [SecurityGroup](docs/SecurityGroup.md) - - [SecurityGroup1](docs/SecurityGroup1.md) - - [SecurityGroupRule](docs/SecurityGroupRule.md) - - [Snapshot](docs/Snapshot.md) - - [SshKey](docs/SshKey.md) - - [SshKeySource](docs/SshKeySource.md) - - [StartNetworkResponse](docs/StartNetworkResponse.md) - - [StartVMResponse](docs/StartVMResponse.md) - - [Status](docs/Status.md) - - [StopNetworkResponse](docs/StopNetworkResponse.md) - - [StopVMResponse](docs/StopVMResponse.md) - - [TerminateVMResponse](docs/TerminateVMResponse.md) - - [UpdatePrivateVMImageResponse](docs/UpdatePrivateVMImageResponse.md) - - [UpdateSecurityGroupResponse](docs/UpdateSecurityGroupResponse.md) - - [UserPermission](docs/UserPermission.md) - - [V1PrivateImage](docs/V1PrivateImage.md) - - [VM](docs/VM.md) - - [VMDataCenter](docs/VMDataCenter.md) - - [VMDataCenterStorageClass](docs/VMDataCenterStorageClass.md) - - [VMMonitoringItem](docs/VMMonitoringItem.md) - - [VMNIC](docs/VMNIC.md) - - [VRouterSize](docs/VRouterSize.md) - - -## Documentation For Authorization - - All endpoints do not require authorization. - - -## Author - +# Cudo Compute +urllib3 +six + conda install -c conda-forge six \ No newline at end of file diff --git a/codegen.sh b/codegen.sh index 6ffa961..074275f 100755 --- a/codegen.sh +++ b/codegen.sh @@ -8,4 +8,8 @@ cd swagger-codegen -l python -o /gen/out -DpackageName=src.cudo_compute cd .. cp -r swagger-codegen/out/src src +rm -rf swagger-codegen +cp helpers/* 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 diff --git a/exp/example.py b/exp/example.py new file mode 100644 index 0000000..a47b343 --- /dev/null +++ b/exp/example.py @@ -0,0 +1,29 @@ +import cudo_compute as client +def get_client(): + configuration = client.Configuration() + # key, err = config.get_api_key() + + # if err != None: + # return None, err + + configuration.api_key['Authorization'] = "derp" + # configuration.debug = True + configuration.api_key_prefix['Authorization'] = 'Bearer' + configuration.host = "https://rest.compute.cudo.org" + + sclient = client.ApiClient(configuration) + vms_api_client = client.VirtualMachinesApi(sclient) + return vms_api_client, None + +def machine_types(gpu_model, mem_gib, vcpu_count, gpu_count): + try: + c, e = get_client() + types = c.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: # TODO what to do with errors ? + raise e + + +t = machine_types("",4,4,0) +print(t) \ No newline at end of file diff --git a/helpers/config.py b/helpers/auth_config.py similarity index 100% rename from helpers/config.py rename to helpers/auth_config.py diff --git a/helpers/cudo_client.py b/helpers/cudo_client.py index 40d0a85..468e1d5 100644 --- a/helpers/cudo_client.py +++ b/helpers/cudo_client.py @@ -1,6 +1,7 @@ +import src.cudo_compute as cudo def get_client(): - configuration = client.Configuration() - key, err = config.get_api_key() + configuration = cudo.Configuration() + key, err = cudo.config.get_api_key() if err != None: return None, err @@ -10,6 +11,6 @@ def get_client(): configuration.api_key_prefix['Authorization'] = 'Bearer' configuration.host = "https://rest.compute.cudo.org" - sclient = client.ApiClient(configuration) - vms_api_client = client.VirtualMachinesApi(sclient) + sclient = cudo.ApiClient(configuration) + vms_api_client = cudo.VirtualMachinesApi(sclient) return vms_api_client, None \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 2ce03e6..c95bac1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "cudo-compute" -version = "0.0.3" +version = "0.0.4" authors = [ { name = "Cudo Ventures", email = "dev@cudoventures.com" }, ] @@ -20,6 +20,7 @@ classifiers = [ dependencies = [ "six>=1.0.0", "urllib3>=1.10.0", + "certifi>=2023.0.0", ] [project.urls] diff --git a/src/cudo_compute/__init__.py b/src/cudo_compute/__init__.py index 55fb986..b302d2a 100644 --- a/src/cudo_compute/__init__.py +++ b/src/cudo_compute/__init__.py @@ -142,3 +142,5 @@ from src.cudo_compute.models.vm_monitoring_item import VMMonitoringItem from src.cudo_compute.models.vmnic import VMNIC from src.cudo_compute.models.v_router_size import VRouterSize +import src.cudo_compute.auth_config as AuthConfig +import src.cudo_compute.cudo_client as CudoClient diff --git a/src/cudo_compute/auth_config.py b/src/cudo_compute/auth_config.py new file mode 100644 index 0000000..f80ae48 --- /dev/null +++ b/src/cudo_compute/auth_config.py @@ -0,0 +1,59 @@ +import yaml +import os + +home = os.path.expanduser("~") + + +def load_config(path, context_name): + key_config = None + context_config = None + error = None + + with open(path, 'r') as file: + config_data = yaml.safe_load(file) + + if config_data['configVersion'] != "v0": + error = Exception("Only config version v0 is supported") + return key_config, context_config, error + + if not context_name: + if 'current-context' in config_data: + context_name = config_data['current-context'] + else: + return key_config, context_config, Exception("No current context selected") + + if 'contexts' in config_data: + for context_data in config_data['contexts']: + if context_data['name'] == context_name: + context_config = context_data + break + + if not context_config: + error = Exception("Context not found") + return key_config, context_config, error + + if 'keys' in config_data: + for key_data in config_data['keys']: + if key_data['name'] == context_config['key']: + key_config = key_data + + if not key_config: + error = Exception("Key not found") + + 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 diff --git a/src/cudo_compute/cudo_client.py b/src/cudo_compute/cudo_client.py new file mode 100644 index 0000000..24a5b73 --- /dev/null +++ b/src/cudo_compute/cudo_client.py @@ -0,0 +1,16 @@ +import src.cudo_compute as cudo +def get_client(): + configuration = cudo.Configuration() + key, err = cudo.AuthConfig.get_api_key() + + if err != None: + return None, err + + configuration.api_key['Authorization'] = key + # configuration.debug = True + configuration.api_key_prefix['Authorization'] = 'Bearer' + configuration.host = "https://rest.compute.cudo.org" + + sclient = cudo.ApiClient(configuration) + vms_api_client = cudo.VirtualMachinesApi(sclient) + return vms_api_client, None \ No newline at end of file diff --git a/helpers/print_config.py b/src/cudo_compute/print_config.py similarity index 100% rename from helpers/print_config.py rename to src/cudo_compute/print_config.py