v16.3.0
v16.3.0
This commit is contained in:
1 parent
dbd979b6f3
commit
4c05d94552
20 files changed
+691
-104
No files matched your search
@@ -116,6 +116,11 @@ type wrapperCreateRequest struct {
|
||||
Routes []string `url:"routes,omitempty"`
|
||||
}
|
||||
|
||||
type asyncWrapperCreateRequest struct {
|
||||
wrapperCreateRequest
|
||||
AsyncMode bool `url:"async_mode"`
|
||||
}
|
||||
|
||||
// Create creates new external network into platform
|
||||
func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
@@ -145,9 +150,14 @@ func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
Routes: routes,
|
||||
}
|
||||
|
||||
reqWrappedAsync := asyncWrapperCreateRequest{
|
||||
wrapperCreateRequest: reqWrapped,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/create"
|
||||
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||
res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrappedAsync)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -159,3 +169,54 @@ func (e ExtNet) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// AsyncCreate creates new external network into platform in async mode
|
||||
func (e ExtNet) AsyncCreate(ctx context.Context, req CreateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
var routes []string
|
||||
|
||||
if len(req.Routes) != 0 {
|
||||
routes = make([]string, 0, len(req.Routes))
|
||||
|
||||
for r := range req.Routes {
|
||||
b, err := json.Marshal(req.Routes[r])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
routes = append(routes, string(b))
|
||||
}
|
||||
} else {
|
||||
routes = []string{}
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateRequest{
|
||||
CreateRequest: req,
|
||||
Routes: routes,
|
||||
}
|
||||
|
||||
reqWrappedAsync := asyncWrapperCreateRequest{
|
||||
wrapperCreateRequest: reqWrapped,
|
||||
AsyncMode: true,
|
||||
}
|
||||
|
||||
url := "/cloudbroker/extnet/create"
|
||||
|
||||
result, err := e.client.DecortApiCall(ctx, http.MethodPost, url, reqWrappedAsync)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var resp string
|
||||
|
||||
err = json.Unmarshal(result, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
Reference in new issue
Block a user