File: v1_server_ipv4.py

package info (click to toggle)
python-vultr 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: python: 1,004; makefile: 5
file content (77 lines) | stat: -rw-r--r-- 2,903 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'''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')