-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: gran <gran@vmware.com>
- Loading branch information
Showing
10 changed files
with
183 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/openlyinc/pointy" | ||
"github.com/vmware/vsphere-automation-sdk-go/runtime/data" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" | ||
) | ||
|
||
// WrapInfra TODO(gran) refactor existing code in other package | ||
func (service *Service) WrapInfra(children []*data.StructValue) (*model.Infra, error) { | ||
// This is the outermost layer of the hierarchy infra client. | ||
// It doesn't need ID field. | ||
resourceType := ResourceTypeInfra | ||
infraObj := model.Infra{ | ||
Children: children, | ||
ResourceType: &resourceType, | ||
} | ||
return &infraObj, nil | ||
} | ||
|
||
func (service *Service) WrapVPC(vpc *model.Vpc) ([]*data.StructValue, error) { | ||
var vpcChildren []*data.StructValue | ||
vpc.ResourceType = pointy.String(ResourceTypeVpc) | ||
childVpc := model.ChildVpc{ | ||
Id: vpc.Id, | ||
MarkedForDelete: vpc.MarkedForDelete, | ||
ResourceType: "ChildVpc", | ||
Vpc: vpc, | ||
} | ||
dataValue, errs := NewConverter().ConvertToVapi(childVpc, childVpc.GetType__()) | ||
if len(errs) > 0 { | ||
return nil, errs[0] | ||
} | ||
vpcChildren = append(vpcChildren, dataValue.(*data.StructValue)) | ||
return vpcChildren, nil | ||
} | ||
|
||
func (service *Service) WrapLBS(lbs *model.LBService) ([]*data.StructValue, error) { | ||
var lbServiceChildren []*data.StructValue | ||
lbs.ResourceType = pointy.String(ResourceTypeLBService) | ||
childLBService := model.ChildLBService{ | ||
Id: lbs.Id, | ||
MarkedForDelete: lbs.MarkedForDelete, | ||
ResourceType: "ChildLBService", | ||
LbService: lbs, | ||
} | ||
dataValue, errs := NewConverter().ConvertToVapi(childLBService, childLBService.GetType__()) | ||
if len(errs) > 0 { | ||
return nil, errs[0] | ||
} | ||
lbServiceChildren = append(lbServiceChildren, dataValue.(*data.StructValue)) | ||
return lbServiceChildren, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package vpc | ||
|
||
import ( | ||
"github.com/vmware/vsphere-automation-sdk-go/runtime/data" | ||
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" | ||
) | ||
|
||
func (s *VPCService) WrapHierarchyVPC(vpc *model.Vpc, lbs *model.LBService) (*model.Infra, error) { | ||
if lbs != nil { | ||
var vpcChildren []*data.StructValue | ||
lbsChildren, err := s.WrapLBS(lbs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
vpcChildren = append(vpcChildren, lbsChildren...) | ||
vpc.Children = vpcChildren | ||
} | ||
var infraChildren []*data.StructValue | ||
vpcChildren, err := s.WrapVPC(vpc) | ||
if err != nil { | ||
return nil, err | ||
} | ||
infraChildren = append(infraChildren, vpcChildren...) | ||
|
||
infra, err := s.WrapInfra(infraChildren) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return infra, nil | ||
} |