-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While init, it will check the license from nsxt side. If CONTAINER license is disable, it will reboot. If DFW license is disable, security policy will be only response for DELETE operation. It will check license periodically. Test Done: no CONTAINER license 1. if no CONTAINER license, nsx-operator should reset CONTAINER license enable, DFW disable 1. nsx-operator could bootup 2. security policy failed to create or update 3. security policy could be deleted CONTAINER license enable, DFW enable -> CONTAINER/DFW disable 1. nsx-operator restart due to DFW changed
- Loading branch information
Showing
11 changed files
with
364 additions
and
1 deletion.
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
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,65 @@ | ||
package util | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
const ( | ||
FeatureContainer = "CONTAINER" | ||
FeatureDFW = "DFW" | ||
LicenseContainerNetwork = "CONTAINER_NETWORK" | ||
LicenseContainerSecurity = "DFW" | ||
LicenseContainer = "CONTAINER" | ||
) | ||
|
||
var ( | ||
container_network = false | ||
container_security = false | ||
licenseMutex sync.Mutex | ||
licenseMap = map[string]bool{FeatureContainer: container_network, FeatureDFW: container_security} | ||
Feature_license_map = map[string][]string{FeatureContainer: {LicenseContainerNetwork, | ||
LicenseContainerSecurity}, | ||
FeatureDFW: {LicenseContainerSecurity}} | ||
Features_to_check = []string{FeatureContainer, FeatureDFW} | ||
) | ||
|
||
type NsxLicense struct { | ||
Results []struct { | ||
FeatureName string `json:"feature_name"` | ||
IsLicensed bool `json:"is_licensed"` | ||
} `json:"results"` | ||
ResultCount int `json:"result_count"` | ||
} | ||
|
||
func IsLicensed(feature string) bool { | ||
licenseMutex.Lock() | ||
defer licenseMutex.Unlock() | ||
return licenseMap[feature] | ||
} | ||
|
||
func UpdateLicense(feature string, isLicensed bool) { | ||
licenseMutex.Lock() | ||
licenseMap[feature] = isLicensed | ||
licenseMutex.Unlock() | ||
} | ||
|
||
func searchLicense(licenses *NsxLicense, licenseNames []string) bool { | ||
license := false | ||
for _, feature := range licenses.Results { | ||
for _, licenseName := range licenseNames { | ||
if feature.FeatureName == licenseName { | ||
license = license || feature.IsLicensed | ||
} | ||
} | ||
} | ||
return license | ||
} | ||
|
||
func UpdateFeatureLicense(licenses *NsxLicense) { | ||
for _, feature := range Features_to_check { | ||
licenseNames := Feature_license_map[feature] | ||
license := searchLicense(licenses, licenseNames) | ||
UpdateLicense(feature, license) | ||
log.V(1).Info("update license", "feature", feature, "license", license) | ||
} | ||
} |
Oops, something went wrong.