### Install aiohttp Dependency Source: https://github.com/0011101000101001/aio4vpsapi/blob/main/README.md This is the dependency required for the aio4vps library. Ensure you have this installed before using the client. ```text aiohttp==3.9.5 ``` -------------------------------- ### Initialize and Use FourVpsClient Source: https://github.com/0011101000101001/aio4vpsapi/blob/main/README.md Demonstrates how to initialize the FourVpsClient and use it as a context manager to make API calls. The user_balance method is shown as an example. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "YOR_API_KEY" four_vps_client = FourVpsClient(API_KEY) async def main(): """You can use a context manager to interact with the api, this approach is most recommended.""" async with four_vps_client as client: """ obtaining balance using the user_balance method https://4vps.su/page/api#userBalance """ balance = await client.user_balance() # return float print(balance) # 11625.9 if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Get Available Upgrade Presets Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves available upgrade options for a specific server. ```APIDOC ## Get Available Upgrade Presets ### Description Retrieves available upgrade options for a specific server. ### Method GET ### Endpoint `/servers/{server_id}/upgrade_presets` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to get upgrade presets for. ### Response #### Success Response (200) - **presets** (array) - A list of available upgrade presets. - **id** (integer) - The ID of the upgrade preset. - **name_full** (string) - The full name of the upgrade preset. - **price** (number) - The price of the upgrade preset. - **cpu_number** (integer) - The number of CPU cores. - **ram** (integer) - The amount of RAM in GB. - **ram_mib** (integer) - The amount of RAM in MiB. - **rom** (integer) - The amount of disk space in GB. - **rom_mib** (integer) - The amount of disk space in MiB. #### Response Example ```json [ { "id": 123, "name_full": "Premium CPU Upgrade", "price": 25.50, "cpu_number": 4, "ram": 8, "ram_mib": 8192, "rom": 100, "rom_mib": 102400 } ] ``` ``` -------------------------------- ### API Error Handling Example Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Demonstrates how to handle various API errors using specific exception types provided by the library. This example includes common exceptions like AuthenticationError, NotEnoughMoney, and ServerNotFound. ```python from FourVps.api import FourVpsClient from FourVps.exceptions.errors import ( AuthenticationError, NotEnoughMoney, ServerNotFound, TariffNotAvailable, DataCenterNotAvailable, NeedVerification, MaximumNumberOfIpAddresses, ServerCannotBeTurnedOn, ServerStoppedByAdministrator, CannotChangeToThisTariffPlan, IncorrectBackupPeriod ) import asyncio async def main(): client = FourVpsClient("your_api_key") try: async with client as c: server = await c.buy_server( tariff_id=123, datacenter_id=1, ostempl_id=3, server_name="my-server" ) print(f"Server created: {server.server_id}") except AuthenticationError as e: print(f"Authentication failed: {e}") except NotEnoughMoney as e: print(f"Insufficient funds: {e}") except ServerNotFound as e: print(f"Server not found: {e}") except TariffNotAvailable as e: print(f"Tariff unavailable: {e}") except DataCenterNotAvailable as e: print(f"Data center unavailable: {e}") except NeedVerification as e: print(f"Account verification required: {e}") except MaximumNumberOfIpAddresses as e: print(f"IP limit reached: {e}") asyncio.run(main()) ``` -------------------------------- ### Get Available Upgrade Presets Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves a list of available upgrade options for a specific server, including details like preset ID, name, price, CPU, RAM, and disk size. ```python async with client as c: server_id = 98104 upgrades = await c.get_available_upgrade_presets(server_id) for preset in upgrades: print(f"Preset ID: {preset.id}") print(f" Name: {preset.name_full}") print(f" Price: {preset.price}") print(f" CPU: {preset.cpu_number} cores") print(f" RAM: {preset.ram}GB ({preset.ram_mib} MiB)") print(f" Disk: {preset.rom}GB ({preset.rom_mib} MiB)") ``` -------------------------------- ### GET /get_dc_list Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Fetches a list of all available data centers with their configurations, pricing, and resource limits. ```APIDOC ## GET /get_dc_list ### Description Fetches a list of all available data centers with their configurations, pricing, and resource limits. ### Method GET ### Endpoint /get_dc_list ### Response #### Success Response (200) - **data_centers** (list) - A list of data center objects. - **dc_name** (string) - Name of the data center. - **city** (string) - City where the data center is located. - **country** (string) - Country where the data center is located. - **cpu_name** (string) - Name of the CPU. - **frequency** (string) - CPU frequency. - **core_price** (float) - Price per CPU core. - **ram_price** (float) - Price per GB of RAM. - **disk_price** (float) - Price per GB of disk space. - **max_core** (integer) - Maximum number of CPU cores available. - **max_ram** (integer) - Maximum RAM in MB. - **max_disk** (integer) - Maximum disk space in GB. - **ipv6** (boolean) - Indicates if IPv6 is available. - **periods** (list) - List of available billing periods. - **period** (integer) - Duration of the period in hours. - **discount** (integer) - Discount percentage for the period. ### Request Example ```python async with client as c: data_centers = await c.get_dc_list() if data_centers: for dc in data_centers: print(f"Data Center: {dc.dc_name}") print(f" Location: {dc.city}, {dc.country}") print(f" CPU: {dc.cpu_name} @ {dc.frequency}") print(f" Pricing - Core: {dc.core_price}, RAM: {dc.ram_price}, Disk: {dc.disk_price}") print(f" Max Resources - Cores: {dc.max_core}, RAM: {dc.max_ram}MB, Disk: {dc.max_disk}GB") print(f" IPv6 Available: {dc.ipv6}") if dc.periods: for period in dc.periods: print(f" Period: {period.period} hours, Discount: {period.discount}%") ``` ``` -------------------------------- ### Get VM Console Link Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Generates a direct console access link for the specified server. ```APIDOC ## get_vm_link ### Description Generates a direct console access link for the specified server. ### Method GET ### Endpoint /api/v1/servers/{server_id}/console_link ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server for which to generate the console link. #### Query Parameters - **domain** (string) - Optional - A specific domain to associate with the console link. ### Response #### Success Response (200) - **console_url** (string) - The URL for direct console access to the server. #### Response Example ```json { "console_url": "https://console.example.com/server/98104" } ``` ``` -------------------------------- ### Get Available Backup Periods Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves available backup periods and their pricing. ```APIDOC ## Get Available Backup Periods ### Description Retrieves available backup periods and their pricing. ### Method GET ### Endpoint `/backup_periods` (Assumed) ### Response #### Success Response (200) - **backup_periods** (array) - A list of available backup periods. - **period** (integer) - The backup period in hours. - **price** (number) - The price for the backup period. #### Response Example ```json [ { "period": 24, "price": 1.50 }, { "period": 72, "price": 3.00 } ] ``` ``` -------------------------------- ### GET /get_tariff_list Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves all available tariff plans with cluster information and preset configurations including OS options and upgrade paths. ```APIDOC ## GET /get_tariff_list ### Description Retrieves all available tariff plans with cluster information and preset configurations including OS options and upgrade paths. ### Method GET ### Endpoint /get_tariff_list ### Response #### Success Response (200) - **tariffs** (list) - A list of tariff plan objects. - **cluster_info** (object) - Information about the cluster. - **dc_name** (string) - Name of the data center. - **city** (string) - City of the data center. - **country** (string) - Country of the data center. - **presets** (list) - List of preset configurations for the tariff. - **name_full** (string) - Full name of the preset. - **cpu_number** (integer) - Number of CPU cores. - **frequency** (string) - CPU frequency. - **ram_mib** (integer) - RAM in MiB. - **rom** (integer) - Storage size in GB. - **price** (float) - Price of the preset. - **os_list** (list) - List of available operating systems. - **name** (string) - Name of the OS. - **available_upgrade_presets** (list) - List of available upgrade presets (count indicated). ### Request Example ```python async with client as c: tariffs = await c.get_tariff_list() if tariffs: for tariff in tariffs: cluster = tariff.cluster_info print(f"Cluster: {cluster.dc_name} ({cluster.city}, {cluster.country})") for preset in tariff.presets: print(f" Preset: {preset.name_full}") print(f" CPU: {preset.cpu_number} cores @ {preset.frequency}") print(f" RAM: {preset.ram_mib} MiB, Storage: {preset.rom} GB") print(f" Price: {preset.price}") print(f" Available OS: {[os.name for os in preset.os_list]}") if preset.available_upgrade_presets: print(f" Upgrade options: {len(preset.available_upgrade_presets)}") ``` ``` -------------------------------- ### Get VM Console Link Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Generates a direct console access link for the specified server. Optionally, a domain can be specified. Requires the server ID. ```python async with client as c: server_id = 98104 console_url = await c.get_vm_link(server_id) print(f"Console access URL: {console_url}") # Optionally specify a domain console_url = await c.get_vm_link(server_id, domain="example.com") ``` -------------------------------- ### Get OS Images Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves available operating system images for a specific tariff and data center combination. ```APIDOC ## get_images ### Description Retrieves available operating system images for a specific tariff and data center combination. ### Method GET ### Endpoint /api/v1/images ### Parameters #### Query Parameters - **tariff_id** (integer) - Required - The ID of the tariff. - **dc_id** (integer) - Required - The ID of the data center. ### Response #### Success Response (200) - **images** (array) - A list of available OS image objects, each containing an ID and name. #### Response Example ```json [ { "id": 22, "name": "Alma Linux 8" }, { "id": 3, "name": "Debian 10" }, { "id": 15, "name": "Ubuntu 22.04" } ] ``` ``` -------------------------------- ### Get OS Images Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves available operating system images for a specific tariff and data center. Requires tariff ID and data center ID. ```python async with client as c: tariff_id = 123 dc_id = 1 images = await c.get_images(tariff_id, dc_id) if images: for os_info in images: print(f"OS ID: {os_info.id}, Name: {os_info.name}") # Output examples: # OS ID: 22, Name: Alma Linux 8 # OS ID: 3, Name: Debian 10 # OS ID: 15, Name: Ubuntu 22.04 ``` -------------------------------- ### Get Available Backup Periods Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves a list of available backup periods and their associated pricing. Useful for determining options before purchasing a backup service. ```python async with client as c: backup_periods = await c.get_backup_periods() for period in backup_periods: print(f"Period: {period.period} hours, Price: {period.price}") ``` -------------------------------- ### Get Server Information Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves detailed information about a specific server, including its data center details. Requires the server ID. ```python async with client as c: server_id = 98104 info = await c.get_server_info(server_id) if info: server = info.server_info dc = info.data_center print(f"Server: {server.name} (ID: {server.server_id})") print(f"Status: {server.status}") print(f"IP Address: {server.ipv4}") print(f"Resources: {server.cpu} CPU, {server.mem}MB RAM, {server.disk}GB Disk") print(f"Data Center: {dc.dc_name} ({dc.city}, {dc.country})") print(f"CPU Type: {dc.cpu_name} @ {dc.frequency}") ``` -------------------------------- ### Get Server Info Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves detailed information about a specific server, including its data center details. ```APIDOC ## get_server_info ### Description Retrieves detailed information about a specific server including its data center details. ### Method GET ### Endpoint /api/v1/servers/{server_id} ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to retrieve information for. ### Response #### Success Response (200) - **server_info** (object) - Contains detailed information about the server (name, status, IP, resources, image, tariff, etc.). - **data_center** (object) - Contains information about the data center where the server is located (name, city, country, CPU details). #### Response Example ```json { "server_info": { "server_id": 98104, "name": "my-production-server", "status": "running", "ipv4": "192.168.1.1", "cpu": 1, "mem": 1024, "disk": 25, "image": "Debian 10", "tariff_name": "Standard SSD 1 vCPU", "price": "5.00/period", "expired": "2024-12-31T23:59:59Z", "autoprolong": true }, "data_center": { "dc_name": "New York 1", "city": "New York", "country": "USA", "cpu_name": "Intel Xeon Gold", "frequency": "2.5 GHz" } } ``` ``` -------------------------------- ### Get Tariff Info Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves detailed information about a specific tariff, including available OS templates and upgrade options. ```APIDOC ## get_tariff_info ### Description Gets detailed information about a specific tariff including available OS templates and upgrade options. ### Method GET ### Endpoint /api/v1/tariffs/{tariff_id} ### Parameters #### Path Parameters - **tariff_id** (integer) - Required - The ID of the tariff to retrieve information for. - **dc_id** (integer) - Required - The ID of the data center. ### Response #### Success Response (200) - **tariff_info** (array) - A list of tariff presets with details like name, CPU, RAM, disk, network, and price. #### Response Example ```json [ { "name_full": "Standard SSD 1 vCPU", "cpu_number": 1, "cpu_name": "Intel Xeon", "ram_mib": 1024, "rom": 25, "eth": 1, "price": 5.00 } ] ``` ``` -------------------------------- ### GET /api/messages Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves account messages and notifications. ```APIDOC ## GET /api/messages ### Description Retrieves account messages and notifications. ### Method GET ### Endpoint /api/messages ### Response #### Success Response (200) - **messages** (list) - A list of message objects. - **id** (int) - The ID of the message. - **title** (string) - The title of the message. - **content** (string) - The content of the message. - **time** (string) - The timestamp of the message. ### Request Example ```python async with client as c: messages = await c.get_messages() if messages: for msg in messages: print(f"Message ID: {msg.id}") print(f" Title: {msg.title}") print(f" Content: {msg.content}") print(f" Time: {msg.time}") ``` ``` -------------------------------- ### Get Tariff Information Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves detailed information about a specific tariff, including available OS templates and upgrade options. Requires tariff ID and data center ID. ```python async with client as c: tariff_id = 123 dc_id = 1 tariff_info = await c.get_tariff_info(tariff_id, dc_id) if tariff_info: for preset in tariff_info: print(f"Tariff: {preset.name_full}") print(f"CPU: {preset.cpu_number} x {preset.cpu_name}") print(f"RAM: {preset.ram_mib} MiB") print(f"Disk: {preset.rom} GB") print(f"Network: {preset.eth}") print(f"Price: {preset.price}") ``` -------------------------------- ### GET /user_balance Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves the current account balance. Returns the balance as a float representing available funds in the account. ```APIDOC ## GET /user_balance ### Description Retrieves the current account balance. Returns the balance as a float representing available funds in the account. ### Method GET ### Endpoint /user_balance ### Response #### Success Response (200) - **balance** (float) - The current account balance. ### Request Example ```python async with client as c: balance = await c.user_balance() print(f"Account balance: {balance}") # Output: 11625.9 ``` ``` -------------------------------- ### Client Initialization Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Demonstrates how to initialize the FourVpsClient with an API key, including options for custom timeouts and base URLs. ```APIDOC ## Client Initialization Initialize the FourVpsClient with your API key to start making requests. Supports custom base URL and timeout configuration. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "your_api_key_here" # Basic initialization client = FourVpsClient(API_KEY) # With custom timeout (in seconds) client = FourVpsClient(API_KEY, timeout=30) # With custom base URL client = FourVpsClient(API_KEY, base_url="https://4vps.su", timeout=15) ``` ``` -------------------------------- ### Initialize FourVpsClient Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Initialize the client with your API key. Supports custom base URL and timeout configuration. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "your_api_key_here" # Basic initialization client = FourVpsClient(API_KEY) # With custom timeout (in seconds) client = FourVpsClient(API_KEY, timeout=30) # With custom base URL client = FourVpsClient(API_KEY, base_url="https://4vps.su", timeout=15) ``` -------------------------------- ### Buy a New VPS Server Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Purchases a new VPS server with a specified tariff, data center, OS template, and name. Returns the server ID and password. Requires tariff ID, data center ID, and OS template ID. ```python async with client as c: # First, get available tariffs tariffs = await c.get_tariff_list() tariff = tariffs[0] preset = tariff.presets[0] # Get available OS images images = await c.get_images(preset.id, preset.dc_id) debian_os = next((os for os in images if 'Debian' in os.name), images[0]) # Purchase the server server = await c.buy_server( tariff_id=preset.id, datacenter_id=preset.dc_id, ostempl_id=debian_os.id, server_name="my-production-server", period=720 # 720 hours = 30 days (default) ) print(f"Server created! ID: {server.server_id}") print(f"Root password: {server.password}") # Output: ServerCreated(server_id=98104, password='super_strong_password') ``` -------------------------------- ### Use FourVpsClient with Context Manager Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt The recommended way to use the client is with an async context manager, which automatically handles session creation and cleanup. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "your_api_key_here" client = FourVpsClient(API_KEY) async def main(): async with client as c: balance = await c.user_balance() print(f"Current balance: {balance}") servers = await c.my_servers() if servers: for server in servers: print(f"Server: {server.name} - Status: {server.status}") asyncio.run(main()) ``` -------------------------------- ### Buy Server Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Purchases a new VPS server with the specified tariff, data center, OS template, and name. Returns server ID and password. ```APIDOC ## buy_server ### Description Purchases a new VPS server with the specified tariff, data center, OS template, and name. Returns server ID and password. ### Method POST ### Endpoint /api/v1/servers ### Parameters #### Request Body - **tariff_id** (integer) - Required - The ID of the tariff for the new server. - **datacenter_id** (integer) - Required - The ID of the data center where the server will be located. - **ostempl_id** (integer) - Required - The ID of the OS template to install. - **server_name** (string) - Required - The desired name for the new server. - **period** (integer) - Optional - The billing period in hours (default is 720 hours / 30 days). ### Request Example ```json { "tariff_id": 123, "datacenter_id": 1, "ostempl_id": 22, "server_name": "my-production-server", "period": 720 } ``` ### Response #### Success Response (200) - **server_id** (integer) - The ID of the newly created server. - **password** (string) - The root password for the new server. #### Response Example ```json { "server_id": 98104, "password": "super_strong_password" } ``` ``` -------------------------------- ### Context Manager Usage Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Illustrates the recommended usage of the client with an async context manager for automatic session handling. ```APIDOC ## Context Manager Usage The recommended way to use the client is with async context manager, which automatically handles session creation and cleanup. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "your_api_key_here" client = FourVpsClient(API_KEY) async def main(): async with client as c: balance = await c.user_balance() print(f"Current balance: {balance}") servers = await c.my_servers() if servers: for server in servers: print(f"Server: {server.name} - Status: {server.status}") asyncio.run(main()) ``` ``` -------------------------------- ### Reinstall Server OS Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Reinstalls the operating system on a server with a new OS template and password. ```APIDOC ## Reinstall Server OS ### Description Reinstalls the operating system on a server with a new OS template and password. ### Method POST (Assumed, based on action) ### Endpoint `/servers/{server_id}/reinstall` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to reinstall. #### Request Body - **os_id** (integer) - Required - The ID of the new operating system template. - **new_password** (string) - Required - The new password for the server. ### Request Example ```json { "os_id": 15, "new_password": "new_secure_password_123" } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the reinstallation process was initiated successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Reinstall Server OS Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Reinstalls the operating system on a server using a new OS template and password. Ensure the server ID, OS ID, and a new password are provided. ```python async with client as c: server_id = 98104 os_id = 15 # Ubuntu 22.04 new_password = "new_secure_password_123" success = await c.reinstall(server_id, os_id, new_password) if success: print(f"Server {server_id} is being reinstalled with OS ID {os_id}") print(f"New password: {new_password}") ``` -------------------------------- ### Fetch Tariff Plan List Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves all available tariff plans with cluster information and preset configurations. Iterates through tariffs and presets to display details. ```python async with client as c: tariffs = await c.get_tariff_list() if tariffs: for tariff in tariffs: cluster = tariff.cluster_info print(f"Cluster: {cluster.dc_name} ({cluster.city}, {cluster.country})") for preset in tariff.presets: print(f" Preset: {preset.name_full}") print(f" CPU: {preset.cpu_number} cores @ {preset.frequency}") print(f" RAM: {preset.ram_mib} MiB, Storage: {preset.rom} GB") print(f" Price: {preset.price}") print(f" Available OS: {[os.name for os in preset.os_list]}") if preset.available_upgrade_presets: print(f" Upgrade options: {len(preset.available_upgrade_presets)}") ``` -------------------------------- ### List My Servers Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Lists all servers owned by the authenticated user with their current status and configuration details. ```APIDOC ## my_servers ### Description Lists all servers owned by the authenticated user with their current status and configuration details. ### Method GET ### Endpoint /api/v1/servers ### Response #### Success Response (200) - **servers** (array) - A list of server objects, each containing details like server ID, name, status, IP, resources, OS image, tariff, expiration, and auto-prolong status. #### Response Example ```json [ { "server_id": 98104, "name": "my-production-server", "status": "running", "ipv4": "192.168.1.1", "cpu": 1, "mem": 1024, "disk": 25, "image": "Debian 10", "tariff_name": "Standard SSD 1 vCPU", "price": "5.00/period", "expired": "2024-12-31T23:59:59Z", "autoprolong": true } ] ``` ``` -------------------------------- ### Fetch Data Center List Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Retrieves a list of all available data centers with their configurations, pricing, and resource limits. Iterates through the list to print details. ```python async with client as c: data_centers = await c.get_dc_list() if data_centers: for dc in data_centers: print(f"Data Center: {dc.dc_name}") print(f" Location: {dc.city}, {dc.country}") print(f" CPU: {dc.cpu_name} @ {dc.frequency}") print(f" Pricing - Core: {dc.core_price}, RAM: {dc.ram_price}, Disk: {dc.disk_price}") print(f" Max Resources - Cores: {dc.max_core}, RAM: {dc.max_ram}MB, Disk: {dc.max_disk}GB") print(f" IPv6 Available: {dc.ipv6}") if dc.periods: for period in dc.periods: print(f" Period: {period.period} hours, Discount: {period.discount}%") ``` -------------------------------- ### Purchase Server Backup Service Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Purchases a backup service for a server, selecting from available backup periods. It first retrieves available periods and then activates the service. ```python async with client as c: server_id = 98104 # Get available backup periods first periods = await c.get_backup_periods() selected_period = periods[0].period success = await c.buy_backup(server_id, selected_period) if success: print(f"Backup service activated for server {server_id}") ``` -------------------------------- ### List User's Servers Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Lists all servers owned by the authenticated user, including their status and configuration details. No parameters are required. ```python async with client as c: servers = await c.my_servers() if servers: for server in servers: print(f"Server ID: {server.server_id}") print(f" Name: {server.name}") print(f" Status: {server.status}") print(f" IP: {server.ipv4}") print(f" Config: {server.cpu} CPU, {server.mem}MB RAM, {server.disk}GB Disk") print(f" OS Image: {server.image}") print(f" Tariff: {server.tariff_name} @ {server.price}/period") print(f" Expires: {server.expired}") print(f" Auto-prolong: {server.autoprolong}") ``` -------------------------------- ### Change Server Tariff Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Upgrades or changes a server to a different tariff preset. First retrieves available upgrade options, then applies the chosen preset. ```python async with client as c: server_id = 98104 # Get available upgrade presets first upgrades = await c.get_available_upgrade_presets(server_id) for upgrade in upgrades: print(f"Upgrade option: {upgrade.name_full}") print(f" Price: {upgrade.price}") print(f" CPU: {upgrade.cpu_number}, RAM: {upgrade.ram}GB, Disk: {upgrade.rom}GB") # Apply the upgrade new_preset_id = upgrades[0].id success = await c.change_tariff(server_id, new_preset_id) if success: print(f"Server upgraded to preset {new_preset_id}") ``` -------------------------------- ### Manual Session Management Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Shows how to manage the client's session manually by calling the close() method when session management is not handled by a context manager. ```APIDOC ## Manual Session Management For cases where context manager is not suitable, manually manage the session lifecycle by calling close() when done. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "your_api_key_here" client = FourVpsClient(API_KEY) async def main(): try: balance = await client.user_balance() print(f"Balance: {balance}") # Output: 11205.9 finally: await client.close() asyncio.run(main()) ``` ``` -------------------------------- ### Extend Server Rental Period Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Extends the rental period for a specified server. Returns True upon successful extension. ```python async with client as c: server_id = 98104 success = await c.continue_server(server_id) if success: print(f"Server {server_id} rental period extended") ``` -------------------------------- ### Error Handling Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Demonstrates how to handle various API errors using specific exception types. ```APIDOC ## Error Handling The library provides specific exception types for common API errors, allowing precise error handling in your applications. ### Exception Types - **AuthenticationError**: Raised when authentication fails. - **NotEnoughMoney**: Raised when the user has insufficient funds. - **ServerNotFound**: Raised when the specified server is not found. - **TariffNotAvailable**: Raised when the requested tariff plan is not available. - **DataCenterNotAvailable**: Raised when the specified data center is not available. - **NeedVerification**: Raised when the user account requires verification. - **MaximumNumberOfIpAddresses**: Raised when the maximum number of IP addresses has been reached. - **ServerCannotBeTurnedOn**: Raised when the server cannot be turned on. - **ServerStoppedByAdministrator**: Raised when the server has been stopped by an administrator. - **CannotChangeToThisTariffPlan**: Raised when it's not possible to change to the specified tariff plan. - **IncorrectBackupPeriod**: Raised when an incorrect backup period is provided. ### Request Example ```python from FourVps.api import FourVpsClient from FourVps.exceptions.errors import ( AuthenticationError, NotEnoughMoney, ServerNotFound, TariffNotAvailable, DataCenterNotAvailable, NeedVerification, MaximumNumberOfIpAddresses, ServerCannotBeTurnedOn, ServerStoppedByAdministrator, CannotChangeToThisTariffPlan, IncorrectBackupPeriod ) import asyncio async def main(): client = FourVpsClient("your_api_key") try: async with client as c: server = await c.buy_server( tariff_id=123, datacenter_id=1, ostempl_id=3, server_name="my-server" ) print(f"Server created: {server.server_id}") except AuthenticationError as e: print(f"Authentication failed: {e}") except NotEnoughMoney as e: print(f"Insufficient funds: {e}") except ServerNotFound as e: print(f"Server not found: {e}") except TariffNotAvailable as e: print(f"Tariff unavailable: {e}") except DataCenterNotAvailable as e: print(f"Data center unavailable: {e}") except NeedVerification as e: print(f"Account verification required: {e}") except MaximumNumberOfIpAddresses as e: print(f"IP limit reached: {e}") asyncio.run(main()) ``` ``` -------------------------------- ### Retrieve User Balance Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Fetches the current account balance. Returns the balance as a float representing available funds. ```python async with client as c: balance = await c.user_balance() print(f"Account balance: {balance}") # Output: 11625.9 ``` -------------------------------- ### List Server IP Addresses Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Lists all IP addresses assigned to a specific server, including their ID, name, IP address, and PTR record status. ```python async with client as c: server_id = 98104 ips = await c.ip_list(server_id) if ips: for ip in ips: print(f"IP ID: {ip.id}") print(f" Name: {ip.name}") print(f" Address: {ip.ip}") print(f" PTR Record: {ip.ptr}") ``` -------------------------------- ### Change Server Specifications Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Modifies server specifications like CPU, RAM, and disk size within allowed limits. RAM is in MB and disk in GB. ```python async with client as c: server_id = 98104 success = await c.change_spec( server_id=server_id, cpu_count=4, ram_count=8192, # in MB rom_count=100 # in GB ) if success: print("Server specifications updated") ``` -------------------------------- ### Purchase Backup Service Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Purchases a backup service for a server with the specified period. ```APIDOC ## Purchase Backup Service ### Description Purchases a backup service for a server with the specified period. ### Method POST (Assumed, based on action) ### Endpoint `/servers/{server_id}/backup/buy` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to purchase backup for. #### Request Body - **period** (integer) - Required - The backup period in hours. ### Request Example ```json { "period": 24 } ``` ### Response #### Success Response (200) - **success** (boolean) - True if the backup service was purchased successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Purchase Additional IP Addresses Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Purchases additional IP addresses for a server. ```APIDOC ## Purchase Additional IP Addresses ### Description Purchases additional IP addresses for a server. ### Method POST (Assumed, based on action) ### Endpoint `/servers/{server_id}/ips/buy` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to purchase IPs for. #### Request Body - **count** (integer) - Required - The number of IP addresses to purchase. ### Request Example ```json { "count": 2 } ``` ### Response #### Success Response (200) - **success** (boolean) - True if the IP addresses were purchased successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Manage FourVpsClient Session Manually Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt For cases where the context manager is not suitable, manually manage the session lifecycle by calling close() when done. ```python from FourVps.api import FourVpsClient import asyncio API_KEY = "your_api_key_here" client = FourVpsClient(API_KEY) async def main(): try: balance = await client.user_balance() print(f"Balance: {balance}") # Output: 11205.9 finally: await client.close() asyncio.run(main()) ``` -------------------------------- ### Extend Server Rental Period Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Extends the rental period for a server. Returns True if successful. ```APIDOC ## Extend Server Rental Period ### Description Extends the rental period for a server. ### Method POST (Assumed, based on action) ### Endpoint `/servers/{server_id}/continue` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to extend. ### Response #### Success Response (200) - **success** (boolean) - True if the rental period was extended successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Power On Server Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Powers on a stopped server. Returns True if the operation was successful. ```APIDOC ## power_on ### Description Powers on a stopped server. Returns True if the operation was successful. ### Method POST ### Endpoint /api/v1/servers/{server_id}/power_on ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to power on. ### Response #### Success Response (200) - **success** (boolean) - True if the server was successfully powered on, False otherwise. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Power On Server Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Powers on a stopped server. Returns True if the operation was successful. Requires the server ID. ```python async with client as c: server_id = 98104 success = await c.power_on(server_id) if success: print(f"Server {server_id} is starting up") else: print("Failed to power on server") ``` -------------------------------- ### Purchase Additional IP Addresses Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Purchases a specified number of additional IP addresses for a server. After purchase, it lists the updated IP addresses. ```python async with client as c: server_id = 98104 count = 2 # Number of IPs to purchase success = await c.buy_ip(server_id, count) if success: print(f"Successfully purchased {count} additional IP(s) for server {server_id}") # List the updated IP addresses ips = await c.ip_list(server_id) for ip in ips: print(f" {ip.ip}") ``` -------------------------------- ### List Server IP Addresses Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Lists all IP addresses assigned to a specific server. ```APIDOC ## List Server IP Addresses ### Description Lists all IP addresses assigned to a specific server. ### Method GET ### Endpoint `/servers/{server_id}/ips` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to list IPs for. ### Response #### Success Response (200) - **ips** (array) - A list of IP addresses assigned to the server. - **id** (integer) - The ID of the IP address. - **name** (string) - The name of the IP address. - **ip** (string) - The IP address. - **ptr** (string) - The PTR record for the IP address. #### Response Example ```json [ { "id": 12345, "name": "Primary IP", "ip": "192.168.1.100", "ptr": "server.example.com" } ] ``` ``` -------------------------------- ### Delete Server Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Permanently deletes a server. This action is irreversible. ```python async with client as c: server_id = 98104 success = await c.delete_server(server_id) if success: print(f"Server {server_id} has been deleted") ``` -------------------------------- ### Change Server Tariff Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Upgrades or changes the server to a different tariff preset. ```APIDOC ## Change Server Tariff ### Description Upgrades or changes the server to a different tariff preset. ### Method PUT (Assumed, based on action) ### Endpoint `/servers/{server_id}/tariff` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to change the tariff for. #### Request Body - **new_preset_id** (integer) - Required - The ID of the new upgrade preset. ### Request Example ```json { "new_preset_id": 123 } ``` ### Response #### Success Response (200) - **success** (boolean) - True if the server tariff was changed successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Change Server Specifications Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Modifies the server specifications (CPU, RAM, disk) within the allowed limits. ```APIDOC ## Change Server Specifications ### Description Modifies the server specifications (CPU, RAM, disk) within the allowed limits. ### Method PUT (Assumed, based on action) ### Endpoint `/servers/{server_id}/specifications` (Assumed) ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to modify. #### Request Body - **cpu_count** (integer) - Optional - The desired number of CPU cores. - **ram_count** (integer) - Optional - The desired amount of RAM in MB. - **rom_count** (integer) - Optional - The desired amount of disk space in GB. ### Request Example ```json { "cpu_count": 4, "ram_count": 8192, "rom_count": 100 } ``` ### Response #### Success Response (200) - **success** (boolean) - True if the server specifications were updated successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Reboot Server Source: https://context7.com/0011101000101001/aio4vpsapi/llms.txt Reboots a running server. Returns True if the operation was successful. ```APIDOC ## reboot ### Description Reboots a running server. Returns True if the operation was successful. ### Method POST ### Endpoint /api/v1/servers/{server_id}/reboot ### Parameters #### Path Parameters - **server_id** (integer) - Required - The ID of the server to reboot. ### Response #### Success Response (200) - **success** (boolean) - True if the server was successfully rebooted, False otherwise. #### Response Example ```json { "success": true } ``` ```