Skip to content

Server

Bases: BaseRoute

A class for managing the Outline VPN server's settings and configurations.

This class provides methods to interact with and configure various server-level settings for the Outline VPN server. It allows you to perform tasks like renaming the server, changing the hostname, adjusting port settings, and setting or removing data transfer limits for the server.

Attributes:

Name Type Description
base_url str

The base URL for the metrics endpoint of the Outline server.

Parameters:

Name Type Description Default
management_url str

The management URL used to communicate with the Outline server API.

required
ssl_verify bool

Flag to enable or disable SSL certificate verification for API requests. Default is False. You should set this flag to False if the server's SSL certificate is self-signed or if no certificate is present.

False
Source code in outline_vpn_api_client/client.py
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
class Server(BaseRoute):
    """
    A class for managing the Outline VPN server's settings and configurations.

    This class provides methods to interact with and configure various server-level settings for the Outline VPN server.
    It allows you to perform tasks like renaming the server, changing the hostname, adjusting port settings, 
    and setting or removing data transfer limits for the server.

    Attributes:
        base_url (str): The base URL for the metrics endpoint of the Outline server.

    Args:
        management_url (str): The management URL used to communicate with the Outline server API.
        ssl_verify (bool): Flag to enable or disable SSL certificate verification for API requests. Default is `False`.
                        You should set this flag to `False` if the server's SSL certificate is self-signed or if no certificate is present.
    """
    def __str__(self):
        return json.dumps(self.get_information().model_dump(), ensure_ascii=False, indent=4)

    def get_information(self) -> models.Server:
        """
        Returns information about the server.

        This method retrieves detailed information about the Outline VPN server, such as its status, configuration, 
        and other relevant details.

        Returns:
            dict: A dictionary containing the server information.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        response = requests.get(f"{self.base_url}/server", verify=self.ssl_verify)
        response_json = response.json()
        _check_response(response, response_json)
        return models.Server.model_validate(response_json)

    def change_hostname(self, hostname: str) -> bool:
        """
        Changes the hostname for access keys.

        This method updates the hostname or IP address used for access keys on the Outline VPN server. 
        If a hostname is provided, it must be valid and DNS must be configured independently of this API.

        Args:
            hostname (str): The new hostname or IP address to use for access keys.

        Returns:
            bool: Returns `True` if the hostname was successfully changed.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {
            "hostname": hostname
        }
        response = requests.put(f"{self.base_url}/server/hostname-for-access-keys", json=data, verify=self.ssl_verify)
        _check_response(response)
        return True

    def rename(self, name: str) -> bool:
        """
        Renames the server.

        This method changes the name of the Outline VPN server to the specified `name`.

        Args:
            name (str): The new name for the server.

        Returns:
            bool: Returns `True` if the server was successfully renamed.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {
            "name": name
        }
        response = requests.put(f"{self.base_url}/name", json=data, verify=self.ssl_verify)
        _check_response(response)
        return True

    def change_default_port_for_new_keys(self, port: int) -> bool:
        """
        Changes the default port for newly created access keys.

        This method updates the default port that will be used for new access keys. The specified port can be one
        that is already in use by other access keys.

        Args:
            port (int): The new default port to be used for newly created access keys.

        Returns:
            bool: Returns `True` if the default port was successfully changed.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {
            "port": port
        }
        response = requests.put(f"{self.base_url}/server/port-for-new-access-keys", json=data, verify=self.ssl_verify)
        _check_response(response)
        return True

    def set_server_default_limits(self, limit: int) -> bool:
        """
        Sets a data transfer limit for all access keys.

        This method sets a default data transfer limit that will apply to all access keys on the server. 
        The specified limit is in bytes.

        Args:
            limit (int): The data transfer limit in bytes to set for all access keys.

        Returns:
            bool: Returns `True` if the default data transfer limit was successfully set.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        data = {
            "limit": {
                "bytes": limit
            }
        }
        response = requests.put(f"{self.base_url}/server/access-key-data-limit", json=data, verify=self.ssl_verify)
        _check_response(response)
        return True

    def remove_server_default_limits(self) -> bool:
        """
        Removes the access key data limit, lifting data transfer restrictions on all access keys.

        This method removes the data transfer limit for all access keys, effectively lifting any restrictions 
        on data usage for the keys.

        Returns:
            bool: Returns `True` if the data transfer limit was successfully removed.

        Raises:
            ResponseNotOkException: If the server response indicates an error (status code >= 300).
        """
        response = requests.delete(f"{self.base_url}/server/access-key-data-limit", verify=self.ssl_verify)
        _check_response(response)
        return True

change_default_port_for_new_keys(port)

Changes the default port for newly created access keys.

This method updates the default port that will be used for new access keys. The specified port can be one that is already in use by other access keys.

Parameters:

Name Type Description Default
port int

The new default port to be used for newly created access keys.

required

Returns:

Name Type Description
bool bool

Returns True if the default port was successfully changed.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def change_default_port_for_new_keys(self, port: int) -> bool:
    """
    Changes the default port for newly created access keys.

    This method updates the default port that will be used for new access keys. The specified port can be one
    that is already in use by other access keys.

    Args:
        port (int): The new default port to be used for newly created access keys.

    Returns:
        bool: Returns `True` if the default port was successfully changed.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {
        "port": port
    }
    response = requests.put(f"{self.base_url}/server/port-for-new-access-keys", json=data, verify=self.ssl_verify)
    _check_response(response)
    return True

