Skip to content

Commit

Permalink
Merge pull request #52 from fabric-testbed/adv-res
Browse files Browse the repository at this point in the history
Advance Reservations - Time based filtering for List Resources
  • Loading branch information
kthare10 authored Apr 17, 2024
2 parents 5858fe9 + 1a4470b commit 90e2f87
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.46
3.0.54
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Class | Method | HTTP request | Description
*ResourcesApi* | [**portalresources_get**](docs/ResourcesApi.md#portalresources_get) | **GET** /portalresources | Retrieve a listing and description of available resources for portal
*ResourcesApi* | [**resources_get**](docs/ResourcesApi.md#resources_get) | **GET** /resources | Retrieve a listing and description of available resources. By default, a cached available resource information is returned. User can force to request the current available resources.
*SlicesApi* | [**slices_create_post**](docs/SlicesApi.md#slices_create_post) | **POST** /slices/create | Create slice
*SlicesApi* | [**slices_creates_post**](docs/SlicesApi.md#slices_creates_post) | **POST** /slices/creates | Create slice
*SlicesApi* | [**slices_delete_delete**](docs/SlicesApi.md#slices_delete_delete) | **DELETE** /slices/delete | Delete all slices for a User within a project.
*SlicesApi* | [**slices_delete_slice_id_delete**](docs/SlicesApi.md#slices_delete_slice_id_delete) | **DELETE** /slices/delete/{slice_id} | Delete slice.
*SlicesApi* | [**slices_get**](docs/SlicesApi.md#slices_get) | **GET** /slices | Retrieve a listing of user slices
Expand All @@ -128,6 +129,7 @@ Class | Method | HTTP request | Description
- [PoaData](docs/PoaData.md)
- [PoaPost](docs/PoaPost.md)
- [PoaPostData](docs/PoaPostData.md)
- [PoaPostDataKeys](docs/PoaPostDataKeys.md)
- [PoaPostDataVcpuCpuMap](docs/PoaPostDataVcpuCpuMap.md)
- [Resource](docs/Resource.md)
- [Resources](docs/Resources.md)
Expand Down
28 changes: 24 additions & 4 deletions docs/ResourcesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Method | HTTP request | Description
[**resources_get**](ResourcesApi.md#resources_get) | **GET** /resources | Retrieve a listing and description of available resources. By default, a cached available resource information is returned. User can force to request the current available resources.

# **portalresources_get**
> Resources portalresources_get(graph_format)
> Resources portalresources_get(graph_format, level=level, force_refresh=force_refresh, start_date=start_date, end_date=end_date, includes=includes, excludes=excludes)
Retrieve a listing and description of available resources for portal

Expand All @@ -25,10 +25,16 @@ from pprint import pprint
# create an instance of the API class
api_instance = ResourcesApi()
graph_format = 'GRAPHML' # str | graph format (default to GRAPHML)
level = 1 # int | Level of details (optional) (default to 1)
force_refresh = false # bool | Force to retrieve current available resource information. (optional) (default to false)
start_date = 'start_date_example' # str | starting date to check availability from (optional)
end_date = 'end_date_example' # str | end date to check availability until (optional)
includes = 'includes_example' # str | comma separated lists of sites to include (optional)
excludes = 'excludes_example' # str | comma separated lists of sites to exclude (optional)

try:
# Retrieve a listing and description of available resources for portal
api_response = api_instance.portalresources_get(graph_format)
api_response = api_instance.portalresources_get(graph_format, level=level, force_refresh=force_refresh, start_date=start_date, end_date=end_date, includes=includes, excludes=excludes)
pprint(api_response)
except ApiException as e:
print("Exception when calling ResourcesApi->portalresources_get: %s\n" % e)
Expand All @@ -39,6 +45,12 @@ except ApiException as e:
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**graph_format** | **str**| graph format | [default to GRAPHML]
**level** | **int**| Level of details | [optional] [default to 1]
**force_refresh** | **bool**| Force to retrieve current available resource information. | [optional] [default to false]
**start_date** | **str**| starting date to check availability from | [optional]
**end_date** | **str**| end date to check availability until | [optional]
**includes** | **str**| comma separated lists of sites to include | [optional]
**excludes** | **str**| comma separated lists of sites to exclude | [optional]

### Return type

Expand All @@ -56,7 +68,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **resources_get**
> Resources resources_get(level, force_refresh)
> Resources resources_get(level, force_refresh, start_date=start_date, end_date=end_date, includes=includes, excludes=excludes)
Retrieve a listing and description of available resources. By default, a cached available resource information is returned. User can force to request the current available resources.

Expand All @@ -80,10 +92,14 @@ configuration.api_key['Authorization'] = 'YOUR_API_KEY'
api_instance = ResourcesApi(ApiClient(configuration))
level = 1 # int | Level of details (default to 1)
force_refresh = False # bool | Force to retrieve current available resource information. (default to false)
start_date = 'start_date_example' # str | starting date to check availability from (optional)
end_date = 'end_date_example' # str | end date to check availability until (optional)
includes = 'includes_example' # str | comma separated lists of sites to include (optional)
excludes = 'excludes_example' # str | comma separated lists of sites to exclude (optional)

try:
# Retrieve a listing and description of available resources. By default, a cached available resource information is returned. User can force to request the current available resources.
api_response = api_instance.resources_get(level, force_refresh)
api_response = api_instance.resources_get(level, force_refresh, start_date=start_date, end_date=end_date, includes=includes, excludes=excludes)
pprint(api_response)
except ApiException as e:
print("Exception when calling ResourcesApi->resources_get: %s\n" % e)
Expand All @@ -95,6 +111,10 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**level** | **int**| Level of details | [default to 1]
**force_refresh** | **bool**| Force to retrieve current available resource information. | [default to false]
**start_date** | **str**| starting date to check availability from | [optional]
**end_date** | **str**| end date to check availability until | [optional]
**includes** | **str**| comma separated lists of sites to include | [optional]
**excludes** | **str**| comma separated lists of sites to exclude | [optional]

### Return type

Expand Down
6 changes: 5 additions & 1 deletion docs/SlicesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,16 @@ configuration.api_key['Authorization'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = SlicesApi(ApiClient(configuration))
name = 'name_example' # str | Search for Slices with the name (optional)
search = 'search_example' # str | search term applied (optional)
exact_match = false # bool | Exact Match for Search term (optional) (default to false)
as_self = true # bool | GET object as Self (optional) (default to true)
states = ['states_example'] # list[str] | Search for Slices in the specified states (optional)
limit = 5 # int | maximum number of results to return per page (1 or more) (optional) (default to 5)
offset = 0 # int | number of items to skip before starting to collect the result set (optional) (default to 0)

try:
# Retrieve a listing of user slices
api_response = api_instance.slices_get(name=name, as_self=as_self, states=states, limit=limit, offset=offset)
api_response = api_instance.slices_get(name=name, search=search, exact_match=exact_match, as_self=as_self, states=states, limit=limit, offset=offset)
pprint(api_response)
except ApiException as e:
print("Exception when calling SlicesApi->slices_get: %s\n" % e)
Expand All @@ -281,6 +283,8 @@ except ApiException as e:
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**name** | **str**| Search for Slices with the name | [optional]
**search** | **str**| search term applied | [optional]
**exact_match** | **bool**| Exact Match for Search term | [optional] [default to false]
**as_self** | **bool**| GET object as Self | [optional] [default to true]
**states** | [**list[str]**](str.md)| Search for Slices in the specified states | [optional]
**limit** | **int**| maximum number of results to return per page (1 or more) | [optional] [default to 5]
Expand Down
2 changes: 1 addition & 1 deletion fabric_cf/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.6.0"
__version__ = "1.7.0b1"
29 changes: 21 additions & 8 deletions fabric_cf/orchestrator/orchestrator_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def delete(self, *, token: str, slice_id: str = None) -> Tuple[Status, Union[Exc

def slices(self, *, token: str, includes: List[SliceState] = None, excludes: List[SliceState] = None,
name: str = None, limit: int = 20, offset: int = 0, slice_id: str = None,
as_self: bool = True) -> Tuple[Status, Union[Exception, List[Slice]]]:
as_self: bool = True, search: str = None, exact_match: bool = False) -> Tuple[Status, Union[Exception, List[Slice]]]:
"""
Get slices
@param token fabric token
Expand All @@ -288,7 +288,9 @@ def slices(self, *, token: str, includes: List[SliceState] = None, excludes: Lis
@param limit maximum number of slices to return
@param offset offset of the first slice to return
@param slice_id Slice Id
@param as_self
@param as_self query as self
@param search search term
@param exact_match true if exact match
@return Tuple containing Status and Exception/Json containing slices
"""
if token is None:
Expand All @@ -314,10 +316,12 @@ def slices(self, *, token: str, includes: List[SliceState] = None, excludes: Lis
as_self=as_self)
elif name is not None:
slices = self.slices_api.slices_get(states=SliceState.state_list_to_str_list(states), name=name,
limit=limit, offset=offset, as_self=as_self)
limit=limit, offset=offset, as_self=as_self,
search=search, exact_match=exact_match)
else:
slices = self.slices_api.slices_get(states=SliceState.state_list_to_str_list(states), limit=limit,
offset=offset, as_self=as_self)
offset=offset, as_self=as_self, search=search,
exact_match=exact_match)

return Status.OK, slices.data if slices.data is not None else []
except Exception as e:
Expand Down Expand Up @@ -388,24 +392,33 @@ def slivers(self, *, token: str, slice_id: str,
except Exception as e:
return Status.FAILURE, e

def resources(self, *, token: str, level: int = 1,
force_refresh: bool = False) -> Tuple[Status, Union[Exception, AdvertizedTopology]]:
def resources(self, *, token: str, level: int = 1, force_refresh: bool = False,
start: datetime = None, end: datetime = None,
includes: List[str] = None, excludes: List[str] = None) -> Tuple[Status, Union[Exception, AdvertizedTopology]]:
"""
Get resources; by default cached resource information is returned. Cache is refreshed every 5 minutes.
@param token fabric token
@param level level
@param force_refresh force current available resources
@param start start time
@param end end time
@param includes list of sites to include
@param excludes list of sites to exclude
@return Tuple containing Status and Exception/Json containing Resources
"""

if token is None:
return Status.INVALID_ARGUMENTS, OrchestratorProxyException(f"Token {token} must be specified")

try:
# Set the tokens
self.__set_tokens(token=token)

resources = self.resources_api.resources_get(level=level, force_refresh=force_refresh)
start_date = start.strftime('%Y-%m-%d %H:%M:%S %z') if start else None
end_date = end.strftime('%Y-%m-%d %H:%M:%S %z') if end else None
resources = self.resources_api.resources_get(level=level, force_refresh=force_refresh,
start_date=start_date, end_date=end_date,
includes=', '.join(includes) if includes else None,
excludes=', '.join(excludes) if excludes else None)
graph_string = resources.data[0].model
substrate = None
if graph_string is not None:
Expand Down
Loading

0 comments on commit 90e2f87

Please sign in to comment.