pax_global_header00006660000000000000000000000064146501763760014531gustar00rootroot0000000000000052 comment=901f99227971287648fdfa4134aac95bddf19c5b python-vultr-1.0.1/000077500000000000000000000000001465017637600142235ustar00rootroot00000000000000python-vultr-1.0.1/.gitignore000066400000000000000000000000701465017637600162100ustar00rootroot00000000000000build dist Include Lib Scripts *.egg-info *.pyc venv python-vultr-1.0.1/.travis.yml000066400000000000000000000002451465017637600163350ustar00rootroot00000000000000language: python python: - "2.7" - "3.3" - "3.4" - "3.5" - "nightly" install: - "pip install ." script: "python setup.py develop && python setup.py test"python-vultr-1.0.1/CONTRIBUTING.md000066400000000000000000000034551465017637600164630ustar00rootroot00000000000000# Vultr Vultr is a client library for the Vultr API. ## Bug Reports Please report bugs through the github issue queue. When reporting a bug please include a code sample, describe the behavior you expect, and the behavior you're observing. ## Contributing Code Vultr is maintained on Github. Changes should be submitted as pull requests rebased on the latest master. ## Becoming a Maintainer Please send an email to darrel.opry@spry-group.com if you are interested in becoming a maintainer. Like all open source projects, the more hands the merrier. ## Development ``` # dependencies pip install -r requirements.txt # development dependencies pip install setuptools virtualenv pep8 wheel twine ``` When makeing commit messages please follow the [Angular Git Commit Guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) ## Testing Tests spawn and destroy instances labelled 'python-vultr: test' I highly recommend you setup a Vultr account specifically for integration testing with this library to avoid unintentionally destroying servers you need. Be sure to clean up your Vultr account when done. ``` python setup.py test ``` ## Release Process Releases are tracked by creating a pull request from master to release. Ensure the version has been properly upticked before creating the release candidate pull request. The merged commit should be tagged with the proper version and built and uploaded to pypi. Currently the release process is manual. Once a more mature testing suite in place, it should be automated with TravisCI. ``` rm -rf dist/ python setup.py sdist python setup.py bdist_wheel twine upload -r pypi .\dist\vultr* ``` based on: [Sharing Your Labor of Love: PyPI Quick and Dirty](https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/) python-vultr-1.0.1/LICENSE000066400000000000000000000020761465017637600152350ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2018 The Spry Group, LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.python-vultr-1.0.1/MANIFEST.in000066400000000000000000000000251465017637600157560ustar00rootroot00000000000000include *.rst LICENSEpython-vultr-1.0.1/README.md000066400000000000000000000072341465017637600155100ustar00rootroot00000000000000# Vultr [![build status](https://travis-ci.org/spry-group/python-vultr.svg?branch=master)](https://travis-ci.org/spry-group/python-vultr) Vultr provides a client library to the [Vultr.com](http://www.vultr.com/?ref=6989379-3B) API. ## Usage ```python api_key = 'XXXXXXXXX' vultr = Vultr(api_key) plans_json = vultr.plans.list() ``` ## Testing From the repo root directory Performs generic, unauthenticated tests ```shell python -m unittest -v tests.test_vultr.UnauthenticatedTests ``` Requires the environment variable VULTR_KEY to be set ```shell python -m unittest -v tests.test_vultr.AuthenticatedTests ``` ## Support Python Vultr is supported on a volunteer basis. * [Open an Issue](https://github.com/spry-group/python-vultr/issues/new) * [![Gitter.im](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/spry-group/python-vultr) ## API * def account.info(self, params=None): * def app.list(self, params=None): * def backup.list(self, params=None): * def dns.create_domain(self, domain, ipaddr, params=None): * def dns.create_record(self, domain, name, _type, data, params=None): * def dns.delete_domain(self, domain, params=None): * def dns.delete_record(self, domain, recordid, params=None): * def dns.list(self, params=None): * def dns.records(self, domain, params=None): * def dns.update_record(self, domain, recordid, params=None): * def iso.list(self, params=None): * def iso.create_from_url(self, url, params=None) * def os.list(self, params=None): * def plans.list(self, params=None): * def regions.availability(self, dcid, params=None): * def regions.list(self, params=None): * def server.ipv4.create(self, subid, params=None): * def server.ipv4.destroy(self, subid, ipaddr, params=None): * def server.ipv4.list(self, subid, params=None): * def server.ipv4.reverse_default(self, subid, ipaddr, params=None): * def server.ipv4.reverse_set(self, subid, ipaddr, entry, params=None): * def server.ipv6.list_ipv6(self, subid, params=None): * def server.ipv6.reverse_delete_ipv6(self, subid, ipaddr, params=None): * def server.ipv6.reverse_list_ipv6(self, subid, params=None): * def server.ipv6.reverse_set_ipv6(self, subid, ipaddr, entry, params=None): * def server.bandwidth(self, subid, params=None): * def server.create(self, dcid, vpsplanid, osid, params=None): * def server.destroy(self, subid, params=None): * def server.get_user_data(self, subid, params=None): * def server.halt(self, subid, params=None): * def server.label_set(self, subid, label, params=None): * def server.list(self, subid=None, params=None): * def server.neighbors(self, subid, params=None): * def server.os_change(self, subid, osid, params=None): * def server.os_change_list(self, subid, params=None): * def server.reboot(self, subid, params=None): * def server.reinstall(self, subid, params=None): * def server.restore_backup(self, subid, backupid, params=None): * def server.restore_snapshot(self, subid, snapshotid, params=None): * def server.set_user_data(self, subid, userdata, params=None): * def server.start(self, subid, params=None): * def server.upgrade_plan(self, subid, vpsplanid, params=None): * def server.upgrade_plan_list(self, subid, params=None): * def snapshot.create(self, subid, params=None): * def snapshot.destroy(self, snapshotid, params=None): * def snapshot.list(self, params=None): * def sshkey.create(self, name, ssh_key, params=None): * def sshkey.destroy(self, sshkeyid, params=None): * def sshkey.list(self, params=None): * def sshkey.update(self, sshkeyid, params=None): * def startupscript.create(self, name, script, params=None): * def startupscript.destroy(self, scriptid, params=None): * def startupscript.list(self, params=None): * def startupscript.update(self, scriptid, params=None): python-vultr-1.0.1/examples/000077500000000000000000000000001465017637600160415ustar00rootroot00000000000000python-vultr-1.0.1/examples/basic_list.py000066400000000000000000000040311465017637600205250ustar00rootroot00000000000000#!/usr/bin/env python '''Basic app to list Vultr account & server information''' import logging from os import environ from json import dumps from vultr import Vultr, VultrError # Looks for an environment variable named "VULTR_KEY" API_KEY = environ.get('VULTR_KEY') logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s [%(funcName)s():%(lineno)d] %(message)s' ) logging.getLogger("requests").setLevel(logging.WARNING) def dump_info(): '''Shows various details about the account & servers''' vultr = Vultr(API_KEY) try: logging.info('Listing account info:\n%s', dumps( vultr.account.info(), indent=2 )) logging.info('Listing apps:\n%s', dumps( vultr.app.list(), indent=2 )) logging.info('Listing backups:\n%s', dumps( vultr.backup.list(), indent=2 )) logging.info('Listing DNS:\n%s', dumps( vultr.dns.list(), indent=2 )) logging.info('Listing ISOs:\n%s', dumps( vultr.iso.list(), indent=2 )) logging.info('Listing OSs:\n%s', dumps( vultr.os.list(), indent=2 )) logging.info('Listing plans:\n%s', dumps( vultr.plans.list(), indent=2 )) logging.info('Listing regions:\n%s', dumps( vultr.regions.list(), indent=2 )) logging.info('Listing servers:\n%s', dumps( vultr.server.list(), indent=2 )) logging.info('Listing snapshots:\n%s', dumps( vultr.snapshot.list(), indent=2 )) logging.info('Listing SSH keys:\n%s', dumps( vultr.sshkey.list(), indent=2 )) logging.info('Listing startup scripts:\n%s', dumps( vultr.startupscript.list(), indent=2 )) except VultrError as ex: logging.error('VultrError: %s', ex) def main(): '''Entry point''' logging.info('Vultr API Client Python Library') logging.info('URL: https://www.vultr.com/api/') dump_info() main() python-vultr-1.0.1/requirements.txt000066400000000000000000000002421465017637600175050ustar00rootroot00000000000000˙ūcertifi==2018.4.16 chardet==3.0.4 idna==2.6 requests==2.18.4 urllib3==1.22 python-vultr-1.0.1/setup.cfg000066400000000000000000000000721465017637600160430ustar00rootroot00000000000000[bdist_wheel] universal=1 [metadata] license_file=LICENSEpython-vultr-1.0.1/setup.py000066400000000000000000000024051465017637600157360ustar00rootroot00000000000000'''Module setup''' from setuptools import setup ''' packaging modeled after https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/ ''' def read(filename): '''Read content from file''' return open(filename).read() setup( name='vultr', version='1.0.1', install_requires=[ "requests" ], description='Vultr.com API Client', long_description=(read('README.md')), long_description_content_type='text/markdown', url='http://github.com/spry-group/python-vultr', author='Darrel O\'Pry', author_email='darrel.opry@spry-group.com', packages=['vultr'], classifiers=[ 'Intended Audience :: Developers', 'Natural Language :: English', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Topic :: Software Development :: Libraries :: Python Modules' ], license=read('LICENSE'), test_suite='tests' ) python-vultr-1.0.1/tests/000077500000000000000000000000001465017637600153655ustar00rootroot00000000000000python-vultr-1.0.1/tests/__init__.py000066400000000000000000000001301465017637600174700ustar00rootroot00000000000000from .test_vultr import UnauthenticatedTests from .test_vultr import AuthenticatedTests python-vultr-1.0.1/tests/test_vultr.py000066400000000000000000000074031465017637600201560ustar00rootroot00000000000000'''Tests for the Vultr cloud API client library''' import unittest import os from time import sleep import warnings import pprint from vultr import Vultr, VultrError VULTR_TEST_LABEL = 'python-vultr: test' class UnauthenticatedTests(unittest.TestCase): '''Tests without authentication (no VULTR_KEY)''' def setUp(self): self.vultr = Vultr('') def test_plans_list(self): '''List plans''' self.vultr.plans.list() def test_regions_list(self): '''List regions''' self.vultr.regions.list() def test_os_list(self): '''List operating systems''' self.vultr.os.list() def test_app_list(self): '''List applications''' self.vultr.app.list() @unittest.skipIf(not os.environ.get('VULTR_KEY'), 'Skipping AuthenticatedTests') class AuthenticatedTests(unittest.TestCase): '''Tests with authentication (VULTR_KEY)''' @classmethod def setUpClass(cls): cls.VULTR_KEY = os.environ.get('VULTR_KEY') cls.vultr = Vultr(cls.VULTR_KEY) cls.server_list = {} def test_backup_list(self): '''List backups''' self.vultr.backup.list() def test_dns_list(self): '''List DNS records''' self.vultr.dns.list() def test_firewall_group_list(self): '''List firewall groups''' self.vultr.firewall.group_list() def test_iso_list(self): '''List ISOs / images''' self.vultr.iso.list() def test_snapshot_list(self): '''List snapshots''' self.vultr.snapshot.list() def test_sshkey_list(self): '''List SSH public keys''' self.vultr.sshkey.list() def test_startupscript_list(self): '''List startup scripts''' self.vultr.startupscript.list() def test_label_set(self): '''Set an instance label''' try: self.vultr.server.label_set('', '') except VultrError as ex: msg = str(ex) self.assertEqual( msg, 'Request failed. Check the response body ' 'for a more detailed description. Body: ' '\nInvalid server. Check SUBID value and ' 'ensure your API key matches the server\'s account') def test_account_info(self): '''Get account information''' self.vultr.account.info() def test_server_create(self): '''Create a server instance (this will take 5-10 minutes)''' response = self.vultr.server.create( 1, # DCID (New Jersey, USA) 29, # VPSPLANID (768 MB RAM,15 GB SSD,1.00 TB BW) 216, # OSID (Ubuntu 16.04 i386) { 'label': VULTR_TEST_LABEL } ) warnings.warn('Creating VM: {0}' '\n This will cost money.' '\n Sleeping for 5 minutes...' . format(response)) sleep(300) def test_server_list(self): '''List servers''' AuthenticatedTests.server_list = self.vultr.server.list() def test_server_list_by_subid(self): '''List server by SUBID''' for subid in AuthenticatedTests.server_list: self.vultr.server.list(subid=subid) def test_server_destroy(self): '''Destroy a server instance''' servers = self.vultr.server.list() for subid in servers: # skip machines not made by tests. if servers[subid]['label'] != VULTR_TEST_LABEL: warnings.warn('skipping [{0}]:\n{1}' . format(subid, str(servers[subid]))) continue self.vultr.server.destroy(subid) warnings.warn('Destroying VM: {0}' . format(subid)) if __name__ == '__main__': unittest.main() python-vultr-1.0.1/vultr/000077500000000000000000000000001465017637600153775ustar00rootroot00000000000000python-vultr-1.0.1/vultr/__init__.py000066400000000000000000000001741465017637600175120ustar00rootroot00000000000000'''Vultr cloud API client library''' from .vultr import Vultr from .utils import VultrError assert Vultr assert VultrError python-vultr-1.0.1/vultr/utils.py000066400000000000000000000072211465017637600171130ustar00rootroot00000000000000'''Helper classes''' import requests import time import json as json_module API_ENDPOINT = 'https://api.vultr.com' class VultrError(RuntimeError): '''Vultr custom exception''' pass class VultrBase(object): '''Base class for Vultr inheritance''' def __init__(self, api_key): self.api_endpoint = API_ENDPOINT self.api_key = api_key self.set_requests_per_second(1) def set_requests_per_second(self, req_per_second): '''Adjusts the request/second at run-time''' self.req_per_second = req_per_second self.req_duration = 1 / self.req_per_second def _request_get_helper(self, url, params=None): '''API GET request helper''' if not isinstance(params, dict): params = dict() if self.api_key: params['api_key'] = self.api_key return requests.get(url, params=params, timeout=60) def _request_post_helper(self, url, params=None): '''API POST helper''' if self.api_key: query = {'api_key': self.api_key} return requests.post(url, params=query, data=params, timeout=60) def _request_helper(self, url, params, method): '''API request helper method''' try: if method == 'POST': return self._request_post_helper(url, params) elif method == 'GET': return self._request_get_helper(url, params) raise VultrError('Unsupported method %s' % method) except requests.RequestException as ex: raise RuntimeError(ex) def request(self, path, params=None, method='GET'): '''API request / call method''' _start = time.time() if not path.startswith('/'): path = '/' + path resp = self._request_helper(self.api_endpoint + path, params, method) if resp.status_code != 200: if resp.status_code == 400: raise VultrError('Invalid API location. Check the URL that' + ' you are using') elif resp.status_code == 403: raise VultrError('Invalid or missing API key. Check that' + ' your API key is present and matches' + ' your assigned key') elif resp.status_code == 405: raise VultrError('Invalid HTTP method. Check that the' + ' method (POST|GET) matches what the' + ' documentation indicates') elif resp.status_code == 412: raise VultrError('Request failed. Check the response body ' + 'for a more detailed description. Body: \n' + resp.text) elif resp.status_code == 500: raise VultrError('Internal server error. Try again at a' + ' later time') elif resp.status_code == 503: raise VultrError('Rate limit hit. API requests are limited' + ' to an average of 1/s. Try your request' + ' again later.') # very simplistic synchronous rate limiting; _elapsed = time.time() - _start if _elapsed < self.req_duration: time.sleep(self.req_duration - _elapsed) # return an empty json object if the API doesn't respond with a value. return resp.json() if resp.text else json_module.loads('{}') def update_params(params, updates): '''Merges updates into params''' params = params.copy() if isinstance(params, dict) else dict() params.update(updates) return params python-vultr-1.0.1/vultr/v1_account.py000066400000000000000000000010451465017637600200130ustar00rootroot00000000000000'''Partial class to handle Vultr Account API calls''' from .utils import VultrBase class VultrAccount(VultrBase): '''Handles Vultr Account API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def info(self, params=None): ''' /v1/account/info GET - account Retrieve information about the current account Link: https://www.vultr.com/api/#account_info ''' params = params if params else dict() return self.request('/v1/account/info', params, 'GET') python-vultr-1.0.1/vultr/v1_app.py000066400000000000000000000011511465017637600171350ustar00rootroot00000000000000'''Partial class to handle Vultr App API calls''' from .utils import VultrBase class VultrApp(VultrBase): '''Handles Vultr App API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def list(self, params=None): ''' /v1/app/list GET - account Retrieve a list of available applications. These refer to applications that can be launched when creating a Vultr VPS. Link: https://www.vultr.com/api/#app_app_list ''' params = params if params else dict() return self.request('/v1/app/list', params, 'GET') python-vultr-1.0.1/vultr/v1_backup.py000066400000000000000000000010371465017637600176250ustar00rootroot00000000000000'''Partial class to handle Vultr Backup API calls''' from .utils import VultrBase class VultrBackup(VultrBase): '''Handles Vultr Backup API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def list(self, params=None): ''' /v1/backup/list GET - account List all backups on the current account Link: https://www.vultr.com/api/#backup_backup_list ''' params = params if params else dict() return self.request('/v1/backup/list', params, 'GET') python-vultr-1.0.1/vultr/v1_dns.py000066400000000000000000000055651465017637600171560ustar00rootroot00000000000000'''Partial class to handle Vultr DNS API calls''' from .utils import VultrBase, update_params class VultrDNS(VultrBase): '''Handles Vultr DNS API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def create_domain(self, domain, ipaddr, params=None): ''' /v1/dns/create_domain POST - account Create a domain name in DNS Link: https://www.vultr.com/api/#dns_create_domain ''' params = update_params(params, { 'domain': domain, 'ip': ipaddr }) return self.request('/v1/dns/create_domain', params, 'POST') def create_record(self, domain, name, _type, data, params=None): ''' /v1/dns/create_domain POST - account Add a DNS record Link: https://www.vultr.com/api/#dns_create_record ''' params = update_params(params, { 'domain': domain, 'name': name, 'type': _type, 'data': data }) return self.request('/v1/dns/create_record', params, 'POST') def delete_domain(self, domain, params=None): ''' /v1/dns/delete_domain POST - account Delete a domain name (and all associated records) Link: https://www.vultr.com/api/#dns_delete_domain ''' params = update_params(params, {'domain': domain}) return self.request('/v1/dns/delete_domain', params, 'POST') def delete_record(self, domain, recordid, params=None): ''' /v1/dns/delete_record POST - account Deletes an individual DNS record Link: https://www.vultr.com/api/#dns_delete_record ''' params = update_params(params, { 'domain': domain, 'RECORDID': recordid }) return self.request('/v1/dns/delete_record', params, 'POST') def list(self, params=None): ''' /v1/dns/list GET - account List all domains associated with the current account Link: https://www.vultr.com/api/#dns_dns_list ''' params = params if params else dict() return self.request('/v1/dns/list', params, 'GET') def records(self, domain, params=None): ''' /v1/dns/records GET - account List all the records associated with a particular domain Link: https://www.vultr.com/api/#dns_records ''' params = update_params(params, {'domain': domain}) return self.request('/v1/dns/records', params, 'GET') def update_record(self, domain, recordid, params=None): ''' /v1/dns/update_record POST - account Update a DNS record Link: https://www.vultr.com/api/#dns_update_record ''' params = update_params(params, { 'domain': domain, 'RECORDID': recordid }) return self.request('/v1/dns/update_record', params, 'POST') python-vultr-1.0.1/vultr/v1_firewall.py000066400000000000000000000011051465017637600201610ustar00rootroot00000000000000'''Partial class to handle Vultr Firewall API calls''' from .utils import VultrBase class VultrFirewall(VultrBase): '''Handles Vultr Firewall API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def group_list(self, params=None): ''' /v1/firewall/group_list GET - account List all firewall groups on the current account. Link: https://www.vultr.com/api/#firewall_group_list ''' params = params if params else dict() return self.request('/v1/firewall/group_list', params, 'GET') python-vultr-1.0.1/vultr/v1_iso.py000066400000000000000000000020421465017637600171470ustar00rootroot00000000000000'''Partial class to handle Vultr ISO API calls''' from .utils import VultrBase, update_params class VultrISO(VultrBase): '''Handles Vultr ISO API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def list(self, params=None): ''' /v1/iso/list GET - account List all ISOs currently available on this account Link: https://www.vultr.com/api/#iso_iso_list ''' params = params if params else dict() return self.request('/v1/iso/list', params, 'GET') def create_from_url(self, url, params=None): ''' /vi/iso/create_from_url POST - account Create a new ISO image on the current account. The ISO image will be downloaded from a given URL. Download status can be checked with the v1/iso/list call. Link: https://www.vultr.com/api/#iso_create_from_url ''' params = update_params(params, { 'url': url, }) return self.request('/v1/iso/create_from_url', params, 'POST') python-vultr-1.0.1/vultr/v1_os.py000066400000000000000000000012161465017637600170000ustar00rootroot00000000000000'''Partial class to handle Vultr OS API calls''' from .utils import VultrBase class VultrOS(VultrBase): '''Handles Vultr OS API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def list(self, params=None): ''' /v1/os/list GET - public Retrieve a list of available operating systems. If the 'windows' flag is true, a Windows licenses will be included with the instance, which will increase the cost. Link: https://www.vultr.com/api/#os_os_list ''' params = params if params else dict() return self.request('/v1/os/list', params, 'GET') python-vultr-1.0.1/vultr/v1_plans.py000066400000000000000000000016511465017637600174770ustar00rootroot00000000000000'''Partial class to handle Vultr Plans API calls''' from .utils import VultrBase class VultrPlans(VultrBase): '''Handles Vultr Plans API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def list(self, params=None): ''' /v1/plans/list GET - public Retrieve a list of all active plans. Plans that are no longer available will not be shown. The 'windows' field is no longer in use, and will always be false. Windows licenses will be automatically added to any plan as necessary. If your account has special plans available, you will need to pass your api_key in in order to see them. For all other accounts, the API key is not optional. Link: https://www.vultr.com/api/#plans_plan_list ''' params = params if params else dict() return self.request('/v1/plans/list', params, 'GET') python-vultr-1.0.1/vultr/v1_regions.py000066400000000000000000000023411465017637600200250ustar00rootroot00000000000000'''Partial class to handle Vultr Regions API calls''' from .utils import VultrBase, update_params class VultrRegions(VultrBase): '''Handles Vultr Regions API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def availability(self, dcid, params=None): ''' /v1/regions/availability GET - public Retrieve a list of the VPSPLANIDs currently available in this location. If your account has special plans available, you will need to pass your api_key in in order to see them. For all other accounts, the API key is not optional. Link: https://www.vultr.com/api/#regions_region_available ''' params = update_params(params, {'DCID': dcid}) return self.request('/v1/regions/availability', params, 'GET') def list(self, params=None): ''' /v1/regions/list GET - public Retrieve a list of all active regions. Note that just because a region is listed here, does not mean that there is room for new servers. Link: https://www.vultr.com/api/#regions_region_list ''' params = params if params else dict() return self.request('/v1/regions/list', params, 'GET') python-vultr-1.0.1/vultr/v1_reservedip.py000066400000000000000000000013471465017637600205340ustar00rootroot00000000000000'''Partial class to handle Vultr ReservedIP API calls''' from .utils import VultrBase, update_params class VultrReservedIP(VultrBase): '''Handles Vultr ReservedIP API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def create(self, dcid, ip_type, params=None): ''' /v1/reservedip/create POST - account Create a new reserved IP. Reserved IPs can only be used within the same datacenter for which they were created. Link: https://www.vultr.com/api/#reservedip_create ''' params = update_params(params, { 'DCID': dcid, 'ip_type': ip_type }) return self.request('/v1/reservedip/create', params, 'POST') python-vultr-1.0.1/vultr/v1_server.py000066400000000000000000000216641465017637600176760ustar00rootroot00000000000000'''Partial class to handle Vultr Server API calls''' from .utils import VultrBase, update_params from .v1_server_ipv4 import VultrServerIPv4 from .v1_server_ipv6 import VultrServerIPv6 class VultrServer(VultrBase): '''Handles Vultr Server API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) self.ipv4 = VultrServerIPv4(api_key) self.ipv6 = VultrServerIPv6(api_key) def bandwidth(self, subid, params=None): ''' /v1/server/bandwidth GET - account Get the bandwidth used by a virtual machine Link: https://www.vultr.com/api/#server_bandwidth ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/bandwidth', params, 'GET') def create(self, dcid, vpsplanid, osid, params=None): ''' /v1/server/create POST - account Create a new virtual machine. You will start being billed for this immediately. The response only contains the SUBID for the new machine. You should use v1/server/list to poll and wait for the machine to be created (as this does not happen instantly). Link: https://www.vultr.com/api/#server_create ''' params = update_params(params, { 'DCID': dcid, 'VPSPLANID': vpsplanid, 'OSID': osid }) return self.request('/v1/server/create', params, 'POST') def destroy(self, subid, params=None): ''' /v1/server/destroy POST - account Destroy (delete) a virtual machine. All data will be permanently lost, and the IP address will be released. There is no going back from this call. Link: https://www.vultr.com/api/#server_destroy ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/destroy', params, 'POST') def get_user_data(self, subid, params=None): ''' /v1/server/get_user_data GET - account Retrieves the (base64 encoded) user-data for this subscription. Link: https://www.vultr.com/api/#server_get_user_data ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/get_user_data', params, 'GET') def halt(self, subid, params=None): ''' /v1/server/halt POST - account Halt a virtual machine. This is a hard power off (basically, unplugging the machine). The data on the machine will not be modified, and you will still be billed for the machine. To completely delete a machine, see v1/server/destroy Link: https://www.vultr.com/api/#server_halt ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/halt', params, 'POST') def label_set(self, subid, label, params=None): ''' /v1/server/label_set POST - account Set the label of a virtual machine. Link: https://www.vultr.com/api/#server_label_set ''' params = update_params(params, { 'SUBID': subid, 'label': label }) return self.request('/v1/server/label_set', params, 'POST') def list(self, subid=None, params=None): ''' /v1/server/list GET - account List all active or pending virtual machines on the current account. The 'status' field represents the status of the subscription and will be one of pending|active|suspended|closed. If the status is 'active', you can check 'power_status' to determine if the VPS is powered on or not. The API does not provide any way to determine if the initial installation has completed or not. Link: https://www.vultr.com/api/#server_server_list ''' params = update_params( params, {'SUBID': subid} if subid else dict() ) return self.request('/v1/server/list', params, 'GET') def neighbors(self, subid, params=None): ''' v1/server/neighbors GET - account Determine what other subscriptions are hosted on the same physical host as a given subscription. Link: https://www.vultr.com/api/#server_neighbors ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/neighbors', params, 'GET') def os_change(self, subid, osid, params=None): ''' /v1/server/os_change POST - account Changes the operating system of a virtual machine. All data will be permanently lost. Link: https://www.vultr.com/api/#server_os_change ''' params = update_params(params, { 'SUBID': subid, 'OSID': osid }) return self.request('/v1/server/os_change', params, 'POST') def os_change_list(self, subid, params=None): ''' /v1/server/os_change_list GET - account Retrieves a list of operating systems to which this server can be changed. Link: https://www.vultr.com/api/#server_os_change_list ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/os_change_list', params, 'GET') def reboot(self, subid, params=None): ''' /v1/server/reboot POST - account Reboot a virtual machine. This is a hard reboot (basically, unplugging the machine). Link: https://www.vultr.com/api/#server_reboot ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/reboot', params, 'POST') def reinstall(self, subid, params=None): ''' /v1/server/reinstall POST - account Reinstall the operating system on a virtual machine. All data will be permanently lost, but the IP address will remain the same There is no going back from this call. Link: https://www.vultr.com/api/#server_reinstall ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/reinstall', params, 'POST') def restore_backup(self, subid, backupid, params=None): ''' /v1/server/restore_backup POST - account Restore the specified backup to the virtual machine. Any data already on the virtual machine will be lost. Link: https://www.vultr.com/api/#server_restore_backup ''' params = update_params(params, { 'SUBID': subid, 'BACKUPID': backupid }) return self.request('/v1/server/restore_backup', params, 'POST') def restore_snapshot(self, subid, snapshotid, params=None): ''' /v1/server/restore_snapshot POST - account Restore the specificed snapshot to the virtual machine. Any data already on the virtual machine will be lost. Link: https://www.vultr.com/api/#server_restore_snapshot ''' params = update_params(params, { 'SUBID': subid, 'SNAPSHOTID': snapshotid }) return self.request('/v1/server/restore_snapshot', params, 'POST') def set_user_data(self, subid, userdata, params=None): ''' /v1/server/set_user_data POST - account Sets the cloud-init user-data (base64) for this subscription. Note that user-data is not supported on every operating system, and is generally only provided on instance startup. Link: https://www.vultr.com/api/#server_set_user_data ''' params = update_params(params, { 'SUBID': subid, 'userdata': userdata }) return self.request('/v1/server/set_user_data', params, 'POST') def start(self, subid, params=None): ''' /v1/server/start POST - account Start a virtual machine. If the machine is already running, it will be restarted. Link: https://www.vultr.com/api/#server_start ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/start', params, 'POST') def upgrade_plan(self, subid, vpsplanid, params=None): ''' /v1/server/upgrade_plan POST - account Upgrade the plan of a virtual machine. The virtual machine will be rebooted upon a successful upgrade. Link: https://www.vultr.com/api/#server_upgrade_plan ''' params = update_params(params, { 'SUBID': subid, 'VPSPLANID': vpsplanid }) return self.request('/v1/server/upgrade_plan', params, 'POST') def upgrade_plan_list(self, subid, params=None): ''' /v1/server/upgrade_plan_list GET - account Retrieve a list of the VPSPLANIDs for which a virtual machine can be upgraded. An empty response array means that there are currently no upgrades available. Link: https://www.vultr.com/api/#server_upgrade_plan_list ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/upgrade_plan_list', params, 'GET') python-vultr-1.0.1/vultr/v1_server_ipv4.py000066400000000000000000000055271465017637600206400ustar00rootroot00000000000000'''Partial class to handle Vultr Server (IPv4) API calls''' from .utils import VultrBase, update_params class VultrServerIPv4(VultrBase): '''Handles Vultr Server (IPv4) API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def create(self, subid, params=None): ''' /v1/server/create_ipv4 POST - account Add a new IPv4 address to a server. You will start being billed for this immediately. The server will be rebooted unless you specify otherwise. You must reboot the server before the IPv4 address can be configured. Link: https://www.vultr.com/api/#server_create_ipv4 ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/create_ipv4', params, 'POST') def destroy(self, subid, ipaddr, params=None): ''' /v1/server/destroy_ipv4 POST - account Removes a secondary IPv4 address from a server. Your server will be hard-restarted. We suggest halting the machine gracefully before removing IPs. Link: https://www.vultr.com/api/#server_destroy_ipv4 ''' params = update_params(params, { 'SUBID': subid, 'ip': ipaddr }) return self.request('/v1/server/destroy_ipv4', params, 'POST') def list(self, subid, params=None): ''' /v1/server/list_ipv4 GET - account List the IPv4 information of a virtual machine. IP information is only available for virtual machines in the "active" state. Link: https://www.vultr.com/api/#server_list_ipv4 ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/list_ipv4', params, 'GET') def reverse_default(self, subid, ipaddr, params=None): ''' /v1/server/reverse_default_ipv4 POST - account Set a reverse DNS entry for an IPv4 address of a virtual machine to the original setting. Upon success, DNS changes may take 6-12 hours to become active. Link: https://www.vultr.com/api/#server_reverse_default_ipv4 ''' params = update_params(params, { 'SUBID': subid, 'ip': ipaddr }) return self.request('/v1/server/reverse_default_ipv4', params, 'POST') def reverse_set(self, subid, ipaddr, entry, params=None): ''' /v1/server/reverse_set_ipv4 POST - account Set a reverse DNS entry for an IPv4 address of a virtual machine. Upon success, DNS changes may take 6-12 hours to become active. Link: https://www.vultr.com/api/#server_reverse_set_ipv4 ''' params = update_params(params, { 'SUBID': subid, 'ip': ipaddr, 'entry': entry }) return self.request('/v1/server/reverse_set_ipv4', params, 'POST') python-vultr-1.0.1/vultr/v1_server_ipv6.py000066400000000000000000000046611465017637600206400ustar00rootroot00000000000000'''Partial class to handle Vultr Server (IPv6) API calls''' from .utils import VultrBase, update_params class VultrServerIPv6(VultrBase): '''Handles Vultr Server (IPv6) API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def list_ipv6(self, subid, params=None): ''' /v1/server/list_ipv6 GET - account List the IPv6 information of a virtual machine. IP information is only available for virtual machines in the "active" state. If the virtual machine does not have IPv6 enabled, then an empty array is returned. Link: https://www.vultr.com/api/#server_list_ipv6 ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/list_ipv6', params, 'GET') def reverse_delete_ipv6(self, subid, ipaddr, params=None): ''' /v1/server/reverse_delete_ipv6 POST - account Remove a reverse DNS entry for an IPv6 address of a virtual machine. Upon success, DNS changes may take 6-12 hours to become active. Link: https://www.vultr.com/api/#server_reverse_delete_ipv6 ''' params = update_params(params, { 'SUBID': subid, 'ip': ipaddr }) return self.request('/v1/server/reverse_delete_ipv6', params, 'POST') def reverse_list_ipv6(self, subid, params=None): ''' /v1/server/reverse_list_ipv6 GET - account List the IPv6 reverse DNS entries of a virtual machine. Reverse DNS entries are only available for virtual machines in the "active" state. If the virtual machine does not have IPv6 enabled, then an empty array is returned. Link: https://www.vultr.com/api/#server_reverse_list_ipv6 ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/server/reverse_list_ipv6', params, 'GET') def reverse_set_ipv6(self, subid, ipaddr, entry, params=None): ''' /v1/server/reverse_set_ipv6 POST - account Set a reverse DNS entry for an IPv6 address of a virtual machine. Upon success, DNS changes may take 6-12 hours to become active. Link: https://www.vultr.com/api/#server_reverse_set_ipv6 ''' params = update_params(params, { 'SUBID': subid, 'ip': ipaddr, 'entry': entry }) return self.request('/v1/server/reverse_set_ipv6', params, 'POST') python-vultr-1.0.1/vultr/v1_snapshot.py000066400000000000000000000025421465017637600202210ustar00rootroot00000000000000'''Partial class to handle Vultr Snapshot API calls''' from .utils import VultrBase, update_params class VultrSnapshot(VultrBase): '''Handles Vultr Snapshot API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def create(self, subid, params=None): ''' /v1/snapshot/create POST - account Create a snapshot from an existing virtual machine. The virtual machine does not need to be stopped. Link: https://www.vultr.com/api/#snapshot_create ''' params = update_params(params, {'SUBID': subid}) return self.request('/v1/snapshot/create', params, 'POST') def destroy(self, snapshotid, params=None): ''' /v1/snapshot/destroy POST - account Destroy (delete) a snapshot. There is no going back from this call. Link: https://www.vultr.com/api/#snapshot_destroy ''' params = update_params(params, {'SNAPSHOTID': snapshotid}) return self.request('/v1/snapshot/destroy', params, 'POST') def list(self, params=None): ''' /v1/snapshot/list GET - account List all snapshots on the current account Link: https://www.vultr.com/api/#snapshot_snapshot_list ''' params = params if params else dict() return self.request('/v1/snapshot/list', params, 'GET') python-vultr-1.0.1/vultr/v1_sshkey.py000066400000000000000000000034141465017637600176670ustar00rootroot00000000000000'''Partial class to handle Vultr SSH Key API calls''' from .utils import VultrBase, update_params class VultrSSHKey(VultrBase): '''Handles Vultr SSH Key API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def create(self, name, ssh_key, params=None): ''' /v1/sshkey/create POST - account Create a new SSH Key Link: https://www.vultr.com/api/#sshkey_create ''' params = update_params(params, { 'name': name, 'ssh_key': ssh_key }) return self.request('/v1/sshkey/create', params, 'POST') def destroy(self, sshkeyid, params=None): ''' /v1/sshkey/destroy POST - account Remove a SSH key. Note that this will not remove the key from any machines that already have it. Link: https://www.vultr.com/api/#sshkey_destroy ''' params = update_params(params, {'SSHKEYID': sshkeyid}) return self.request('/v1/sshkey/destroy', params, 'POST') def list(self, params=None): ''' /v1/sshkey/list GET - account List all the SSH keys on the current account Link: https://www.vultr.com/api/#sshkey_list ''' params = params if params else dict() return self.request('/v1/sshkey/list', params, 'GET') def update(self, sshkeyid, params=None): ''' /v1/sshkey/update POST - account Update an existing SSH Key. Note that this will only update newly installed machines. The key will not be updated on any existing machines. Link: https://www.vultr.com/api/#sshkey_update ''' params = update_params(params, {'SSHKEYID': sshkeyid}) return self.request('/v1/sshkey/update', params, 'POST') python-vultr-1.0.1/vultr/v1_startupscript.py000066400000000000000000000035451465017637600213150ustar00rootroot00000000000000'''Partial class to handle Vultr Startup Script API calls''' from .utils import VultrBase, update_params class VultrStartupScript(VultrBase): '''Handles Vultr Startup Script API calls''' def __init__(self, api_key): VultrBase.__init__(self, api_key) def create(self, name, script, params=None): ''' /v1/startupscript/create POST - account Create a startup script Link: https://www.vultr.com/api/#startupscript_create ''' params = update_params(params, { 'name': name, 'script': script }) return self.request('/v1/startupscript/create', params, 'POST') def destroy(self, scriptid, params=None): ''' /v1/startupscript/destroy POST - account Remove a startup script Link: https://www.vultr.com/api/#startupscript_destroy ''' params = update_params(params, {'SCRIPTID': scriptid}) return self.request('/v1/startupscript/destroy', params, 'POST') def list(self, params=None): ''' /v1/startupscript/list GET - account List all startup scripts on the current account. 'boot' type scripts are executed by the server's operating system on the first boot. 'pxe' type scripts are executed by iPXE when the server itself starts up. Link: https://www.vultr.com/api/#startupscript_list ''' params = params if params else dict() return self.request('/v1/startupscript/list', params, 'GET') def update(self, scriptid, params=None): ''' /v1/startupscript/update POST - account Update an existing startup script Link: https://www.vultr.com/api/#startupscript_update ''' params = update_params(params, {'SCRIPTID': scriptid}) return self.request('/v1/startupscript/update', params, 'POST') python-vultr-1.0.1/vultr/vultr.py000066400000000000000000000027321465017637600171310ustar00rootroot00000000000000'''Python library for the Vultr cloud API''' from .utils import VultrBase from .v1_account import VultrAccount from .v1_app import VultrApp from .v1_backup import VultrBackup from .v1_dns import VultrDNS from .v1_firewall import VultrFirewall from .v1_iso import VultrISO from .v1_os import VultrOS from .v1_plans import VultrPlans from .v1_regions import VultrRegions from .v1_reservedip import VultrReservedIP from .v1_server import VultrServer from .v1_snapshot import VultrSnapshot from .v1_sshkey import VultrSSHKey from .v1_startupscript import VultrStartupScript class Vultr(VultrBase): '''Public Vultr interface''' # pylint: disable=too-many-instance-attributes # The interface is large, but built correctly def __init__(self, api_key): VultrBase.__init__(self, api_key) self.account = VultrAccount(api_key) self.app = VultrApp(api_key) self.backup = VultrBackup(api_key) self.dns = VultrDNS(api_key) self.firewall = VultrFirewall(api_key) self.iso = VultrISO(api_key) # pylint: disable=invalid-name # OS is the Vultr API namespace name self.os = VultrOS(api_key) self.plans = VultrPlans(api_key) self.regions = VultrRegions(api_key) self.reservedip = VultrReservedIP(api_key) self.server = VultrServer(api_key) self.snapshot = VultrSnapshot(api_key) self.sshkey = VultrSSHKey(api_key) self.startupscript = VultrStartupScript(api_key)