Assign a policy to a computer

Assign a policy to a computer to protect the computer according to the policy settings and the configuration of the security modules:

  1. Create a Computer object.
  2. Set the policy ID to use on the object.
  3. Use a ComputersApi object to update the computer on Deep Security Manager.

The following example assigns a policy to a computer. A search obtains the policy to obtain its ID, which is assigned to a computer. (The creation of the search criteria and search filter is not shown.)

Language

Code

Python

View source

# Perform the search
policy_search_results = policies_api.search_policies(api_version, search_filter=search_filter)

# Assign the policy to the computer
computer.policy_id = policy_search_results.policies[0].id

JavaScript

View source

const policiesApi = new api.PoliciesApi();

// Searches for the policy
const searchPolicy = () => policiesApi.searchPolicies(apiVersion, searchFilter);

// Assigns the found policy to the computer
const assignPolicy = searchResults => {
  const computer = new api.Computer();
  computer.policyID = searchResults.policies[0].ID;

  const computersApi = new api.ComputersApi();
  return computersApi.modifyComputer(computerID, computer, apiVersion, { overrides: false });
};

searchPolicy()
  .then(assignPolicy)
  .then(data => {
    resolve(data);
  })
  .catch(error => {
    reject(error);
  });

Java

View source

// Search for the policy
PoliciesApi policiesApi = new PoliciesApi();
Policies policies = policiesApi.searchPolicies(sf, Boolean.FALSE, apiVersion);

if (policies.getPolicies().isEmpty())
    return null;

// Set the policy for the computer
Computer computer = new Computer();
computer.setPolicyID(policies.getPolicies().get(0).getID());

// Update on Deep Security Manager
ComputersApi computersApi = new ComputersApi();
Expand expand = new Expand();
return computersApi.modifyComputer(computerID, computer, expand.list(), Boolean.FALSE, apiVersion);
Tip:

Also see the Modify a Policy operation in the API Reference.

You can override a policy at the computer level. See Configure Computers to Override Policies.