Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Add DrawIP Button #28

Merged
merged 3 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions pkg/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (api *APIServer) ListNetwork(
}, nil
}

// DrawIP returns new IP.
func (api *APIServer) DrawIP(
ctx context.Context,
req *serverpb.DrawIPRequest,
Expand All @@ -56,32 +57,43 @@ func (api *APIServer) DrawIP(

var n *model.Network
var err error
if req.Name == "" {
ip := &net.IPNet{
IP: net.ParseIP(req.Ip),
Mask: net.CIDRMask(int(req.Mask), 32),
var pools []*model.Pool
if req.RangeStart != "" && req.RangeEnd != "" {
s := net.ParseIP(req.RangeStart)
e := net.ParseIP(req.RangeEnd)
pool, err := api.manager.GetPool(ctx, s, e)
if err != nil {
return nil, err
}

n, err = api.manager.GetNetworkByIP(ctx, ip)
pools = []*model.Pool{pool}
} else {
n, err = api.manager.GetNetworkByName(ctx, req.Name)
}
if err != nil {
return nil, err
}
if req.Name == "" {
ip := &net.IPNet{
IP: net.ParseIP(req.Ip),
Mask: net.CIDRMask(int(req.Mask), 32),
}

pools, err := api.manager.GetPoolsInNetwork(ctx, n)
if err != nil {
return nil, err
n, err = api.manager.GetNetworkByIP(ctx, ip)
} else {
n, err = api.manager.GetNetworkByName(ctx, req.Name)
}
if err != nil {
return nil, err
}
pools, err = api.manager.GetPoolsInNetwork(ctx, n)
if err != nil {
return nil, err
}
}

if len(pools) == 0 {
return nil, status.Error(
codes.NotFound, "Not found any pools")
}

target := make([]*model.Pool, 0)
for _, p := range pools {
if p.Status == model.Pool_AVAILABLE && p.MatchTags([]*model.Tag{req.PoolTag}) {
if p.Status == model.Pool_AVAILABLE && (req.PoolTag == nil || p.MatchTags([]*model.Tag{req.PoolTag})) {
target = append(target, p)
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/server/apiclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Class | Method | HTTP request | Description
*NetworkServiceV0Api* | [**DrawIP**](docs/NetworkServiceV0Api.md#drawip) | **Get** /api/v0/network/{ip}/{mask}/drawip |
*NetworkServiceV0Api* | [**DrawIPEstimatingNetwork**](docs/NetworkServiceV0Api.md#drawipestimatingnetwork) | **Get** /api/v0/drawip |
*NetworkServiceV0Api* | [**DrawIP_0**](docs/NetworkServiceV0Api.md#drawip_0) | **Get** /api/v0/network/{name}/drawip |
*NetworkServiceV0Api* | [**DrawIP_1**](docs/NetworkServiceV0Api.md#drawip_1) | **Get** /api/v0/pool/{range_start}/{range_end}/drawip |
*NetworkServiceV0Api* | [**GetEstimatedNetwork**](docs/NetworkServiceV0Api.md#getestimatednetwork) | **Get** /api/v0/network |
*NetworkServiceV0Api* | [**GetNetwork**](docs/NetworkServiceV0Api.md#getnetwork) | **Get** /api/v0/network/{ip}/{mask} |
*NetworkServiceV0Api* | [**GetNetwork_0**](docs/NetworkServiceV0Api.md#getnetwork_0) | **Get** /api/v0/network/{name} |
Expand Down
43 changes: 41 additions & 2 deletions pkg/server/apiclient/docs/NetworkServiceV0Api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Method | HTTP request | Description
[**DrawIP**](NetworkServiceV0Api.md#DrawIP) | **Get** /api/v0/network/{ip}/{mask}/drawip |
[**DrawIPEstimatingNetwork**](NetworkServiceV0Api.md#DrawIPEstimatingNetwork) | **Get** /api/v0/drawip |
[**DrawIP_0**](NetworkServiceV0Api.md#DrawIP_0) | **Get** /api/v0/network/{name}/drawip |
[**DrawIP_1**](NetworkServiceV0Api.md#DrawIP_1) | **Get** /api/v0/pool/{range_start}/{range_end}/drawip |
[**GetEstimatedNetwork**](NetworkServiceV0Api.md#GetEstimatedNetwork) | **Get** /api/v0/network |
[**GetNetwork**](NetworkServiceV0Api.md#GetNetwork) | **Get** /api/v0/network/{ip}/{mask} |
[**GetNetwork_0**](NetworkServiceV0Api.md#GetNetwork_0) | **Get** /api/v0/network/{name} |
Expand Down Expand Up @@ -105,7 +106,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)

# **DrawIP**
> ServerpbDrawIpResponse DrawIP($ip, $mask, $poolTagKey, $poolTagValue, $name, $temporaryReserved)
> ServerpbDrawIpResponse DrawIP($ip, $mask, $poolTagKey, $poolTagValue, $name, $temporaryReserved, $rangeStart, $rangeEnd)



Expand All @@ -120,6 +121,8 @@ Name | Type | Description | Notes
**poolTagValue** | **string**| | [optional]
**name** | **string**| | [optional]
**temporaryReserved** | **bool**| | [optional]
**rangeStart** | **string**| | [optional]
**rangeEnd** | **string**| | [optional]

### Return type

Expand Down Expand Up @@ -166,7 +169,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)

# **DrawIP_0**
> ServerpbDrawIpResponse DrawIP_0($name, $ip, $mask, $poolTagKey, $poolTagValue, $temporaryReserved)
> ServerpbDrawIpResponse DrawIP_0($name, $ip, $mask, $poolTagKey, $poolTagValue, $temporaryReserved, $rangeStart, $rangeEnd)



Expand All @@ -181,6 +184,42 @@ Name | Type | Description | Notes
**poolTagKey** | **string**| | [optional]
**poolTagValue** | **string**| | [optional]
**temporaryReserved** | **bool**| | [optional]
**rangeStart** | **string**| | [optional]
**rangeEnd** | **string**| | [optional]

### Return type

[**ServerpbDrawIpResponse**](serverpbDrawIPResponse.md)

### Authorization

No authorization required

### HTTP request headers

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

# **DrawIP_1**
> ServerpbDrawIpResponse DrawIP_1($rangeStart, $rangeEnd, $ip, $mask, $poolTagKey, $poolTagValue, $name, $temporaryReserved)




### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**rangeStart** | **string**| |
**rangeEnd** | **string**| |
**ip** | **string**| | [optional]
**mask** | **int32**| | [optional]
**poolTagKey** | **string**| | [optional]
**poolTagValue** | **string**| | [optional]
**name** | **string**| | [optional]
**temporaryReserved** | **bool**| | [optional]

### Return type

Expand Down
88 changes: 85 additions & 3 deletions pkg/server/apiclient/network_service_v0_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ func (a NetworkServiceV0Api) DeleteNetwork(ip string, mask int32) (*ServerpbDele
* @param poolTagValue
* @param name
* @param temporaryReserved
* @param rangeStart
* @param rangeEnd
* @return *ServerpbDrawIpResponse
*/
func (a NetworkServiceV0Api) DrawIP(ip string, mask int32, poolTagKey string, poolTagValue string, name string, temporaryReserved bool) (*ServerpbDrawIpResponse, *APIResponse, error) {
func (a NetworkServiceV0Api) DrawIP(ip string, mask int32, poolTagKey string, poolTagValue string, name string, temporaryReserved bool, rangeStart string, rangeEnd string) (*ServerpbDrawIpResponse, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand All @@ -262,6 +264,8 @@ func (a NetworkServiceV0Api) DrawIP(ip string, mask int32, poolTagKey string, po
localVarQueryParams.Add("pool_tag.value", a.Configuration.APIClient.ParameterToString(poolTagValue, ""))
localVarQueryParams.Add("name", a.Configuration.APIClient.ParameterToString(name, ""))
localVarQueryParams.Add("temporary_reserved", a.Configuration.APIClient.ParameterToString(temporaryReserved, ""))
localVarQueryParams.Add("range_start", a.Configuration.APIClient.ParameterToString(rangeStart, ""))
localVarQueryParams.Add("range_end", a.Configuration.APIClient.ParameterToString(rangeEnd, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json"}
Expand Down Expand Up @@ -372,9 +376,11 @@ func (a NetworkServiceV0Api) DrawIPEstimatingNetwork(poolTagKey string, poolTagV
* @param poolTagKey
* @param poolTagValue
* @param temporaryReserved
* @param rangeStart
* @param rangeEnd
* @return *ServerpbDrawIpResponse
*/
func (a NetworkServiceV0Api) DrawIP_1(name string, ip string, mask int32, poolTagKey string, poolTagValue string, temporaryReserved bool) (*ServerpbDrawIpResponse, *APIResponse, error) {
func (a NetworkServiceV0Api) DrawIP_1(name string, ip string, mask int32, poolTagKey string, poolTagValue string, temporaryReserved bool, rangeStart string, rangeEnd string) (*ServerpbDrawIpResponse, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand All @@ -396,6 +402,8 @@ func (a NetworkServiceV0Api) DrawIP_1(name string, ip string, mask int32, poolTa
localVarQueryParams.Add("pool_tag.key", a.Configuration.APIClient.ParameterToString(poolTagKey, ""))
localVarQueryParams.Add("pool_tag.value", a.Configuration.APIClient.ParameterToString(poolTagValue, ""))
localVarQueryParams.Add("temporary_reserved", a.Configuration.APIClient.ParameterToString(temporaryReserved, ""))
localVarQueryParams.Add("range_start", a.Configuration.APIClient.ParameterToString(rangeStart, ""))
localVarQueryParams.Add("range_end", a.Configuration.APIClient.ParameterToString(rangeEnd, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json"}
Expand Down Expand Up @@ -433,6 +441,80 @@ func (a NetworkServiceV0Api) DrawIP_1(name string, ip string, mask int32, poolTa
return successPayload, localVarAPIResponse, err
}

/**
*
*
* @param rangeStart
* @param rangeEnd
* @param ip
* @param mask
* @param poolTagKey
* @param poolTagValue
* @param name
* @param temporaryReserved
* @return *ServerpbDrawIpResponse
*/
func (a NetworkServiceV0Api) DrawIP_2(rangeStart string, rangeEnd string, ip string, mask int32, poolTagKey string, poolTagValue string, name string, temporaryReserved bool) (*ServerpbDrawIpResponse, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
localVarPath := a.Configuration.BasePath + "/api/v0/pool/{range_start}/{range_end}/drawip"
localVarPath = strings.Replace(localVarPath, "{"+"range_start"+"}", fmt.Sprintf("%v", rangeStart), -1)
localVarPath = strings.Replace(localVarPath, "{"+"range_end"+"}", fmt.Sprintf("%v", rangeEnd), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := make(map[string]string)
var localVarPostBody interface{}
var localVarFileName string
var localVarFileBytes []byte
// add default headers if any
for key := range a.Configuration.DefaultHeader {
localVarHeaderParams[key] = a.Configuration.DefaultHeader[key]
}
localVarQueryParams.Add("ip", a.Configuration.APIClient.ParameterToString(ip, ""))
localVarQueryParams.Add("mask", a.Configuration.APIClient.ParameterToString(mask, ""))
localVarQueryParams.Add("pool_tag.key", a.Configuration.APIClient.ParameterToString(poolTagKey, ""))
localVarQueryParams.Add("pool_tag.value", a.Configuration.APIClient.ParameterToString(poolTagValue, ""))
localVarQueryParams.Add("name", a.Configuration.APIClient.ParameterToString(name, ""))
localVarQueryParams.Add("temporary_reserved", a.Configuration.APIClient.ParameterToString(temporaryReserved, ""))

// to determine the Content-Type header
localVarHttpContentTypes := []string{"application/json"}

// set Content-Type header
localVarHttpContentType := a.Configuration.APIClient.SelectHeaderContentType(localVarHttpContentTypes)
if localVarHttpContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHttpContentType
}
// to determine the Accept header
localVarHttpHeaderAccepts := []string{
"application/json",
}

// set Accept header
localVarHttpHeaderAccept := a.Configuration.APIClient.SelectHeaderAccept(localVarHttpHeaderAccepts)
if localVarHttpHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
}
var successPayload = new(ServerpbDrawIpResponse)
localVarHttpResponse, err := a.Configuration.APIClient.CallAPI(localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)

var localVarURL, _ = url.Parse(localVarPath)
localVarURL.RawQuery = localVarQueryParams.Encode()
var localVarAPIResponse = &APIResponse{Operation: "DrawIP_1", Method: localVarHttpMethod, RequestURL: localVarURL.String()}
if localVarHttpResponse != nil {
localVarAPIResponse.Response = localVarHttpResponse.RawResponse
localVarAPIResponse.Payload = localVarHttpResponse.Body()
}

if err != nil {
return successPayload, localVarAPIResponse, err
}
err = json.Unmarshal(localVarHttpResponse.Body(), &successPayload)
return successPayload, localVarAPIResponse, err
}

/**
*
*
Expand Down Expand Up @@ -563,7 +645,7 @@ func (a NetworkServiceV0Api) GetNetwork(ip string, mask int32, name string) (*Se
* @param mask
* @return *ServerpbGetNetworkResponse
*/
func (a NetworkServiceV0Api) GetNetwork_2(name string, ip string, mask int32) (*ServerpbGetNetworkResponse, *APIResponse, error) {
func (a NetworkServiceV0Api) GetNetwork_3(name string, ip string, mask int32) (*ServerpbGetNetworkResponse, *APIResponse, error) {

var localVarHttpMethod = strings.ToUpper("Get")
// create path and map variables
Expand Down
Loading