Skip to content

Commit

Permalink
Merge pull request #2623 from HakanSunay/issue-2622
Browse files Browse the repository at this point in the history
Refactor EAM code to use BaseAgencyConfigInfo interface instead of impl
  • Loading branch information
akutz authored Oct 14, 2021
2 parents df705a2 + 68b5458 commit 98d4902
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion eam/mo/agency.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Agency struct {
EamObject `yaml:",inline"`

Agent []vim.ManagedObjectReference `json:"agent,omitempty"`
Config types.AgencyConfigInfo `json:"config"`
Config types.BaseAgencyConfigInfo `json:"config"`
Runtime types.EamObjectRuntimeInfo `json:"runtime"`
SolutionId string `json:"solutionId,omitempty"`
}
4 changes: 2 additions & 2 deletions eam/mo/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/vmware/govmomi/eam/types"
)

// Agenct is the vSphere ESX Agent Manager managed object responsible
// fordeploying an Agency on a single host. The Agent maintains the state
// Agent is the vSphere ESX Agent Manager managed object responsible
// for deploying an Agency on a single host. The Agent maintains the state
// of the current deployment in its runtime information
type Agent struct {
EamObject `yaml:",inline"`
Expand Down
9 changes: 5 additions & 4 deletions eam/object/agency.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func (m Agency) Agents(ctx context.Context) ([]Agent, error) {
return objs, nil
}

func (m Agency) Config(ctx context.Context) (*types.AgencyConfigInfo, error) {
func (m Agency) Config(ctx context.Context) (types.BaseAgencyConfigInfo, error) {
resp, err := methods.QueryConfig(ctx, m.c, &types.QueryConfig{
This: m.r,
})
if err != nil {
return nil, err
}
return resp.Returnval.GetAgencyConfigInfo(), nil
return resp.Returnval, nil
}

func (m Agency) Runtime(ctx context.Context) (*types.EamObjectRuntimeInfo, error) {
Expand Down Expand Up @@ -154,10 +154,11 @@ func (m Agency) UnregisterAgentVm(

func (m Agency) Update(
ctx context.Context,
config types.AgencyConfigInfo) error {
config types.BaseAgencyConfigInfo) error {

_, err := methods.Update(ctx, m.c, &types.Update{
This: m.r,
This: m.r,
Config: config,
})
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions eam/object/agency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAgency(t *testing.T) {
)
var (
agency object.Agency
agencyConfig = types.AgencyConfigInfo{
agencyConfig = &types.AgencyConfigInfo{
AgencyName: t.Name(),
AgentName: t.Name(),
AgentConfig: []types.AgentConfigInfo{
Expand Down Expand Up @@ -135,10 +135,11 @@ func TestAgency(t *testing.T) {
testConfig := func(t *testing.T) {
t.Parallel()

config, err := agency.Config(client.ctx)
baseConfig, err := agency.Config(client.ctx)
if err != nil {
t.Fatal(err)
}
config := baseConfig.GetAgencyConfigInfo()
if config.AgencyName != agencyConfig.AgencyName {
t.Fatalf(
"unexpected agency name: exp=%v, act=%v",
Expand Down
4 changes: 2 additions & 2 deletions eam/object/esx_agent_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func NewEsxAgentManager(c *eam.Client, ref vim.ManagedObjectReference) EsxAgentM

func (m EsxAgentManager) CreateAgency(
ctx context.Context,
config types.AgencyConfigInfo,
config types.BaseAgencyConfigInfo,
initialGoalState string) (Agency, error) {

var agency Agency
resp, err := methods.CreateAgency(ctx, m.c, &types.CreateAgency{
This: m.r,
AgencyConfigInfo: config.GetAgencyConfigInfo(),
AgencyConfigInfo: config,
InitialGoalState: initialGoalState,
})
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions eam/simulator/agency.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ type Agency struct {
// EsxAgentManager object.
func NewAgency(
ctx *simulator.Context,
agencyConfig types.AgencyConfigInfo,
baseAgencyConfig types.BaseAgencyConfigInfo,
initialGoalState string) (*Agency, vim.BaseMethodFault) {

agencyConfig := baseAgencyConfig.GetAgencyConfigInfo()
if agencyConfig.AgentName == "" {
agencyConfig.AgentName = agencyConfig.AgencyName
}
Expand Down Expand Up @@ -197,7 +198,7 @@ func (m *Agency) QueryConfig(

return &methods.QueryConfigBody{
Res: &types.QueryConfigResponse{
Returnval: &m.Config,
Returnval: m.Config,
},
}
}
Expand Down Expand Up @@ -237,7 +238,7 @@ func (m *Agency) Update(
ctx *simulator.Context,
req *types.Update) soap.HasFault {

m.Config = *req.Config.GetAgencyConfigInfo()
m.Config = req.Config

return &methods.UpdateBody{
Res: &types.UpdateResponse{},
Expand Down
2 changes: 1 addition & 1 deletion eam/simulator/esx_agent_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m *EsxAgentManager) CreateAgency(

if agency, err := NewAgency(
ctx,
*req.AgencyConfigInfo.GetAgencyConfigInfo(),
req.AgencyConfigInfo,
req.InitialGoalState); err != nil {

res.Fault_ = simulator.Fault("", err)
Expand Down
2 changes: 1 addition & 1 deletion eam/simulator/simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestSimulator(t *testing.T) {
t.Log("creating a new agency")
agency, err := mgr.CreateAgency(
ctx,
types.AgencyConfigInfo{
&types.AgencyConfigInfo{
AgencyName: "nginx",
AgentVmDatastore: []vim.ManagedObjectReference{
datastore.Reference(),
Expand Down
4 changes: 2 additions & 2 deletions eam/simulator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func getAgentVMPlacementOptions(
ctx *simulator.Context,
reg *simulator.Registry,
r *rand.Rand, i int,
agencyConfig types.AgencyConfigInfo) (AgentVMPlacementOptions, error) {
baseAgencyConfig types.BaseAgencyConfigInfo) (AgentVMPlacementOptions, error) {

var opts AgentVMPlacementOptions

agencyConfig := baseAgencyConfig.GetAgencyConfigInfo()
if l := len(agencyConfig.AgentVmDatastore); l == 0 {
return opts, agentVmDatastoreEmptyErr
} else if l == len(agencyConfig.AgentConfig) {
Expand Down

0 comments on commit 98d4902

Please sign in to comment.