예제 #1
0
// NewAPIController creates a new controller
func NewAPIController(router *mux.Router) *APIController {
	ctrler := new(APIController)
	ctrler.router = router

	// initialize the model objects
	contivModel.Init()

	// Register Callbacks
	contivModel.RegisterAppCallbacks(ctrler)
	contivModel.RegisterEndpointGroupCallbacks(ctrler)
	contivModel.RegisterNetworkCallbacks(ctrler)
	contivModel.RegisterPolicyCallbacks(ctrler)
	contivModel.RegisterRuleCallbacks(ctrler)
	contivModel.RegisterServiceCallbacks(ctrler)
	contivModel.RegisterServiceInstanceCallbacks(ctrler)
	contivModel.RegisterTenantCallbacks(ctrler)
	contivModel.RegisterVolumeCallbacks(ctrler)
	contivModel.RegisterVolumeProfileCallbacks(ctrler)

	// Register routes
	contivModel.AddRoutes(router)

	// Add default tenant if it doesnt exist
	tenant := contivModel.FindTenant("default")
	if tenant == nil {
		log.Infof("Creating default tenant")
		err := contivModel.CreateTenant(&contivModel.Tenant{
			Key:        "default",
			TenantName: "default",
			SubnetPool: "10.1.1.1/16",
			SubnetLen:  24,
			Vlans:      "100-200",
			Vxlans:     "1001-1100",
		})
		if err != nil {
			log.Fatalf("Error creating default tenant. Err: %v", err)
		}
	}

	return ctrler
}
예제 #2
0
// NewAPIController creates a new controller
func NewAPIController(router *mux.Router) *APIController {
	ctrler := new(APIController)
	ctrler.router = router

	// initialize the model objects
	contivModel.Init()

	// Register Callbacks
	contivModel.RegisterGlobalCallbacks(ctrler)
	contivModel.RegisterAppCallbacks(ctrler)
	contivModel.RegisterEndpointGroupCallbacks(ctrler)
	contivModel.RegisterNetworkCallbacks(ctrler)
	contivModel.RegisterPolicyCallbacks(ctrler)
	contivModel.RegisterRuleCallbacks(ctrler)
	contivModel.RegisterServiceCallbacks(ctrler)
	contivModel.RegisterServiceInstanceCallbacks(ctrler)
	contivModel.RegisterTenantCallbacks(ctrler)

	// Register routes
	contivModel.AddRoutes(router)

	return ctrler
}