Module libnova.common.api.Storage

Expand source code
#!/usr/bin/env python
# coding: utf-8

import datetime
import json
from enum import Enum
from libnova.common import api

# Define Enum structs
from libnova.common.api.Serializable import Serializable


class StorageType(Enum):
    """Storage Type
    """
    FILESYSTEM = 1
    S3         = 2


# Define main object structure
class Storage(Serializable):
    """Storage

    The main methods allows the interaction with the main structures related to storages in the platform
    """

    id:                        int         = 0
    name:                      str
    type:                      StorageType = 1
    storage_class_id:          int
    storage_class_apply_after: datetime.datetime
    extra:                     str
    extra_data:                {}

    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

        if bool(self.extra):
            try:
                self.extra_data = json.loads(self.extra)
            except:
                pass


def get(storage_id):
    """Retrieve a storage by its `storage_id`

    Args:
        storage_id (int): The `Storage` id

    Returns:
        Storage: A `Storage` if exists
    """

    api_driver = api.Driver.get_instance()

    return api_driver.serialize(
        api_driver.get(
            url_segment='storage/' + str(storage_id)
        ),
        Storage
    )


def get_all():
    """Retrieve all storage available

    Returns:
        list(Storage): A list of `Storage` objects
    """

    api_driver = api.Driver.get_instance()

    return api_driver.get(
        url_segment='storages'
    )


if __name__ == "__main__":
    print('This file cannot be executed directly!')

Functions

def get(storage_id)

Retrieve a storage by its storage_id

Args

storage_id : int
The Storage id

Returns

Storage
A Storage if exists
Expand source code
def get(storage_id):
    """Retrieve a storage by its `storage_id`

    Args:
        storage_id (int): The `Storage` id

    Returns:
        Storage: A `Storage` if exists
    """

    api_driver = api.Driver.get_instance()

    return api_driver.serialize(
        api_driver.get(
            url_segment='storage/' + str(storage_id)
        ),
        Storage
    )
def get_all()

Retrieve all storage available

Returns

list(Storage): A list of Storage objects

Expand source code
def get_all():
    """Retrieve all storage available

    Returns:
        list(Storage): A list of `Storage` objects
    """

    api_driver = api.Driver.get_instance()

    return api_driver.get(
        url_segment='storages'
    )

Classes

class Storage (**kwargs)

Storage

The main methods allows the interaction with the main structures related to storages in the platform

Expand source code
class Storage(Serializable):
    """Storage

    The main methods allows the interaction with the main structures related to storages in the platform
    """

    id:                        int         = 0
    name:                      str
    type:                      StorageType = 1
    storage_class_id:          int
    storage_class_apply_after: datetime.datetime
    extra:                     str
    extra_data:                {}

    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

        if bool(self.extra):
            try:
                self.extra_data = json.loads(self.extra)
            except:
                pass

Ancestors

Class variables

var extra : str
var extra_data
var id : int
var name : str
var storage_class_apply_after : datetime.datetime
var storage_class_id : int
var typeStorageType
class StorageType (value, names=None, *, module=None, qualname=None, type=None, start=1)

Storage Type

Expand source code
class StorageType(Enum):
    """Storage Type
    """
    FILESYSTEM = 1
    S3         = 2

Ancestors

  • enum.Enum

Class variables

var FILESYSTEM
var S3