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
delete()[source]

Delete current project and all it’s objects.

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.
list()[source]

Get list of projects in current domain.

Return type:list of Project
resource_class

alias of Project

show(project_id)[source]

Show detailed project information.

Parameters:project_id (string) – Project id.
Return type:Project with additional fields.
update(project_id, name)[source]

Update Project’s properties.

Parameters:
  • project_id (string) – Project id.
  • name (string) – New name for project.
Return type:

Project

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
get_projects_quotas()[source]

Show quotas info for all domain projects.

Return type:Quotas
optimize_project_quotas(project_id)[source]

Optimize project quotas.

Parameters:project_id (string) – Project id.
resource_class

alias of Quotas

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:

Quotas

Manage Licenses

class selvpcclient.resources.licenses.License(manager, info)[source]

Bases: selvpcclient.base.Resource

Represents a license.

delete()[source]

Delete current license from domain.

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

delete(license_id)[source]

Delete license from domain.

Parameters:license_id (string) – License id.
resource_class

alias of License

show(license_id)[source]

Show detailed license information.

Parameters:license_id (string) – License id.
Return type: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
delete()[source]

Delete current user

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
update_password(new_password)[source]

Update password for current user.

Parameters:new_password (string) – New user password.
Return type:User
update_status(enabled)[source]

Update status (enabled|disabled) for current user.

Parameters:enabled (bool) – New user status: enabled or disabled.
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:

User

delete(user_id)[source]

Delete user and it’s roles from domain.

Parameters:user_id (string) – User id.
Return type:None
list()[source]

Get list of all users in current domain.

Return type:list of User
resource_class

alias of User

update(user_id, name=None, password=None, enabled=None)[source]

Edit user parameters.

Parameters:
  • user_id (string) – User id.
  • name (string) – New user name. (optional)
  • password (string) – New user password. (optional)
  • enabled (bool) – New user status. (optional)
Return type:

User

Manage Roles in projects

class selvpcclient.resources.roles.Role(manager, info)[source]

Bases: selvpcclient.base.Resource

Represents a role.

delete()[source]

Delete current user role from project

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:

Role

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
get_user_roles(user_id)[source]

List roles for the user.

Parameters:user_id (string) – User id.
Return type:list of Role
resource_class

alias of Role

Manage Subnets

class selvpcclient.resources.subnets.Subnet(manager, info)[source]

Bases: selvpcclient.base.Resource

Represents a subnet.

delete()[source]

Delete current subnet from domain.

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

delete(subnet_id)[source]

Delete subnet from domain.

resource_class

alias of Subnet

show(subnet_id)[source]

Show detailed subnet information.

Parameters:subnet_id (string) – Subnet id.
Return type:Subnet

Manage VRRP Subnets

class selvpcclient.resources.vrrp.VRRP(manager, info)[source]

Bases: selvpcclient.base.Resource

Represents a vrrp.

delete()[source]

Delete current vrrp subnet from domain.

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

delete(vrrp_id)[source]

Delete vrrp from domain.

Parameters:vrrp_id (string) – VRRP id.
resource_class

alias of VRRP

show(vrrp_id)[source]

Show detailed vrrp information.

Parameters:vrrp_id (string) – VRRP id.
Return type:VRRP

Manage Floating IP

class selvpcclient.resources.floatingips.FloatingIP(manager, info)[source]

Bases: selvpcclient.base.Resource

Represents a floating ip.

delete()[source]

Delete current floatingip from domain.

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

Manage Tokens

class selvpcclient.resources.tokens.Token(manager, info)[source]

Bases: selvpcclient.base.Resource

Represents a token.

class selvpcclient.resources.tokens.TokensManager(client)[source]

Bases: selvpcclient.base.Manager

Manager class for manipulating token.

create(project_id)[source]

Create reseller token for project.

Parameters:project_id (string) – Project_id.
Return type:Token
resource_class

alias of Token