Python library¶
Basic Usage¶
First create a Client instance using a HttpClient with your api token and actual API URL. (you might get API token here and API URL here)
>>> from selvpcclient.client import Client, setup_http_client
>>> SEL_TOKEN=YOUR_API_TOKEN_HERE
>>> SEL_URL="https://api.selectel.ru/vpc/resell"
>>> http_client = setup_http_client(api_url=SEL_URL, api_token=SEL_TOKEN)
>>> selvpc = Client(client=http_client)
Now you can call various methods on the client instance. For example
Create a project¶
>>> project = selvpc.projects.add(name="Bonnie")
Set project quotas¶
>>> quotas = {
"quotas": {
"compute_cores": [
{
"region": "ru-1",
"zone": "ru-1a",
"value": 10
}
],
"compute_ram": [
{
"region": "ru-1",
"zone": "ru-1a",
"value": 1024
}
]
}
}
# via object
>>> project.update_quotas(quotas)
# via quotas manager
>>> quotas = selvpc.quotas.update(project.id, quotas=quotas)
Add Windows license¶
>>> licenses = {
"licenses": [{
"region": "ru-1",
"quantity": 1,
"type": "license_windows_2012_standard"
}]
}
# via object
>>> project.add_license(license)
# via licenses manager
>>> licenses = selvpc.licenses.add(project.id, licenses=licenses)
All available managers¶
Manage Projects¶
-
class
selvpcclient.resources.projects.
Project
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a project.
-
add_floating_ips
(floatingips)[source]¶ Add floatingips to current project.
Parameters: floatingips (dict) – Dict with key floatingips and value as array of items region and quantity:
{ "floatingips": [ { "region": "ru-1", "quantity": 4 } ] }
Return type: list of selvpcclient.resources.floatingips.FloatingIP
-
add_license
(licenses)[source]¶ Create licenses for current project.
Parameters: licenses (dict) – Dict with key licenses and value as array of items region, quantity and type:
{ "licenses": [{ "region": "ru-1", "quantity": 4, "type": "license_windows_2012_standard" }, { "region": "ru-2", "quantity": 1, "type": "license_windows_2012_standard" }] }
Return type: list of selvpcclient.resources.licenses.License
-
add_subnet
(subnets)[source]¶ Add public subnets to current project.
Parameters: subnets (dict) – Dict with key subnets and value as array of items region, quantity and type:
{ "subnets": [ { "region": "ru-1", "quantity": 4, "type": "ipv4" } ] }
Return type: list of selvpcclient.resources.subnets.Subnet
-
add_token
()[source]¶ Create reseller token for current project.
Return type: selvpcclient.resources.tokens.Token
-
get
()[source]¶ Get full information about current project.
Return type: Project
with additional fields.
-
get_quotas
()[source]¶ Show quotas info for current project.
Return type: list of selvpcclient.resources.quotas.Quotas
-
get_roles
()[source]¶ List all roles for the project.
Return type: list of selvpcclient.resources.roles.Role
-
update
(name=None)[source]¶ Update current project properties.
Parameters: name (string) – New name for project. Return type: Project
with new name.
-
update_quotas
(quotas)[source]¶ Update current project’s quotas.
Parameters: quotas (dict) – Dict with key quotas and keys as dict of items region, zone and value:
{ "quotas": { "compute_cores": [ { "region": "ru-1", "zone": "ru-1a", "value": 10 }, { "region": "ru-1", "zone": "ru-1b", "value": 10 } ] } }
Return type: list of selvpcclient.resources.quotas.Quotas
-
-
class
selvpcclient.resources.projects.
ProjectsManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating project.
-
create
(name, quotas=None)[source]¶ Create new project and optionally set quotas on it.
Parameters: - name (string) – Name of project.
- quotas (dict) –
Dict with key quotas and keys as dict of items region, zone and value:
{ "quotas": { "compute_cores": [ { "region": "ru-1", "zone": "ru-1a", "value": 10 }, { "region": "ru-1", "zone": "ru-1b", "value": 10 } ] } }
Return type: list of
Project
.
-
delete
(project_id)[source]¶ Delete Project and all it’s objects.
Parameters: project_id (string) – Project id.
-
Manage Quotas¶
-
class
selvpcclient.resources.quotas.
Quotas
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a quota.
-
class
selvpcclient.resources.quotas.
QuotasManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating quota.
-
get_domain_quotas
()[source]¶ Get total amount of resources available to be allocated to projects.
Return type: Quotas
-
get_free_domain_quotas
()[source]¶ Get amount of resources available to be allocated to projects.
Return type: Quotas
-
get_project_quotas
(project_id)[source]¶ Show quotas info for one project.
Parameters: project_id (string) – Project id. Return type: Quotas
-
optimize_project_quotas
(project_id)[source]¶ Optimize project quotas.
Parameters: project_id (string) – Project id.
-
update
(project_id, quotas)[source]¶ Update Project’s quotas.
Parameters: - project_id (string) – Project id.
- quotas (dict) –
Dict with key quotas and keys as dict of items region, zone and value:
{ "quotas": { "compute_cores": [ { "region": "ru-1", "zone": "ru-1a", "value": 10 }, { "region": "ru-1", "zone": "ru-1b", "value": 10 } ] } }
Return type:
-
Manage Licenses¶
-
class
selvpcclient.resources.licenses.
License
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a license.
-
class
selvpcclient.resources.licenses.
LicenseManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating licenses.
-
add
(project_id, licenses)[source]¶ Create licenses for project.
Parameters: - project_id (string) – Project id.
- licenses (dict) –
Dict with key licenses and value as array of items region, quantity and type:
{ "licenses": [{ "region": "ru-1", "quantity": 4, "type": "license_windows_2012_standard" }, { "region": "ru-2", "quantity": 1, "type": "license_windows_2012_standard" }] }
Return type: list of
License
-
Manage Users¶
-
class
selvpcclient.resources.users.
User
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a user.
-
add_to_project
(project_id)[source]¶ Add current user to project.
Parameters: project_id (str) – Project id, where user will be added. Return type: selvpcclient.resources.roles.Role
-
check_in_project
(project_id)[source]¶ Check if the current user is have a role in project.
Parameters: project_id (str) – Project id, where user will be checked. Return type: bool
-
get_roles
()[source]¶ List roles for current user.
Return type: list of selvpcclient.resources.roles.Role
-
remove_from_project
(project_id)[source]¶ Remove current user from project.
Parameters: project_id (str) – Project id, where user will be removed. Return type: None
-
update_name
(new_name)[source]¶ Update name for current user.
Parameters: new_name (string) – New user name. Return type: User
-
-
class
selvpcclient.resources.users.
UsersManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating users.
-
create
(name, password, enabled)[source]¶ Create new user in current domain.
Parameters: - name (string) – User name.
- password (string) – User password.
- enabled (bool) – User status.
Return type:
-
Manage Roles in projects¶
-
class
selvpcclient.resources.roles.
Role
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a role.
-
class
selvpcclient.resources.roles.
RolesManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating roles.
-
add
(roles)[source]¶ Bulk create user <-> project roles for given input.
Parameters: roles (dict) – Dict with key roles and keys as dict of items project_id and user_id:
{ "roles": [{ "project_id": "7354286c9ebf464d86efc1", "user_id": "5900efc62db34decae9f2dbc0" }] }
Return type: list of Role
-
add_user_role_in_project
(project_id, user_id)[source]¶ Create user <-> project role.
Parameters: - project_id (string) – Project id.
- user_id (string) – User id.
Return type:
-
delete_user_role_from_project
(project_id, user_id)[source]¶ Delete user <-> project role.
Parameters: - project_id (string) – Project id.
- user_id (string) – User id.
-
get_project_roles
(project_id)[source]¶ List all roles for the project.
Parameters: project_id (string) – Project id. Return type: list of Role
-
Manage Subnets¶
-
class
selvpcclient.resources.subnets.
Subnet
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a subnet.
-
class
selvpcclient.resources.subnets.
SubnetManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating subnet.
-
add
(project_id, subnets)[source]¶ Create public subnets for project.
Parameters: - project_id (string) – Project id.
- subnets (dict) –
Dict with key subnets and value as array of items region, quantity and type:
{ "subnets": [ { "region": "ru-1", "quantity": 4, "type": "ipv4", "prefix_length": 29 } ] }
Return type: list of
Subnet
-
Manage VRRP Subnets¶
-
class
selvpcclient.resources.vrrp.
VRRP
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a vrrp.
-
class
selvpcclient.resources.vrrp.
VRRPManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating vrrp subnets.
-
add
(project_id, vrrp)[source]¶ Create vrrp in project.
Parameters: - project_id (string) – Project id.
- vrrp (dict) –
Dict with key vrrp and value as array of items region and quantity:
{ "vrrp_subnets": [ { "regions": ["ru-1", "ru-2"], "quantity": 1, "prefix_length": 29, "type": "ipv4", } ] }
Return type: list of
VRRP
-
Manage Floating IP¶
-
class
selvpcclient.resources.floatingips.
FloatingIP
(manager, info)[source]¶ Bases:
selvpcclient.base.Resource
Represents a floating ip.
-
class
selvpcclient.resources.floatingips.
FloatingIPManager
(client)[source]¶ Bases:
selvpcclient.base.Manager
Manager class for manipulating floating ip.
-
add
(project_id, floatingips)[source]¶ Create floatingips in project.
Parameters: - project_id (string) – Project id.
- floatingips (dict) –
Dict with key floatingips and value as array of items region and quantity:
{ "floatingips": [ { "region": "ru-1", "quantity": 4 } ] }
Return type: list of
FloatingIP
-
delete
(floatingip_id)[source]¶ Delete floatingip from domain.
Parameters: floatingip_id (string) – Floating ip id.
-
resource_class
¶ alias of
FloatingIP
-
show
(floatingip_id)[source]¶ Show detailed floatingip information.
Parameters: floatingip_id (string) – Floatingip id. Return type: FloatingIP
-