mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #4497 from rainzm/bugfix/nat_huawei
fix(huawei): Add 'X-Project-Id' header for huawei nat reuqest
This commit is contained in:
@@ -23,7 +23,7 @@ type SNatDRuleManager struct {
|
||||
}
|
||||
|
||||
func NewNatDManager(regionId string, projectId string, signer auth.Signer, debug bool) *SNatDRuleManager {
|
||||
return &SNatDRuleManager{SResourceManager: SResourceManager{
|
||||
man := &SNatDRuleManager{SResourceManager: SResourceManager{
|
||||
SBaseManager: NewBaseManager(signer, debug),
|
||||
ServiceName: ServiceNameNAT,
|
||||
Region: regionId,
|
||||
@@ -34,4 +34,8 @@ func NewNatDManager(regionId string, projectId string, signer auth.Signer, debug
|
||||
|
||||
ResourceKeyword: "dnat_rules",
|
||||
}}
|
||||
if len(projectId) > 0 {
|
||||
man.requestHook = &sProjectHook{projectId}
|
||||
}
|
||||
return man
|
||||
}
|
||||
|
||||
@@ -16,14 +16,23 @@ package modules
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/auth"
|
||||
"yunion.io/x/onecloud/pkg/multicloud/huawei/client/requests"
|
||||
)
|
||||
|
||||
type SNatGatewayManager struct {
|
||||
SResourceManager
|
||||
}
|
||||
|
||||
type sProjectHook struct {
|
||||
projectId string
|
||||
}
|
||||
|
||||
func (self *sProjectHook) Process(request requests.IRequest) {
|
||||
request.AddHeaderParam("X-Project-Id", self.projectId)
|
||||
}
|
||||
|
||||
func NewNatGatewayManager(regionId string, projectId string, signer auth.Signer, debug bool) *SNatGatewayManager {
|
||||
return &SNatGatewayManager{SResourceManager: SResourceManager{
|
||||
man := &SNatGatewayManager{SResourceManager: SResourceManager{
|
||||
SBaseManager: NewBaseManager(signer, debug),
|
||||
ServiceName: ServiceNameNAT,
|
||||
Region: regionId,
|
||||
@@ -34,4 +43,8 @@ func NewNatGatewayManager(regionId string, projectId string, signer auth.Signer,
|
||||
|
||||
ResourceKeyword: "nat_gateways",
|
||||
}}
|
||||
if len(projectId) > 0 {
|
||||
man.requestHook = &sProjectHook{projectId}
|
||||
}
|
||||
return man
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ type SNatSRuleManager struct {
|
||||
}
|
||||
|
||||
func NewNatSManager(regionId string, projectId string, signer auth.Signer, debug bool) *SNatSRuleManager {
|
||||
return &SNatSRuleManager{SResourceManager: SResourceManager{
|
||||
man := &SNatSRuleManager{SResourceManager: SResourceManager{
|
||||
SBaseManager: NewBaseManager(signer, debug),
|
||||
ServiceName: ServiceNameNAT,
|
||||
Region: regionId,
|
||||
@@ -34,4 +34,8 @@ func NewNatSManager(regionId string, projectId string, signer auth.Signer, debug
|
||||
|
||||
ResourceKeyword: "snat_rules",
|
||||
}}
|
||||
if len(projectId) > 0 {
|
||||
man.requestHook = &sProjectHook{projectId}
|
||||
}
|
||||
return man
|
||||
}
|
||||
|
||||
@@ -171,11 +171,14 @@ func (gateway *SNatGateway) GetINatSEntryByID(id string) (cloudprovider.ICloudNa
|
||||
return &snat, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetNatGateway(natGatewayID string) ([]SNatGateway, error) {
|
||||
func (region *SRegion) GetNatGateways(vpcID, natGatewayID string) ([]SNatGateway, error) {
|
||||
queues := make(map[string]string)
|
||||
if natGatewayID != "" {
|
||||
if len(natGatewayID) != 0 {
|
||||
queues["id"] = natGatewayID
|
||||
}
|
||||
if len(vpcID) != 0 {
|
||||
queues["router_id"] = vpcID
|
||||
}
|
||||
natGateways := make([]SNatGateway, 0, 2)
|
||||
err := doListAllWithMarker(region.ecsClient.NatGateways.List, queues, &natGateways)
|
||||
if err != nil {
|
||||
@@ -187,21 +190,6 @@ func (region *SRegion) GetNatGateway(natGatewayID string) ([]SNatGateway, error)
|
||||
return natGateways, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetNatGateways(vpcID string) ([]SNatGateway, error) {
|
||||
queues := map[string]string{
|
||||
"router_id": vpcID,
|
||||
}
|
||||
natGateways := make([]SNatGateway, 0, 2)
|
||||
err := doListAllWithMarker(region.ecsClient.NatGateways.List, queues, &natGateways)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get nat gateways error by vpcid")
|
||||
}
|
||||
for i := range natGateways {
|
||||
natGateways[i].region = region
|
||||
}
|
||||
return natGateways, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) CreateNatDEntry(rule cloudprovider.SNatDRule, gatewayID string) (SNatDEntry, error) {
|
||||
params := make(map[string]interface{})
|
||||
params["nat_gateway_id"] = gatewayID
|
||||
|
||||
@@ -23,9 +23,10 @@ import (
|
||||
func init() {
|
||||
type NatGatewayOptions struct {
|
||||
NatGatewayID string `help:"Nat Gateway ID"`
|
||||
VpcID string `help:"Vpc ID"`
|
||||
}
|
||||
shellutils.R(&NatGatewayOptions{}, "nat-gateway-list", "List nat gateway", func(region *huawei.SRegion, args *NatGatewayOptions) error {
|
||||
natGateways, err := region.GetNatGateway(args.NatGatewayID)
|
||||
natGateways, err := region.GetNatGateways(args.VpcID, args.NatGatewayID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func (self *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error)
|
||||
}
|
||||
|
||||
func (self *SVpc) GetINatGateways() ([]cloudprovider.ICloudNatGateway, error) {
|
||||
nats, err := self.region.GetNatGateways(self.GetId())
|
||||
nats, err := self.region.GetNatGateways(self.GetId(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user