| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package compute
- import (
- "fmt"
- "yunion.io/x/jsonutils"
- baseoptions "yunion.io/x/onecloud/pkg/mcclient/options"
- )
- type Route struct {
- Type string
- Cidr string
- NextHopType string
- NextHopId string
- }
- type Routes []*Route
- type RoutesOptions struct {
- Type []string
- Cidr []string
- NextHopType []string
- NextHopId []string
- }
- func (opts *RoutesOptions) Params() (jsonutils.JSONObject, error) {
- len0 := len(opts.Type)
- len1 := len(opts.Cidr)
- if len0 != len1 || len0 != len(opts.NextHopType) || len1 != len(opts.NextHopId) {
- return nil, fmt.Errorf("there must be equal number of options for each route")
- }
- routes := []*Route{}
- for i := 0; i < len0; i++ {
- routes = append(routes, &Route{
- Type: opts.Type[i],
- Cidr: opts.Cidr[i],
- NextHopType: opts.NextHopType[i],
- NextHopId: opts.NextHopId[i],
- })
- }
- routesJson := jsonutils.Marshal(routes)
- return routesJson, nil
- }
- type RouteTableCreateOptions struct {
- NAME string
- Vpc string `required:"true"`
- RoutesOptions
- }
- func (opts *RouteTableCreateOptions) Params() (jsonutils.JSONObject, error) {
- params, err := baseoptions.StructToParams(opts)
- if err != nil {
- return nil, err
- }
- routesJson, err := opts.RoutesOptions.Params()
- if err != nil {
- return nil, err
- }
- params.Set("routes", routesJson)
- return params, nil
- }
- type RouteTableGetOptions struct {
- ID string
- }
- type RouteTableIdOptions struct {
- ID string
- }
- func (opts *RouteTableIdOptions) GetId() string {
- return opts.ID
- }
- func (opts *RouteTableIdOptions) Params() (jsonutils.JSONObject, error) {
- return nil, nil
- }
- type RouteTableUpdateOptions struct {
- ID string `json:"-"`
- Name string
- RoutesOptions
- }
- func (opts *RouteTableUpdateOptions) GetId() string {
- return opts.ID
- }
- func (opts *RouteTableUpdateOptions) Params() (jsonutils.JSONObject, error) {
- params, err := baseoptions.StructToParams(opts)
- if err != nil {
- return nil, err
- }
- if len(opts.Cidr) != 0 {
- routesJson, err := opts.RoutesOptions.Params()
- if err != nil {
- return nil, err
- }
- params.Set("routes", routesJson)
- }
- return params, nil
- }
- type RouteTableAddRoutesOptions struct {
- ID string `json:"-"`
- RoutesOptions
- }
- func (opts *RouteTableAddRoutesOptions) GetId() string {
- return opts.ID
- }
- func (opts *RouteTableAddRoutesOptions) Params() (jsonutils.JSONObject, error) {
- if len(opts.Cidr) == 0 {
- return nil, fmt.Errorf("nothing to add")
- }
- routesJson, err := opts.RoutesOptions.Params()
- if err != nil {
- return nil, err
- }
- params := jsonutils.NewDict()
- params.Set("routes", routesJson)
- return params, nil
- }
- type RouteTableDelRoutesOptions struct {
- ID string `json:"-"`
- Cidr []string
- }
- func (opts *RouteTableDelRoutesOptions) GetId() string {
- return opts.ID
- }
- func (opts *RouteTableDelRoutesOptions) Params() (jsonutils.JSONObject, error) {
- if len(opts.Cidr) == 0 {
- return nil, fmt.Errorf("nothing to del")
- }
- params := jsonutils.NewDict()
- params.Set("cidrs", jsonutils.Marshal(opts.Cidr))
- return params, nil
- }
- type RouteTableDeleteOptions struct {
- ID string
- }
- type RouteTablePurgeOptions struct {
- ID string
- }
- type RouteTableListOptions struct {
- Vpc string
- Cloudregion string
- baseoptions.BaseListOptions
- }
- func (opts *RouteTableListOptions) Params() (jsonutils.JSONObject, error) {
- return baseoptions.ListStructToParams(opts)
- }
- type RouteTableSyncstatusOptions struct {
- ID string
- }
|