Rules are used to enforce business logic and manage resources in the cloud and can be specified for hosts, cloud servers, and databases.
Checking that a rule is valid involves using the rule definition to search for cloud objects that violate the rule. Because these search queries look for violators, write the rule definition to search for objects that are not following the rule.
For example, to specify that your database must run on a cloud server that has the tag USA, define the rule as follows:
When the cloud checks that the rule is valid, it searches for the database and checks that the database is not running on a cloud server with the tag USA. If the search query returns a result, then the database is violating the rule.
Strict rules always hold. No violators of the rule can exist. If you run a task that would violate a strict rule, the task returns an error and does not run.
A strict rule can only be strict if it refers to properties that the cloud can control. For example, you can use the cloud to add, edit, and remove tags. So, you can create a strict rule that requires all hosts to have specific tags applied to them. However, because the cloud does not control the load of a cloud server, you cannot create a strict rule that requires a database to run on a cloud server with a load below a specified threshold.
Strict rules can apply to a single object or to a group of same-typed objects with the same tag(s), but not to object types. For example, you can create a rule for a specific database, or for all databases with the tag CompanyABC, but, you cannot create a strict rule that applies to all databases.
The definition for a strict rule is limited to the following subset of search syntax:
filter or filter [or filter]
filter and filter [and filter]
Strict rules applied to hosts and cloud servers only permit a tag filter. The tag filter can specify a single identifier or a name pattern (containing wildcards), optionally enclosed with double quotes or square brackets, or a list of identifiers or name patterns, separated by semicolons.
Strict rules for databases support three link filter types: tag, server, and host. You can use only one link filter type per strict rule. Unlike weak rules or search queries, a link filter for a strict rule cannot be composed from general search syntax but can specify either a (quoted) identifier, a (quoted) name pattern, or a tag filter.
Weak rules can be violated temporarily. If the rule is violated, the Events panel of the Cloud Console displays a warning.
Weak rules can apply to a single object, to a group of objects that have the same tag, or to an object type.
Object type rules apply to all objects of a specified type: hosts, cloud servers, or tenant databases. Object type rules can only be weak rules.
For example, the following weak object type rule specifies that every host must have at least one of the following tags: Canada, USA, or Mexico.
not (tag:Canada or tag:USA or tag:Mexico)
Object rules apply to a single object. The following object rule specifies that the tenant database must run on a host in Canada. Since rules are defined to find violators, the rule would be defined as:
Tag rules apply to all objects of a specified type that have a given tag. The following tag rule specifies that all databases with the tag Overdue must have the status stopped. Checking the rule searches for databases with the tag Overdue whose status is not stopped.
tag:Overdue and not status:stopped
The following task creates a strict rule that specifies that the database DB-z9z0 must run on the cloud server server#3.
dbcloudcmd run CreateRule is_strict=1 rule_definition="not server:server#3" target_object_type=database target_object=DB-z9z0
You can use the ExecuteTaskBatch task to call the CreateRule task. The following task creates a weak rule named CompanyARule that specifies that all databases must have the tag MyCompany:
dbcloudcmd run ExecuteTaskBatch "CALL DBCloud.CreateRule (NULL,0,'not tag:CompanyTag', 'database',NULL,NULL, 'CompanyARule')"
The following task creates a rule that specifies that the primary and mirror databases of the database Demo are not on the same cloud server:
dbcloudcmd run CreateRule is_strict=0 rule_definition="database_copy:(db_mode = 'Primary' and server:(database_copy:(db_mode = 'Mirror' and database:(name:Demo))))" target_object_type=Database target_object=DB-w3z6
The following task creates a rule that specifies that the database Test doesn't run on the same host as Demo:
dbcloudcmd run CreateRule is_strict=0 rule_definition="host:(database:Demo)" target_object_type=Database target_object=Test
The following task creates a rule that specifies that all cloud servers on Canadian hosts are running with a page size of at least 4 KB:
dbcloudcmd run CreateRule is_strict=0 rule_definition="server:(page_size lt 4096)" target_object_type=Host target_tag=Canada
The following task creates a rule that specifies that none of the running database copies of database Demo, or its backups, are located in the UK:
dbcloudcmd run CreateRule is_strict=0 rule_definition=" database_copy:(host:(tag:UK)) or backup:(host:(tag:UK))" target_object_type=Database target_object=Demo
The following task creates a rule that specifies that there are no large (>5 MB) databases on the cloud server myserver#3:
dbcloudcmd run CreateRule is_strict=0 rule_definition="database_copy:(file_size gt 5000000)" target_object_type=Server target_object=myserver#3