def get_backend_sizes(): """ Send backend sizes to InfluxDB """ points = [] backends = BackendList.get_backends() if len(backends) == 0: StatsmonkeyScheduledTaskController._logger.info("No backends found") return for b in backends: global_size = b.alba_backend.ns_statistics['global'] entry = { 'measurement': 'backend_size', 'tags': { 'backend_name': b.name }, 'fields': { 'free': global_size['size'] - global_size['used'], 'used': global_size['used'] } } points.append(entry) if len(points) == 0: StatsmonkeyScheduledTaskController._logger.info("No statistics found") return StatsmonkeyScheduledTaskController._send_stats(points) return points
def list(self, backend_type=None): """ Overview of all backends (from a certain type, if given) on the local node (or a remote one) """ if backend_type is None: return BackendList.get_backends() return BackendTypeList.get_backend_type_by_code(backend_type).backends
def get_preset_by_albabackend(preset_name, albabackend_name): """ Fetches preset by albabackend_guid :param preset_name: name of a existing preset :type preset_name: str :param albabackend_name: name of a existing alba backend :type albabackend_name: str :return: alba backends :rtype: list """ try: return [ preset for preset in BackendList.get_by_name( albabackend_name).alba_backend.presets if preset['name'] == preset_name ][0] except IndexError: raise PresetNotFoundError( "Preset `{0}` on alba backend `{1}` was not found".format( preset_name, albabackend_name)) except AttributeError: raise AlbaBackendNotFoundError( "Albabackend with name `{0}` does not exist".format( albabackend_name))
def get_by_name(name): """ Retrieve a backend based on name :param name: Name of the backend :return: Backend DAL object """ return BackendList.get_by_name(name=name)
def get_backend_status_by_name(backend_name): """ :param backend_name: name of a backend :type backend_name: str :return: backend status :rtype: str """ return BackendList.get_by_name(backend_name).status
def get_backend_by_name(backend_name): """ :param backend_name: name of a backend :type backend_name: str :return: Backend object :rtype: ovs.dal.hybrids.backend.Backend """ return BackendList.get_by_name(backend_name)
def get_backend_guid_by_name(backend_name): """ :param backend_name: name of a backend :type backend_name: str :return: backend_guid :rtype: str """ return BackendList.get_by_name(backend_name).guid
def create(self, request): """ Creates a Backend """ serializer = FullSerializer(Backend, instance=Backend(), data=request.DATA) if serializer.is_valid(): duplicate = BackendList.get_by_name(serializer.object.name) if duplicate is None: serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_add_vpool_params(storagerouter, **kwargs): """ Retrieve the default configuration settings to create a vPool :param storagerouter: Storage Router on which to add or extend the vPool :type storagerouter: StorageRouter :return: Dictionary with default settings :rtype: dict """ test_config = General.get_config() config_params = json.loads(test_config.get("vpool", "config_params")) vpool_type = kwargs.get("type", test_config.get("vpool", "type")) vpool_params = { "type": vpool_type, "vpool_name": kwargs.get("vpool_name", test_config.get("vpool", "name")), "storage_ip": kwargs.get("storage_ip", test_config.get("vpool", "storage_ip")), "integratemgmt": kwargs.get("integrate_mgmt", test_config.getboolean("vpool", "integrate_mgmt")), "readcache_size": kwargs.get("readcache_size", test_config.getint("vpool", "readcache_size")), "writecache_size": kwargs.get("writecache_size", test_config.getint("vpool", "writecache_size")), "storagerouter_ip": storagerouter.ip, "config_params": { "dtl_mode": kwargs.get("dtl_mode", config_params.get("dtl_mode", "a_sync")), "sco_size": kwargs.get("sco_size", config_params.get("sco_size", 4)), "cluster_size": kwargs.get("cluster_size", config_params.get("cluster_size", 4)), "write_buffer": kwargs.get("write_buffer", config_params.get("write_buffer", 128)), "dtl_transport": kwargs.get("dtl_transport", config_params.get("dtl_transport", "tcp")), }, "backend_connection_info": {"host": ""}, } if vpool_type not in ["local", "distributed"]: vpool_params["backend_connection_info"] = { "host": kwargs.get("alba_connection_host", test_config.get("vpool", "alba_connection_host")), "port": kwargs.get("alba_connection_port", test_config.getint("vpool", "alba_connection_port")), "username": kwargs.get("alba_connection_user", test_config.get("vpool", "alba_connection_user")), "password": kwargs.get("alba_connection_pass", test_config.get("vpool", "alba_connection_pass")), } if vpool_type == "alba": backend = BackendList.get_by_name(kwargs.get("backend_name", test_config.get("backend", "name"))) if backend is not None: vpool_params["fragment_cache_on_read"] = kwargs.get( "fragment_cache_on_read", test_config.getboolean("vpool", "fragment_cache_on_read") ) vpool_params["fragment_cache_on_write"] = kwargs.get( "fragment_cache_on_write", test_config.getboolean("vpool", "fragment_cache_on_write") ) vpool_params["backend_connection_info"]["backend"] = { "backend": backend.alba_backend_guid, "metadata": "default", } elif vpool_type == "distributed": vpool_params["distributed_mountpoint"] = kwargs.get("distributed_mountpoint", "/tmp") return vpool_params
def create(self, request): """ Creates a Backend :param request: The raw request :type request: Request """ serializer = FullSerializer(Backend, instance=Backend(), data=request.DATA) backend = serializer.deserialize() duplicate = BackendList.get_by_name(backend.name) if duplicate is None: backend.save() return backend raise HttpNotAcceptableException(error_description='Backend with this name already exists', error='duplicate')
def get_alba_backend_guid_by_name(backend_name): """ :param backend_name: name of a backend :type backend_name: str :return: alba_backend_guid :rtype: str """ try: return BackendList.get_by_name(backend_name).alba_backend_guid except AttributeError: error_msg = "No alba backend found with name `{0}`".format( backend_name) BackendHelper.LOGGER.error(error_msg) raise NameError(error_msg)
def list(self, request, backend_type=None): """ Overview of all backends (from a certain type, if given) on the local node (or a remote one) :param request: The raw request :type request: Request :param backend_type: Optional BackendType code to filter :type backend_type: str """ if backend_type is None: possible_backends = BackendList.get_backends() else: possible_backends = BackendTypeList.get_backend_type_by_code(backend_type).backends backends = [] for backend in possible_backends: if Toolbox.access_granted(request.client, user_rights=backend.user_rights, client_rights=backend.client_rights): backends.append(backend) return backends
def list(self, backend_type=None, ip=None, port=None, client_id=None, client_secret=None, contents=None): """ Overview of all backends (from a certain type, if given) on the local node (or a remote one) """ if ip is None: if backend_type is None: return BackendList.get_backends() return BackendTypeList.get_backend_type_by_code(backend_type).backends client = OVSClient(ip, port, client_id, client_secret) try: remote_backends = client.get( "/backends/", params={"backend_type": backend_type, "contents": "" if contents is None else contents} ) except (HTTPError, URLError): raise NotAcceptable("Could not load remote backends") backend_list = [] for entry in remote_backends["data"]: backend = type("Backend", (), entry)() backend_list.append(backend) return backend_list
def get_add_vpool_params(storagerouter, **kwargs): """ Retrieve the default configuration settings to create a vPool :param storagerouter: Storage Router on which to add or extend the vPool :type storagerouter: StorageRouter :return: Dictionary with default settings :rtype: dict """ test_config = General.get_config() config_params = json.loads(test_config.get('vpool', 'config_params')) vpool_type = kwargs.get('type', test_config.get('vpool', 'type')) vpool_params = {'type': vpool_type, 'vpool_name': kwargs.get('vpool_name', test_config.get('vpool', 'name')), 'storage_ip': kwargs.get('storage_ip', test_config.get('vpool', 'storage_ip')), 'integratemgmt': kwargs.get('integrate_mgmt', test_config.getboolean('vpool', 'integrate_mgmt')), 'readcache_size': kwargs.get('readcache_size', test_config.getint('vpool', 'readcache_size')), 'writecache_size': kwargs.get('writecache_size', test_config.getint('vpool', 'writecache_size')), 'storagerouter_ip': storagerouter.ip, 'config_params': {'dtl_mode': kwargs.get('dtl_mode', config_params.get('dtl_mode', 'a_sync')), 'sco_size': kwargs.get('sco_size', config_params.get('sco_size', 4)), 'dedupe_mode': kwargs.get('dedupe_mode', config_params.get('dedupe_mode', 'dedupe')), 'cluster_size': kwargs.get('cluster_size', config_params.get('cluster_size', 4)), 'write_buffer': kwargs.get('write_buffer', config_params.get('write_buffer', 128)), 'dtl_transport': kwargs.get('dtl_transport', config_params.get('dtl_transport', 'tcp')), 'cache_strategy': kwargs.get('cache_strategy', config_params.get('cache_strategy', 'on_read'))}} if vpool_type not in ['local', 'distributed']: vpool_params['backend_connection_info'] = {'host': kwargs.get('alba_connection_host', test_config.get('vpool', 'alba_connection_host')), 'port': kwargs.get('alba_connection_port', test_config.getint('vpool', 'alba_connection_port')), 'username': kwargs.get('alba_connection_user', test_config.get('vpool', 'alba_connection_user')), 'password': kwargs.get('alba_connection_pass', test_config.get('vpool', 'alba_connection_pass'))} if vpool_type == 'alba': backend = BackendList.get_by_name(kwargs.get('backend_name', test_config.get('backend', 'name'))) if backend is not None: vpool_params['fragment_cache_on_read'] = kwargs.get('fragment_cache_on_read', test_config.getboolean('vpool', 'fragment_cache_on_read')) vpool_params['fragment_cache_on_write'] = kwargs.get('fragment_cache_on_write', test_config.getboolean('vpool', 'fragment_cache_on_write')) vpool_params['backend_connection_info']['backend'] = {'backend': backend.alba_backend_guid, 'metadata': 'default'} elif vpool_type == 'distributed': vpool_params['distributed_mountpoint'] = kwargs.get('distributed_mountpoint', '/tmp') return vpool_params
def get_backends(): """ Retrieve a list of all backend :return: Data-object list of Backends """ return BackendList.get_backends()
def list(self): """ Overview of all backends """ return BackendList.get_backends()