Skip to content

Commit

Permalink
Merge pull request #53 from fabric-testbed/adv-res
Browse files Browse the repository at this point in the history
Adv reservation support
  • Loading branch information
kthare10 authored Jun 24, 2024
2 parents 90e2f87 + e375c1a commit 70eb7e5
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 21 deletions.
9 changes: 9 additions & 0 deletions docs/Metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Metrics

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**results** | **list[object]** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

56 changes: 56 additions & 0 deletions docs/MetricsApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# swagger_client.MetricsApi

All URIs are relative to *http://127.0.0.1:8700/*

Method | HTTP request | Description
------------- | ------------- | -------------
[**metrics_overview_get**](MetricsApi.md#metrics_overview_get) | **GET** /metrics/overview | Control Framework metrics overview

# **metrics_overview_get**
> Metrics metrics_overview_get(excluded_projects=excluded_projects)
Control Framework metrics overview

Control Framework metrics overview

### Example
```python
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint

# create an instance of the API class
api_instance = swagger_client.MetricsApi()
excluded_projects = ['excluded_projects_example'] # list[str] | List of projects to exclude from the metrics overview (optional)

try:
# Control Framework metrics overview
api_response = api_instance.metrics_overview_get(excluded_projects=excluded_projects)
pprint(api_response)
except ApiException as e:
print("Exception when calling MetricsApi->metrics_overview_get: %s\n" % e)
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**excluded_projects** | [**list[str]**](str.md)| List of projects to exclude from the metrics overview | [optional]

### Return type

[**Metrics**](Metrics.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

[[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)

12 changes: 7 additions & 5 deletions docs/SlicesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ Name | Type | Description | Notes

### HTTP request headers

- **Content-Type**: text/plain
- **Content-Type**: application/json
- **Accept**: application/json

[[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)

# **slices_creates_post**
> Slivers slices_creates_post(body, name, lease_end_time=lease_end_time)
> Slivers slices_creates_post(body, name, lease_start_time=lease_start_time, lease_end_time=lease_end_time)
Create slice

Expand All @@ -101,11 +101,12 @@ configuration.api_key['Authorization'] = 'YOUR_API_KEY'
api_instance = SlicesApi(ApiClient(configuration))
body = SlicesPost() # SlicesPost | Create new Slice
name = 'name_example' # str | Slice Name
lease_start_time = 'lease_start_time_example' # str | Lease End Time for the Slice (optional)
lease_end_time = 'lease_end_time_example' # str | Lease End Time for the Slice (optional)

try:
# Create slice
api_response = api_instance.slices_creates_post(body, name, lease_end_time=lease_end_time)
api_response = api_instance.slices_creates_post(body, name, lease_start_time=lease_start_time, lease_end_time=lease_end_time)
pprint(api_response)
except ApiException as e:
print("Exception when calling SlicesApi->slices_creates_post: %s\n" % e)
Expand All @@ -117,6 +118,7 @@ Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**SlicesPost**](SlicesPost.md)| Create new Slice |
**name** | **str**| Slice Name |
**lease_start_time** | **str**| Lease End Time for the Slice | [optional]
**lease_end_time** | **str**| Lease End Time for the Slice | [optional]

### Return type
Expand Down Expand Up @@ -240,7 +242,7 @@ Name | Type | Description | Notes
[[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)

# **slices_get**
> Slices slices_get(name=name, as_self=as_self, states=states, limit=limit, offset=offset)
> Slices slices_get(name=name, search=search, exact_match=exact_match, as_self=as_self, states=states, limit=limit, offset=offset)
Retrieve a listing of user slices

Expand Down Expand Up @@ -398,7 +400,7 @@ except ApiException as e:

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**body** | [**str**](str.md)| | Modify a Slice
**body** | [**str**](str.md)| Modify a Slice |
**slice_id** | **str**| Slice identified by universally unique identifier |

### Return type
Expand Down
Binary file added fabric_cf/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion fabric_cf/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.7.0b1"
__version__ = "1.7.0b8"
46 changes: 36 additions & 10 deletions fabric_cf/orchestrator/orchestrator_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class SliceState(enum.Enum):
Modifying = enum.auto()
ModifyError = enum.auto()
ModifyOK = enum.auto()
AllocatedError = enum.auto()
AllocatedOK = enum.auto()

def __str__(self):
return self.name
Expand Down Expand Up @@ -123,6 +125,7 @@ def __init__(self, orchestrator_host: str):
self.slivers_api = swagger_client.SliversApi(api_client=api_instance)
self.resources_api = swagger_client.ResourcesApi(api_client=api_instance)
self.poas_api = swagger_client.PoasApi(api_client=api_instance)
self.metrics_api = swagger_client.MetricsApi(api_client=api_instance)

def __set_tokens(self, *, token: str):
"""
Expand All @@ -134,7 +137,7 @@ def __set_tokens(self, *, token: str):
self.slices_api.api_client.configuration.api_key_prefix[self.PROP_AUTHORIZATION] = self.PROP_BEARER

def create(self, *, token: str, slice_name: str, ssh_key: Union[str, List[str]],
topology: ExperimentTopology = None, slice_graph: str = None,
topology: ExperimentTopology = None, slice_graph: str = None, lease_start_time: str = None,
lease_end_time: str = None) -> Tuple[Status, Union[Exception, List[Sliver]]]:
"""
Create a slice
Expand All @@ -143,6 +146,7 @@ def create(self, *, token: str, slice_name: str, ssh_key: Union[str, List[str]],
@param ssh_key SSH Key(s)
@param topology Experiment topology
@param slice_graph Slice Graph string
@param lease_start_time Lease Start Time
@param lease_end_time Lease End Time
@return Tuple containing Status and Exception/Json containing slivers created
"""
Expand All @@ -158,6 +162,13 @@ def create(self, *, token: str, slice_name: str, ssh_key: Union[str, List[str]],
f"slice graph {slice_graph} must "
f"be specified")

if lease_start_time is not None:
try:
datetime.strptime(lease_start_time, self.TIME_FORMAT)
except Exception as e:
return Status.INVALID_ARGUMENTS, OrchestratorProxyException(
f"Lease Stat Time {lease_start_time} should be in format: {self.TIME_FORMAT} e: {e}")

if lease_end_time is not None:
try:
datetime.strptime(lease_end_time, self.TIME_FORMAT)
Expand All @@ -177,11 +188,9 @@ def create(self, *, token: str, slice_name: str, ssh_key: Union[str, List[str]],
else:
ssh_keys = ssh_key
body = SlicesPost(graph_model=slice_graph, ssh_keys=ssh_keys)
if lease_end_time is not None:
slivers = self.slices_api.slices_creates_post(name=slice_name, body=body, lease_end_time=lease_end_time)
else:
slivers = self.slices_api.slices_creates_post(name=slice_name, body=body)

slivers = self.slices_api.slices_creates_post(name=slice_name, body=body,
lease_end_time=lease_end_time,
lease_start_time=lease_start_time)
return Status.OK, slivers.data if slivers.data is not None else []
except Exception as e:
return Status.FAILURE, e
Expand Down Expand Up @@ -302,7 +311,8 @@ def slices(self, *, token: str, includes: List[SliceState] = None, excludes: Lis

states = [SliceState.StableError, SliceState.StableOK, SliceState.Nascent,
SliceState.Configuring, SliceState.Closing, SliceState.Dead,
SliceState.ModifyError, SliceState.ModifyOK, SliceState.Modifying]
SliceState.ModifyError, SliceState.ModifyOK, SliceState.Modifying,
SliceState.AllocatedOK, SliceState.AllocatedError]
if includes is not None:
states = includes

Expand Down Expand Up @@ -413,8 +423,8 @@ def resources(self, *, token: str, level: int = 1, force_refresh: bool = False,
# Set the tokens
self.__set_tokens(token=token)

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
start_date = start.strftime(self.TIME_FORMAT) if start else None
end_date = end.strftime(self.TIME_FORMAT) 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,
Expand Down Expand Up @@ -547,4 +557,20 @@ def get_poas(self, *, token: str, sliver_id: str = None,

return Status.OK, poa_data.data if poa_data.data is not None else None
except Exception as e:
return Status.FAILURE, e
return Status.FAILURE, e

def get_metrics_overview(self, *, token: str = None,
excluded_projects: List[str] = None) -> Tuple[Status, Union[Exception, list]]:
"""
Modify a slice
@param token fabric token
@param excluded_projects list of project ids to exclude
@return Tuple containing Status and Exception/Json containing poa info created
"""
try:
# Set the tokens
self.__set_tokens(token=token)
result = self.metrics_api.metrics_overview_get(excluded_projects=excluded_projects)
return Status.OK, result.results
except Exception as e:
return Status.FAILURE, e
2 changes: 2 additions & 0 deletions fabric_cf/orchestrator/swagger_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import absolute_import

# import apis into sdk package
from fabric_cf.orchestrator.swagger_client.api.metrics_api import MetricsApi
from fabric_cf.orchestrator.swagger_client.api.poas_api import PoasApi
from fabric_cf.orchestrator.swagger_client.api.resources_api import ResourcesApi
from fabric_cf.orchestrator.swagger_client.api.slices_api import SlicesApi
Expand All @@ -24,6 +25,7 @@
from fabric_cf.orchestrator.swagger_client.api_client import ApiClient
from fabric_cf.orchestrator.swagger_client.configuration import Configuration
# import models into sdk package
from fabric_cf.orchestrator.swagger_client.models.metrics import Metrics
from fabric_cf.orchestrator.swagger_client.models.poa import Poa
from fabric_cf.orchestrator.swagger_client.models.poa_data import PoaData
from fabric_cf.orchestrator.swagger_client.models.poa_post import PoaPost
Expand Down
1 change: 1 addition & 0 deletions fabric_cf/orchestrator/swagger_client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# flake8: noqa

# import apis into api package
from fabric_cf.orchestrator.swagger_client.api.metrics_api import MetricsApi
from fabric_cf.orchestrator.swagger_client.api.poas_api import PoasApi
from fabric_cf.orchestrator.swagger_client.api.resources_api import ResourcesApi
from fabric_cf.orchestrator.swagger_client.api.slices_api import SlicesApi
Expand Down
126 changes: 126 additions & 0 deletions fabric_cf/orchestrator/swagger_client/api/metrics_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# coding: utf-8

"""
Fabric Orchestrator API
This is Fabric Orchestrator API # noqa: E501
OpenAPI spec version: 1.0.1
Contact: [email protected]
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

from __future__ import absolute_import

import re # noqa: F401

# python 2 and python 3 compatibility library
import six

from fabric_cf.orchestrator.swagger_client.api_client import ApiClient


class MetricsApi(object):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
Ref: https://github.com/swagger-api/swagger-codegen
"""

def __init__(self, api_client=None):
if api_client is None:
api_client = ApiClient()
self.api_client = api_client

def metrics_overview_get(self, **kwargs): # noqa: E501
"""Control Framework metrics overview # noqa: E501
Control Framework metrics overview # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.metrics_overview_get(async_req=True)
>>> result = thread.get()
:param async_req bool
:param list[str] excluded_projects: List of projects to exclude from the metrics overview
:return: Metrics
If the method is called asynchronously,
returns the request thread.
"""
kwargs = {key: value for key, value in kwargs.items() if value is not None}
kwargs['_return_http_data_only'] = True
if kwargs.get('async_req'):
return self.metrics_overview_get_with_http_info(**kwargs) # noqa: E501
else:
(data) = self.metrics_overview_get_with_http_info(**kwargs) # noqa: E501
return data

def metrics_overview_get_with_http_info(self, **kwargs): # noqa: E501
"""Control Framework metrics overview # noqa: E501
Control Framework metrics overview # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.metrics_overview_get_with_http_info(async_req=True)
>>> result = thread.get()
:param async_req bool
:param list[str] excluded_projects: List of projects to exclude from the metrics overview
:return: Metrics
If the method is called asynchronously,
returns the request thread.
"""

all_params = ['excluded_projects'] # noqa: E501
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')

params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method metrics_overview_get" % key
)
params[key] = val
del params['kwargs']

collection_formats = {}

path_params = {}

query_params = []
if 'excluded_projects' in params:
query_params.append(('excluded_projects', params['excluded_projects'])) # noqa: E501
collection_formats['excluded_projects'] = 'multi' # noqa: E501

header_params = {}

form_params = []
local_var_files = {}

body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.select_header_accept(
['application/json']) # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

return self.api_client.call_api(
'/metrics/overview', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='Metrics', # noqa: E501
auth_settings=auth_settings,
async_req=params.get('async_req'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
Loading

0 comments on commit 70eb7e5

Please sign in to comment.