change_hostname(hostname)

Changes the hostname for access keys.

This method updates the hostname or IP address used for access keys on the Outline VPN server. If a hostname is provided, it must be valid and DNS must be configured independently of this API.

Parameters:

Name Type Description Default
hostname str

The new hostname or IP address to use for access keys.

required

Returns:

Name Type Description
bool bool

Returns True if the hostname was successfully changed.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def change_hostname(self, hostname: str) -> bool:
    """
    Changes the hostname for access keys.

    This method updates the hostname or IP address used for access keys on the Outline VPN server. 
    If a hostname is provided, it must be valid and DNS must be configured independently of this API.

    Args:
        hostname (str): The new hostname or IP address to use for access keys.

    Returns:
        bool: Returns `True` if the hostname was successfully changed.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {
        "hostname": hostname
    }
    response = requests.put(f"{self.base_url}/server/hostname-for-access-keys", json=data, verify=self.ssl_verify)
    _check_response(response)
    return True

get_information()

Returns information about the server.

This method retrieves detailed information about the Outline VPN server, such as its status, configuration, and other relevant details.

Returns:

Name Type Description
dict Server

A dictionary containing the server information.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def get_information(self) -> models.Server:
    """
    Returns information about the server.

    This method retrieves detailed information about the Outline VPN server, such as its status, configuration, 
    and other relevant details.

    Returns:
        dict: A dictionary containing the server information.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    response = requests.get(f"{self.base_url}/server", verify=self.ssl_verify)
    response_json = response.json()
    _check_response(response, response_json)
    return models.Server.model_validate(response_json)

remove_server_default_limits()

Removes the access key data limit, lifting data transfer restrictions on all access keys.

This method removes the data transfer limit for all access keys, effectively lifting any restrictions on data usage for the keys.

Returns:

Name Type Description
bool bool

Returns True if the data transfer limit was successfully removed.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
def remove_server_default_limits(self) -> bool:
    """
    Removes the access key data limit, lifting data transfer restrictions on all access keys.

    This method removes the data transfer limit for all access keys, effectively lifting any restrictions 
    on data usage for the keys.

    Returns:
        bool: Returns `True` if the data transfer limit was successfully removed.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    response = requests.delete(f"{self.base_url}/server/access-key-data-limit", verify=self.ssl_verify)
    _check_response(response)
    return True

rename(name)

Renames the server.

This method changes the name of the Outline VPN server to the specified name.

Parameters:

Name Type Description Default
name str

The new name for the server.

required

Returns:

Name Type Description
bool bool

Returns True if the server was successfully renamed.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
def rename(self, name: str) -> bool:
    """
    Renames the server.

    This method changes the name of the Outline VPN server to the specified `name`.

    Args:
        name (str): The new name for the server.

    Returns:
        bool: Returns `True` if the server was successfully renamed.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {
        "name": name
    }
    response = requests.put(f"{self.base_url}/name", json=data, verify=self.ssl_verify)
    _check_response(response)
    return True

set_server_default_limits(limit)

Sets a data transfer limit for all access keys.

This method sets a default data transfer limit that will apply to all access keys on the server. The specified limit is in bytes.

Parameters:

Name Type Description Default
limit int

The data transfer limit in bytes to set for all access keys.

required

Returns:

Name Type Description
bool bool

Returns True if the default data transfer limit was successfully set.

Raises:

Type Description
ResponseNotOkException

If the server response indicates an error (status code >= 300).

Source code in outline_vpn_api_client/client.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def set_server_default_limits(self, limit: int) -> bool:
    """
    Sets a data transfer limit for all access keys.

    This method sets a default data transfer limit that will apply to all access keys on the server. 
    The specified limit is in bytes.

    Args:
        limit (int): The data transfer limit in bytes to set for all access keys.

    Returns:
        bool: Returns `True` if the default data transfer limit was successfully set.

    Raises:
        ResponseNotOkException: If the server response indicates an error (status code >= 300).
    """
    data = {
        "limit": {
            "bytes": limit
        }
    }
    response = requests.put(f"{self.base_url}/server/access-key-data-limit", json=data, verify=self.ssl_verify)
    _check_response(response)
    return True