cloudnet: initial version

This commit is contained in:
Yousong Zhou
2019-10-18 03:40:53 +00:00
parent 5b8fdcd5af
commit 0b6d33d4fc
43 changed files with 3778 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
func NewCloudnetManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager {
return modulebase.ResourceManager{
BaseManager: *modulebase.NewBaseManager("cloudnet", "", "", columns, adminColumns),
Keyword: keyword, KeywordPlural: keywordPlural}
}
var (
registerV2 = func(mod modulebase.BaseManagerInterface) {
modulebase.Register("v2", mod)
}
)
+1
View File
@@ -0,0 +1 @@
package cloudnet // import "yunion.io/x/onecloud/pkg/mcclient/modules/cloudnet"
@@ -0,0 +1,42 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
type MeshNetworkManager struct {
modulebase.ResourceManager
}
var (
MeshNetworks MeshNetworkManager
)
func init() {
MeshNetworks = MeshNetworkManager{
NewCloudnetManager(
"meshnetwork",
"meshnetworks",
[]string{
"id",
"name",
},
[]string{"tenant"},
),
}
registerV2(&MeshNetworks)
}
@@ -0,0 +1,45 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
type RouterManager struct {
modulebase.ResourceManager
}
var (
Routers RouterManager
)
func init() {
Routers = RouterManager{
NewCloudnetManager(
"router",
"routers",
[]string{
"id",
"name",
"user",
"host",
"port",
},
[]string{"tenant"},
),
}
registerV2(&Routers)
}
@@ -0,0 +1,46 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
type RouteManager struct {
modulebase.ResourceManager
}
var (
Routes RouteManager
)
func init() {
Routes = RouteManager{
NewCloudnetManager(
"route",
"routes",
[]string{
"id",
"name",
"iface_id",
"ifname",
"network",
"gateway",
},
[]string{"tenant"},
),
}
registerV2(&Routes)
}
@@ -0,0 +1,51 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
type RuleManager struct {
modulebase.ResourceManager
}
var (
Rules RuleManager
)
func init() {
Rules = RuleManager{
NewCloudnetManager(
"rule",
"rules",
[]string{
"id",
"name",
"router_id",
"match_src_net",
"match_dest_net",
"match_proto",
"match_port",
"match_in_ifname",
"match_out_ifname",
"action",
"action_options",
},
[]string{"tenant"},
),
}
registerV2(&Rules)
}
+1
View File
@@ -0,0 +1 @@
package cloudnet // import "yunion.io/x/onecloud/pkg/mcclient/options/cloudnet"
@@ -0,0 +1,44 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type MeshNetworkCreateOptions struct {
NAME string
}
type MeshNetworkGetOptions struct {
ID string `json:"-"`
}
type MeshNetworkUpdateOptions struct {
ID string `json:"-"`
Name string
}
type MeshNetworkDeleteOptions struct {
ID string `json:"-"`
}
type MeshNetworkListOptions struct {
options.BaseListOptions
}
type MeshNetworkActionRealizeOptions struct {
ID string `json:"-"`
}
+120
View File
@@ -0,0 +1,120 @@
// 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 cloudnet
import (
"io/ioutil"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type RouterCreateOptions struct {
NAME string
User string
Host string
Port int
PrivateKey string
RealizeWgIfaces string `choices:"on|off" default:"on" help:"apply wg ifaces config on realization"`
RealizeRoutes string `choices:"on|off" default:"on" help:"apply routes config on realization"`
RealizeRules string `choices:"on|off" default:"on" help:"apply firewall rules on realization"`
}
func (opts *RouterCreateOptions) Params() (jsonutils.JSONObject, error) {
params, err := options.StructToParams(opts)
if err != nil {
return nil, err
}
if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' {
data, err := ioutil.ReadFile(opts.PrivateKey[1:])
if err != nil {
return nil, err
}
params.Set("private_key", jsonutils.NewString(string(data)))
}
return params, nil
}
type RouterGetOptions struct {
ID string `json:"-"`
}
type RouterUpdateOptions struct {
ID string `json:"-"`
Name string
User string
Host string
Port int `json:",omitzero"`
PrivateKey string
RealizeWgIfaces string `json:",omitzero" choices:"on|off" help:"apply wg ifaces config on realization"`
RealizeRoutes string `json:",omitzero" choices:"on|off" help:"apply routes config on realization"`
RealizeRules string `json:",omitzero" choices:"on|off" help:"apply firewall rules on realization"`
}
func (opts *RouterUpdateOptions) Params() (jsonutils.JSONObject, error) {
params, err := options.StructToParams(opts)
if err != nil {
return nil, err
}
if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' {
data, err := ioutil.ReadFile(opts.PrivateKey[1:])
if err != nil {
return nil, err
}
params.Set("private_key", jsonutils.NewString(string(data)))
}
return params, nil
}
type RouterDeleteOptions struct {
ID string `json:"-"`
}
type RouterListOptions struct {
options.BaseListOptions
}
type RouterActionJoinMeshNetworkOptions struct {
ID string `json:"-"`
MeshNetwork string
AdvertiseSubnets string `help:"cidr concatenated by comma"`
}
type RouterActionLeaveMeshNetworkOptions struct {
ID string `json:"-"`
MeshNetwork string
}
type RouterActionRegisterIfnameOptions struct {
ID string `json:"-"`
Ifname string
}
type RouterActionUnregisterIfnameOptions struct {
ID string `json:"-"`
Ifname string
}
type RouterActionRealizeOptions struct {
ID string `json:"-"`
}
+51
View File
@@ -0,0 +1,51 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type RouteCreateOptions struct {
NAME string
Iface string `required:"true"`
Network string
Gateway string
}
type RouteGetOptions struct {
ID string `json:"-"`
}
type RouteUpdateOptions struct {
ID string `json:"-"`
Name string
Network string
Gateway string
}
type RouteDeleteOptions struct {
ID string `json:"-"`
}
type RouteListOptions struct {
options.BaseListOptions
Iface string
Network string
Gateway string
}
+77
View File
@@ -0,0 +1,77 @@
// 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 cloudnet
import (
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type RuleCreateOptions struct {
NAME string
Router string `required:"true"`
MatchSrcNet string
MatchDestNet string
MatchProto string
MatchSrcPort int
MatchDestPort int
MatchInIfname string
MatchOutIfname string
Action string
ActionOptions string
}
type RuleGetOptions struct {
ID string `json:"-"`
}
type RuleUpdateOptions struct {
ID string `json:"-"`
Name string
MatchSrcNet string
MatchDestNet string
MatchProto string
MatchSrcPort int `json:",omitzero"`
MatchDestPort int `json:",omitzero"`
MatchInIfname string
MatchOutIfname string
Action string
ActionOptions string
}
type RuleDeleteOptions struct {
ID string `json:"-"`
}
type RuleListOptions struct {
options.BaseListOptions
Router string
MatchSrcNet string
MatchDestNet string
MatchProto string
MatchSrcPort int `json:",omitzero"`
MatchDestPort int `json:",omitzero"`
MatchInIfname string
MatchOutIfname string
Action string
ActionOptions string
}