-
Notifications
You must be signed in to change notification settings - Fork 4
3.5 Policies management
This section overviews anti-affinity and alert policy management features available in the SDK. Note that in all examples policies
refer to the new ClcSdk().policyService()
variable.
You can asynchronously create a policy, using the AntiAffinityPolicyConfig
command. To get the result of the operation, call waitUntilComplete().getResult()
.
policies.antiAffinity().create(
new AntiAffinityPolicyConfig()
.name("My policy")
.dataCenter(DataCenter.CA_TORONTO_1)
)
.waitUntilComplete()
.getResult();
Existing policy names can be asynchronously modified, like so:
policies.antiAffinity()
.modify(
AntiAffinityPolicy.refByName(DataCenter.CA_TORONTO_1, "Policy"), //policy reference, list of refs, filter
new AntiAffinityPolicyConfig().name("New policy name")
)
.waitUntilComplete()
.getResult();
You can find anti-affinity policies by data centers, name, and ID. For instance:
policies
.antiAffinity()
.find(
new AntiAffinityPolicyFilter()
.dataCenters(DataCenter.DE_FRANKFURT)
.nameContains("PoLiCy")
);
You may delete a single policy with:
OperationFuture<AntiAffinityPolicy> future = policies.antiAffinity().delete(policyRef);
To delete a set of policies, use:
OperationFuture<List<AntiAffinityPolicy>> future =
policies.antiAffinity()
.delete(
AntiAffinityPolicy.refById("87b67bf7aee948dea939f5de2d9b2dc3"),
AntiAffinityPolicy.refByName(DataCenter.DE_FRANKFURT, "My Policy")
);
To delete a set of policies specified by some search criteria, use:
OperationFuture<List<AntiAffinityPolicy>> future =
policies.antiAffinity()
.delete(new AntiAffinityPolicyFilter()
.dataCenters(DataCenter.US_WEST_SEATTLE)
);
To see the result of the operation, call: waitUntilComplete().getResult()
.
It is possible to asynchronously create a policy, using the AlertPolicyConfig
command. To get the result of the operation, call waitUntilComplete().getResult()
. See this example:
policies.alert().create(
new AlertPolicyConfig()
.name(policyName)
.action(new AlertAction()
.settings(new ActionSettingsEmail("[email protected]"))
)
.triggers(
new AlertTrigger().duration(5).metric(AlertTriggerMetric.CPU).threshold(52.0f)
)
)
Existing policies can be asynchronously modified:
policies.alert()
.modify(AlertPolicy.refByName("Alert policy"),
new AlertPolicyConfig()
.name(newPolicyName)
.action(new AlertAction().settings(new ActionSettingsEmail("[email protected]", "[email protected]")))
.trigger(new AlertTrigger().duration(10).metric(AlertTriggerMetric.DISK).threshold(40f))
)
.waitUntilComplete()
.getResult();
You can find alert policies by name, metrics, and actions. For instance:
policies
.alert()
.find(new AlertPolicyFilter()
.nameContains("PoLiCy")
.where(ap -> ap.getTriggers().get(0).getMetric().equals(AlertTriggerMetric.CPU) &&
ap.getTriggers().get(0).getThreshold() > 20f)
);
You may delete a single policy with:
OperationFuture<AlertPolicy> future = policies.alert().delete(policyRef);
To delete a set of policies, use:
OperationFuture<List<AlertPolicy>> future =
policies.alert()
.delete(
AlertPolicy.refById("e5e2c4fa9daa460b9bf46a8028b021f9"),
AlertPolicy.refByName("My Policy")
);
To delete a set of policies specified by some search criteria, use:
OperationFuture<List<AlertPolicy>> future =
policies.alert()
.delete(new AlertPolicyFilter()
.dataCenters(DataCenter.US_WEST_SEATTLE)
);
To see the result of the operation, call: waitUntilComplete().getResult()
.
- [Getting Started] (./1.-Getting-started)
- User Guide - Basic Functions
- Server management
- Server actions
- Managing groups
- Group actions
- Searching templates
- Searching data centers
- Invoice statistics
- SDK configuration
- User Guide - Advanced Functions
- Configuring remote servers over SSH
- Defining a group hierarchy
- Billing statistics
- Server monitoring statistics
- Policies management
- Shared load balancers management
- User Guide - Framework adapters