Giter Club home page Giter Club logo

python-vultr's Introduction

Vultr

build status

Vultr provides a client library to the Vultr.com API.

Usage

api_key = 'XXXXXXXXX'
vultr = Vultr(api_key)
plans_json = vultr.plans.list()

Testing

From the repo root directory Performs generic, unauthenticated tests

python -m unittest -v tests.test_vultr.UnauthenticatedTests

Requires the environment variable VULTR_KEY to be set

python -m unittest -v tests.test_vultr.AuthenticatedTests

Support

Python Vultr is supported on a volunteer basis.

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's People

Contributors

01000101 avatar aranhoide avatar cpburnz avatar dependabot[bot] avatar dopry avatar furious-luke avatar lihop avatar nishiokay avatar steveclement avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-vultr's Issues

TLSv1.2 required

Vultr is planning on disabling support for TLSv1 within the coming months. Your API connections would need to start using v1.2 in order to remain compatible.

I cannot create new vps from my snapshot.

I cannot create new vps from my snapshot.
vultr.server.create(dcid, planid, osid, {'SNAPSHOTID':snapshot_id})
Everything is OK except this new vps is not from my snapshot.
sample snapshot_id = '3c35c279a5ba8'
Thanks!

Incorrect function definition

At least in method server_start (as well as in another methods, for example, server_destroy) there is no subid argument which causes NameError.

Also I believe subid argument in server_list method should be optional.

Universalize module

Hi,

Vultr api is rather unified, why not to try universalize it? I've written following code, which is working perfectly for me. And you don't need anything except this code, which is pretty convenient, as all new features will be automatically supported by the module.

#!/usr/bin/python
import json
import requests
from urlparse import urljoin
from os import path


class Vultr(object):
    def __init__(self, api):
        self.apikey = api
        self.url = "https://api.vultr.com/v1/"

    def __getattr__(self, key):
        return VultrMethod(self, key)


class VultrMethod(object):
    def __init__(self, client, method_name):
        self.client = client
        self.method_name = method_name

    def __getattr__(self, key):
        return VultrMethod(self.client, '.'.join((self.method_name, key)))

    def __call__(self, **kwargs):
        method = self.method_name.split('.')
        headers = {'API-Key': self.client.apikey}
        return getattr(requests, method[0])(urljoin(
            self.client.url, path.join(method[1], method[2])
            ), headers=headers, data=kwargs)


def main():
    vultr = Vultr(api="APIKEY")
    create_server = vultr.post.server.create(DCID=6, VPSPLANID=201, OSID=164, SNAPSHOTID="910594a93622c")
    print create_server.text


if __name__ == "__main__":
    main()

The API key is incorrectly passed as POST data in some functions

When making a request via POST, all options are passed as POST data. In the POST-dependent functions in Vultr's API, the API key should be passed as a URL parameter and the rest of the options as POST data. For example, see server_create: https://www.vultr.com/api/#server_create

Example Request:
POST https://api.vultr.com/v1/server/create?api_key=APIKEY
DCID=1
VPSPLANID=1
OSID=127

The API key is passed as the 'api_key' URL parameter, while DCID is passed as POST data.

The request function for python-vultr (which is a great module, by the way, thank you for putting it together) does not assemble the request this way; instead, it places all options in the params{} dict, which is passed as either GET or POST. This is the current implementation:

    def request(self, path, params={}, method='GET'):
        if not path.startswith('/'):
            path = '/' + path
        url = self.api_endpoint + path
        params['api_key'] = self.api_key

        try:
            if method == 'POST':
                resp = requests.post(url, data=params, timeout=60)
            elif method == 'GET':
                resp = requests.get(url, params=params, timeout=60)
            else:
                raise VultrError('Unsupported method %s' % method)

This means that all requests using method='POST' will not correctly pass the API key. Instead, the API key should be in params, while the rest of the options should be in data: something like requests.post(url, params=api_key, data=params, timeout=60)

I used a one-change workaround in lieu of a more elegant solution:

if method == 'POST':
                resp = requests.post(url, params={'api_key':params.get('api_key', None)}, data=params, timeout=60)

Not a tasteful fix, but I would rather change as little as possible pending a fix in the master branch.

Thanks again for your work on this module! It's been really helpful.

Error 403: Invalid or missing API key.

Hello. Got the problem

ERROR 403: Invalid or missing API key. Check that your API key is present and matches your assigned key.

changed

API_KEY = environ.get('VULTR_KEY')

to

API_KEY = 'VULTR_KEY'

now working.

The SSHKEYID option in server_create() must be uppercase to be processed by Vultr

Small problem, only applies to server_create(). The SSHKEYID is stored in the params{} dict in lowercase:

if sshkeyid is not None:
            params['sshkeyid'] = sshkeyid

Vultr ignores the value of the key called sshkeyid, as it's only looking for one called SSHKEYID. More a limitation on their end than in python-vultr, but an easy fix:

if sshkeyid is not None:
            params['SSHKEYID'] = sshkeyid

How do I pass parameters to snapshot_create?

Was wondering how I'm able to pass label/extra parameters to snapshot.

The following method of adding params doesn't work. Was wondering if it had anything to do with how snapshot_create was written.

params = dict()
params['label] = 'new snapshot'
vultr.snapshot_create(subid,params=params)

Thanks!

Update API Documentation in README.rst.

We refactored all the optional request parameters into a params dictionary, but didn't update the README.rst at the same time. We probably also consider completing the documentation of the API parameters in the README.rst.

supercedes #30.

Examples not working

Hi,

I've tried the example on the page along with the sample base_list.py. Neither works for me. Python 2.7 or 3.4 on FreeBSD.

2016-02-21 19:33:37,906 INFO [main():77] Vultr API Client Python Library
2016-02-21 19:33:37,907 INFO [main():78] URL: https://www.vultr.com/api/
Traceback (most recent call last):
  File "basic_list.py", line 81, in <module>
    main()
  File "basic_list.py", line 79, in main
    dump_info()
  File "basic_list.py", line 25, in dump_info
    vultr.account.info(), indent=2
AttributeError: 'Vultr' object has no attribute 'account'

Basically the same error on both. I'm setting my API key as an environment variable and it should be passed properly.

Is the example out of date or am I doing something wrong?

Thank you,
Teran

Print statements are incompatible with Python3.x

The print statements in vultr.py cause import errors, due to their syntax. Everything seems to work fine if those are reformatted:

if __name__ == '__main__':
    print("Vultr API Python Libary")
    print("http://vultr.com")

    api_key = ''
    if len(sys.argv) > 1:
        api_key = sys.argv[1]

    vultr = Vultr(api_key)

    print(vultr.iso_list())
    print(vultr.plans_list())
    print(vultr.regions_list())
    print(vultr.os_list())
    print(vultr.app_list())

    if api_key:
        print(vultr.account_info())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.