Google Cloud OsConfig V1 Client - Class OsConfigZonalServiceClient (1.1.1)

Reference documentation and code samples for the Google Cloud OsConfig V1 Client class OsConfigZonalServiceClient.

Service Description: Zonal OS Config API

The OS Config service is the server-side component that allows users to manage package installations and patch jobs for Compute Engine VM instances.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$osConfigZonalServiceClient = new OsConfigZonalServiceClient();
try {
    $formattedParent = $osConfigZonalServiceClient->locationName('[PROJECT]', '[LOCATION]');
    $osPolicyAssignment = new OSPolicyAssignment();
    $osPolicyAssignmentId = 'os_policy_assignment_id';
    $operationResponse = $osConfigZonalServiceClient->createOSPolicyAssignment($formattedParent, $osPolicyAssignment, $osPolicyAssignmentId);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $osConfigZonalServiceClient->createOSPolicyAssignment($formattedParent, $osPolicyAssignment, $osPolicyAssignmentId);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $osConfigZonalServiceClient->resumeOperation($operationName, 'createOSPolicyAssignment');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $osConfigZonalServiceClient->close();
}

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

This service has a new (beta) implementation. See Google\Cloud\OsConfig\V1\Client\OsConfigZonalServiceClient to use the new surface.

Namespace

Google \ Cloud \ OsConfig \ V1

Methods

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

createOSPolicyAssignment

Create an OS policy assignment.

This method also creates the first revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

Parameters
NameDescription
parent string

Required. The parent resource name in the form: projects/{project}/locations/{location}

osPolicyAssignment Google\Cloud\OsConfig\V1\OSPolicyAssignment

Required. The OS policy assignment to be created.

osPolicyAssignmentId string

Required. The logical name of the OS policy assignment in the project with the following restrictions:

  • Must contain only lowercase letters, numbers, and hyphens.
  • Must start with a letter.
  • Must be between 1-63 characters.
  • Must end with a number or a letter.
  • Must be unique within the project.
optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\OsConfig\V1\FixedOrPercent;
use Google\Cloud\OsConfig\V1\OSPolicy;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment\InstanceFilter;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment\Rollout;
use Google\Cloud\OsConfig\V1\OSPolicy\Mode;
use Google\Cloud\OsConfig\V1\OSPolicy\Resource;
use Google\Cloud\OsConfig\V1\OSPolicy\ResourceGroup;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;
use Google\Protobuf\Duration;
use Google\Rpc\Status;

/**
 * @param string $formattedParent                                       The parent resource name in the form:
 *                                                                      projects/{project}/locations/{location}
 *                                                                      Please see {@see OsConfigZonalServiceClient::locationName()} for help formatting this field.
 * @param string $osPolicyAssignmentOsPoliciesId                        The id of the OS policy with the following restrictions:
 *
 *                                                                      * Must contain only lowercase letters, numbers, and hyphens.
 *                                                                      * Must start with a letter.
 *                                                                      * Must be between 1-63 characters.
 *                                                                      * Must end with a number or a letter.
 *                                                                      * Must be unique within the assignment.
 * @param int    $osPolicyAssignmentOsPoliciesMode                      Policy mode
 * @param string $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId The id of the resource with the following restrictions:
 *
 *                                                                      * Must contain only lowercase letters, numbers, and hyphens.
 *                                                                      * Must start with a letter.
 *                                                                      * Must be between 1-63 characters.
 *                                                                      * Must end with a number or a letter.
 *                                                                      * Must be unique within the OS policy.
 * @param string $osPolicyAssignmentId                                  The logical name of the OS policy assignment in the project
 *                                                                      with the following restrictions:
 *
 *                                                                      * Must contain only lowercase letters, numbers, and hyphens.
 *                                                                      * Must start with a letter.
 *                                                                      * Must be between 1-63 characters.
 *                                                                      * Must end with a number or a letter.
 *                                                                      * Must be unique within the project.
 */
function create_os_policy_assignment_sample(
    string $formattedParent,
    string $osPolicyAssignmentOsPoliciesId,
    int $osPolicyAssignmentOsPoliciesMode,
    string $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId,
    string $osPolicyAssignmentId
): void {
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $resource = (new Resource())
        ->setId($osPolicyAssignmentOsPoliciesResourceGroupsResourcesId);
    $osPolicyAssignmentOsPoliciesResourceGroupsResources = [$resource,];
    $resourceGroup = (new ResourceGroup())
        ->setResources($osPolicyAssignmentOsPoliciesResourceGroupsResources);
    $osPolicyAssignmentOsPoliciesResourceGroups = [$resourceGroup,];
    $oSPolicy = (new OSPolicy())
        ->setId($osPolicyAssignmentOsPoliciesId)
        ->setMode($osPolicyAssignmentOsPoliciesMode)
        ->setResourceGroups($osPolicyAssignmentOsPoliciesResourceGroups);
    $osPolicyAssignmentOsPolicies = [$oSPolicy,];
    $osPolicyAssignmentInstanceFilter = new InstanceFilter();
    $osPolicyAssignmentRolloutDisruptionBudget = new FixedOrPercent();
    $osPolicyAssignmentRolloutMinWaitDuration = new Duration();
    $osPolicyAssignmentRollout = (new Rollout())
        ->setDisruptionBudget($osPolicyAssignmentRolloutDisruptionBudget)
        ->setMinWaitDuration($osPolicyAssignmentRolloutMinWaitDuration);
    $osPolicyAssignment = (new OSPolicyAssignment())
        ->setOsPolicies($osPolicyAssignmentOsPolicies)
        ->setInstanceFilter($osPolicyAssignmentInstanceFilter)
        ->setRollout($osPolicyAssignmentRollout);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $osConfigZonalServiceClient->createOSPolicyAssignment(
            $formattedParent,
            $osPolicyAssignment,
            $osPolicyAssignmentId
        );
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var OSPolicyAssignment $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = OsConfigZonalServiceClient::locationName('[PROJECT]', '[LOCATION]');
    $osPolicyAssignmentOsPoliciesId = '[ID]';
    $osPolicyAssignmentOsPoliciesMode = Mode::MODE_UNSPECIFIED;
    $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId = '[ID]';
    $osPolicyAssignmentId = '[OS_POLICY_ASSIGNMENT_ID]';

    create_os_policy_assignment_sample(
        $formattedParent,
        $osPolicyAssignmentOsPoliciesId,
        $osPolicyAssignmentOsPoliciesMode,
        $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId,
        $osPolicyAssignmentId
    );
}

deleteOSPolicyAssignment

Delete the OS policy assignment.

This method creates a new revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

If the LRO completes and is not cancelled, all revisions associated with the OS policy assignment are deleted.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

Parameters
NameDescription
name string

Required. The name of the OS policy assignment to be deleted

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the OS policy assignment to be deleted
 *                              Please see {@see OsConfigZonalServiceClient::oSPolicyAssignmentName()} for help formatting this field.
 */
function delete_os_policy_assignment_sample(string $formattedName): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $osConfigZonalServiceClient->deleteOSPolicyAssignment($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            printf('Operation completed successfully.' . PHP_EOL);
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = OsConfigZonalServiceClient::oSPolicyAssignmentName(
        '[PROJECT]',
        '[LOCATION]',
        '[OS_POLICY_ASSIGNMENT]'
    );

    delete_os_policy_assignment_sample($formattedName);
}

getInventory

Get inventory data for the specified VM instance. If the VM has no associated inventory, the message NOT_FOUND is returned.

Parameters
NameDescription
name string

Required. API resource name for inventory resource.

Format: projects/{project}/locations/{location}/instances/{instance}/inventory

For {project}, either project-number or project-id can be provided. For {instance}, either Compute Engine instance-id or instance-name can be provided.

optionalArgs array

Optional.

↳ view int

Inventory view indicating what information should be included in the inventory resource. If unspecified, the default view is BASIC. For allowed values, use constants defined on Google\Cloud\OsConfig\V1\InventoryView

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\OsConfig\V1\Inventory
Example
use Google\ApiCore\ApiException;
use Google\Cloud\OsConfig\V1\Inventory;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedName API resource name for inventory resource.
 *
 *                              Format:
 *                              `projects/{project}/locations/{location}/instances/{instance}/inventory`
 *
 *                              For `{project}`, either `project-number` or `project-id` can be provided.
 *                              For `{instance}`, either Compute Engine  `instance-id` or `instance-name`
 *                              can be provided. Please see
 *                              {@see OsConfigZonalServiceClient::inventoryName()} for help formatting this field.
 */
function get_inventory_sample(string $formattedName): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var Inventory $response */
        $response = $osConfigZonalServiceClient->getInventory($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = OsConfigZonalServiceClient::inventoryName('[PROJECT]', '[LOCATION]', '[INSTANCE]');

    get_inventory_sample($formattedName);
}

getOSPolicyAssignment

Retrieve an existing OS policy assignment.

This method always returns the latest revision. In order to retrieve a previous revision of the assignment, also provide the revision ID in the name parameter.

Parameters
NameDescription
name string

Required. The resource name of OS policy assignment.

Format: projects/{project}/locations/{location}/osPolicyAssignments/{os_policy_assignment}@{revisionId}

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\OsConfig\V1\OSPolicyAssignment
Example
use Google\ApiCore\ApiException;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedName The resource name of OS policy assignment.
 *
 *                              Format:
 *                              `projects/{project}/locations/{location}/osPolicyAssignments/{os_policy_assignment}@{revisionId}`
 *                              Please see {@see OsConfigZonalServiceClient::oSPolicyAssignmentName()} for help formatting this field.
 */
function get_os_policy_assignment_sample(string $formattedName): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var OSPolicyAssignment $response */
        $response = $osConfigZonalServiceClient->getOSPolicyAssignment($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = OsConfigZonalServiceClient::oSPolicyAssignmentName(
        '[PROJECT]',
        '[LOCATION]',
        '[OS_POLICY_ASSIGNMENT]'
    );

    get_os_policy_assignment_sample($formattedName);
}

getOSPolicyAssignmentReport

Get the OS policy asssignment report for the specified Compute Engine VM instance.

Parameters
NameDescription
name string

Required. API resource name for OS policy assignment report.

Format: /projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/{assignment}/report

For {project}, either project-number or project-id can be provided. For {instance_id}, either Compute Engine instance-id or instance-name can be provided. For {assignment_id}, the OSPolicyAssignment id must be provided.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\OsConfig\V1\OSPolicyAssignmentReport
Example
use Google\ApiCore\ApiException;
use Google\Cloud\OsConfig\V1\OSPolicyAssignmentReport;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedName API resource name for OS policy assignment report.
 *
 *                              Format:
 *                              `/projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/{assignment}/report`
 *
 *                              For `{project}`, either `project-number` or `project-id` can be provided.
 *                              For `{instance_id}`, either Compute Engine `instance-id` or `instance-name`
 *                              can be provided.
 *                              For `{assignment_id}`, the OSPolicyAssignment id must be provided. Please see
 *                              {@see OsConfigZonalServiceClient::oSPolicyAssignmentReportName()} for help formatting this field.
 */
function get_os_policy_assignment_report_sample(string $formattedName): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var OSPolicyAssignmentReport $response */
        $response = $osConfigZonalServiceClient->getOSPolicyAssignmentReport($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = OsConfigZonalServiceClient::oSPolicyAssignmentReportName(
        '[PROJECT]',
        '[LOCATION]',
        '[INSTANCE]',
        '[ASSIGNMENT]'
    );

    get_os_policy_assignment_report_sample($formattedName);
}

getVulnerabilityReport

Gets the vulnerability report for the specified VM instance. Only VMs with inventory data have vulnerability reports associated with them.

Parameters
NameDescription
name string

Required. API resource name for vulnerability resource.

Format: projects/{project}/locations/{location}/instances/{instance}/vulnerabilityReport

For {project}, either project-number or project-id can be provided. For {instance}, either Compute Engine instance-id or instance-name can be provided.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\OsConfig\V1\VulnerabilityReport
Example
use Google\ApiCore\ApiException;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;
use Google\Cloud\OsConfig\V1\VulnerabilityReport;

/**
 * @param string $formattedName API resource name for vulnerability resource.
 *
 *                              Format:
 *                              `projects/{project}/locations/{location}/instances/{instance}/vulnerabilityReport`
 *
 *                              For `{project}`, either `project-number` or `project-id` can be provided.
 *                              For `{instance}`, either Compute Engine `instance-id` or `instance-name`
 *                              can be provided. Please see
 *                              {@see OsConfigZonalServiceClient::vulnerabilityReportName()} for help formatting this field.
 */
function get_vulnerability_report_sample(string $formattedName): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var VulnerabilityReport $response */
        $response = $osConfigZonalServiceClient->getVulnerabilityReport($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = OsConfigZonalServiceClient::vulnerabilityReportName(
        '[PROJECT]',
        '[LOCATION]',
        '[INSTANCE]'
    );

    get_vulnerability_report_sample($formattedName);
}

listInventories

List inventory data for all VM instances in the specified zone.

Parameters
NameDescription
parent string

Required. The parent resource name.

Format: projects/{project}/locations/{location}/instances/-

For {project}, either project-number or project-id can be provided.

optionalArgs array

Optional.

↳ view int

Inventory view indicating what information should be included in the inventory resource. If unspecified, the default view is BASIC. For allowed values, use constants defined on Google\Cloud\OsConfig\V1\InventoryView

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

If provided, this field specifies the criteria that must be met by a Inventory API resource to be included in the response.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\OsConfig\V1\Inventory;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedParent The parent resource name.
 *
 *                                Format: `projects/{project}/locations/{location}/instances/-`
 *
 *                                For `{project}`, either `project-number` or `project-id` can be provided. Please see
 *                                {@see OsConfigZonalServiceClient::instanceName()} for help formatting this field.
 */
function list_inventories_sample(string $formattedParent): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $osConfigZonalServiceClient->listInventories($formattedParent);

        /** @var Inventory $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = OsConfigZonalServiceClient::instanceName('[PROJECT]', '[ZONE]', '[INSTANCE]');

    list_inventories_sample($formattedParent);
}

listOSPolicyAssignmentReports

List OS policy asssignment reports for all Compute Engine VM instances in the specified zone.

Parameters
NameDescription
parent string

Required. The parent resource name.

Format: projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/{assignment}/reports

For {project}, either project-number or project-id can be provided. For {instance}, either instance-name, instance-id, or - can be provided. If '-' is provided, the response will include OSPolicyAssignmentReports for all instances in the project/location. For {assignment}, either assignment-id or - can be provided. If '-' is provided, the response will include OSPolicyAssignmentReports for all OSPolicyAssignments in the project/location. Either {instance} or {assignment} must be -.

For example: projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/-/reports returns all reports for the instance projects/{project}/locations/{location}/instances/-/osPolicyAssignments/{assignment-id}/reports returns all the reports for the given assignment across all instances. projects/{project}/locations/{location}/instances/-/osPolicyAssignments/-/reports returns all the reports for all assignments across all instances.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ filter string

If provided, this field specifies the criteria that must be met by the OSPolicyAssignmentReport API resource that is included in the response.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\OsConfig\V1\OSPolicyAssignmentReport;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedParent The parent resource name.
 *
 *                                Format:
 *                                `projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/{assignment}/reports`
 *
 *                                For `{project}`, either `project-number` or `project-id` can be provided.
 *                                For `{instance}`, either `instance-name`, `instance-id`, or `-` can be
 *                                provided. If '-' is provided, the response will include
 *                                OSPolicyAssignmentReports for all instances in the project/location.
 *                                For `{assignment}`, either `assignment-id` or `-` can be provided. If '-'
 *                                is provided, the response will include OSPolicyAssignmentReports for all
 *                                OSPolicyAssignments in the project/location.
 *                                Either {instance} or {assignment} must be `-`.
 *
 *                                For example:
 *                                `projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/-/reports`
 *                                returns all reports for the instance
 *                                `projects/{project}/locations/{location}/instances/-/osPolicyAssignments/{assignment-id}/reports`
 *                                returns all the reports for the given assignment across all instances.
 *                                `projects/{project}/locations/{location}/instances/-/osPolicyAssignments/-/reports`
 *                                returns all the reports for all assignments across all instances. Please see
 *                                {@see OsConfigZonalServiceClient::instanceOSPolicyAssignmentName()} for help formatting this field.
 */
function list_os_policy_assignment_reports_sample(string $formattedParent): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $osConfigZonalServiceClient->listOSPolicyAssignmentReports($formattedParent);

        /** @var OSPolicyAssignmentReport $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = OsConfigZonalServiceClient::instanceOSPolicyAssignmentName(
        '[PROJECT]',
        '[LOCATION]',
        '[INSTANCE]',
        '[ASSIGNMENT]'
    );

    list_os_policy_assignment_reports_sample($formattedParent);
}

listOSPolicyAssignmentRevisions

List the OS policy assignment revisions for a given OS policy assignment.

Parameters
NameDescription
name string

Required. The name of the OS policy assignment to list revisions for.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedName The name of the OS policy assignment to list revisions for. Please see
 *                              {@see OsConfigZonalServiceClient::oSPolicyAssignmentName()} for help formatting this field.
 */
function list_os_policy_assignment_revisions_sample(string $formattedName): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $osConfigZonalServiceClient->listOSPolicyAssignmentRevisions($formattedName);

        /** @var OSPolicyAssignment $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = OsConfigZonalServiceClient::oSPolicyAssignmentName(
        '[PROJECT]',
        '[LOCATION]',
        '[OS_POLICY_ASSIGNMENT]'
    );

    list_os_policy_assignment_revisions_sample($formattedName);
}

listOSPolicyAssignments

List the OS policy assignments under the parent resource.

For each OS policy assignment, the latest revision is returned.

Parameters
NameDescription
parent string

Required. The parent resource name.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;

/**
 * @param string $formattedParent The parent resource name. Please see
 *                                {@see OsConfigZonalServiceClient::locationName()} for help formatting this field.
 */
function list_os_policy_assignments_sample(string $formattedParent): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $osConfigZonalServiceClient->listOSPolicyAssignments($formattedParent);

        /** @var OSPolicyAssignment $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = OsConfigZonalServiceClient::locationName('[PROJECT]', '[LOCATION]');

    list_os_policy_assignments_sample($formattedParent);
}

listVulnerabilityReports

List vulnerability reports for all VM instances in the specified zone.

Parameters
NameDescription
parent string

Required. The parent resource name.

Format: projects/{project}/locations/{location}/instances/-

For {project}, either project-number or project-id can be provided.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

If provided, this field specifies the criteria that must be met by a vulnerabilityReport API resource to be included in the response.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;
use Google\Cloud\OsConfig\V1\VulnerabilityReport;

/**
 * @param string $formattedParent The parent resource name.
 *
 *                                Format: `projects/{project}/locations/{location}/instances/-`
 *
 *                                For `{project}`, either `project-number` or `project-id` can be provided. Please see
 *                                {@see OsConfigZonalServiceClient::instanceName()} for help formatting this field.
 */
function list_vulnerability_reports_sample(string $formattedParent): void
{
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $osConfigZonalServiceClient->listVulnerabilityReports($formattedParent);

        /** @var VulnerabilityReport $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = OsConfigZonalServiceClient::instanceName('[PROJECT]', '[ZONE]', '[INSTANCE]');

    list_vulnerability_reports_sample($formattedParent);
}

updateOSPolicyAssignment

Update an existing OS policy assignment.

This method creates a new revision of the OS policy assignment.

This method returns a long running operation (LRO) that contains the rollout details. The rollout can be cancelled by cancelling the LRO.

For more information, see Method: projects.locations.osPolicyAssignments.operations.cancel.

Parameters
NameDescription
osPolicyAssignment Google\Cloud\OsConfig\V1\OSPolicyAssignment

Required. The updated OS policy assignment.

optionalArgs array

Optional.

↳ updateMask FieldMask

Optional. Field mask that controls which fields of the assignment should be updated.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\OsConfig\V1\FixedOrPercent;
use Google\Cloud\OsConfig\V1\OSPolicy;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment\InstanceFilter;
use Google\Cloud\OsConfig\V1\OSPolicyAssignment\Rollout;
use Google\Cloud\OsConfig\V1\OSPolicy\Mode;
use Google\Cloud\OsConfig\V1\OSPolicy\Resource;
use Google\Cloud\OsConfig\V1\OSPolicy\ResourceGroup;
use Google\Cloud\OsConfig\V1\OsConfigZonalServiceClient;
use Google\Protobuf\Duration;
use Google\Rpc\Status;

/**
 * @param string $osPolicyAssignmentOsPoliciesId                        The id of the OS policy with the following restrictions:
 *
 *                                                                      * Must contain only lowercase letters, numbers, and hyphens.
 *                                                                      * Must start with a letter.
 *                                                                      * Must be between 1-63 characters.
 *                                                                      * Must end with a number or a letter.
 *                                                                      * Must be unique within the assignment.
 * @param int    $osPolicyAssignmentOsPoliciesMode                      Policy mode
 * @param string $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId The id of the resource with the following restrictions:
 *
 *                                                                      * Must contain only lowercase letters, numbers, and hyphens.
 *                                                                      * Must start with a letter.
 *                                                                      * Must be between 1-63 characters.
 *                                                                      * Must end with a number or a letter.
 *                                                                      * Must be unique within the OS policy.
 */
function update_os_policy_assignment_sample(
    string $osPolicyAssignmentOsPoliciesId,
    int $osPolicyAssignmentOsPoliciesMode,
    string $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId
): void {
    // Create a client.
    $osConfigZonalServiceClient = new OsConfigZonalServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $resource = (new Resource())
        ->setId($osPolicyAssignmentOsPoliciesResourceGroupsResourcesId);
    $osPolicyAssignmentOsPoliciesResourceGroupsResources = [$resource,];
    $resourceGroup = (new ResourceGroup())
        ->setResources($osPolicyAssignmentOsPoliciesResourceGroupsResources);
    $osPolicyAssignmentOsPoliciesResourceGroups = [$resourceGroup,];
    $oSPolicy = (new OSPolicy())
        ->setId($osPolicyAssignmentOsPoliciesId)
        ->setMode($osPolicyAssignmentOsPoliciesMode)
        ->setResourceGroups($osPolicyAssignmentOsPoliciesResourceGroups);
    $osPolicyAssignmentOsPolicies = [$oSPolicy,];
    $osPolicyAssignmentInstanceFilter = new InstanceFilter();
    $osPolicyAssignmentRolloutDisruptionBudget = new FixedOrPercent();
    $osPolicyAssignmentRolloutMinWaitDuration = new Duration();
    $osPolicyAssignmentRollout = (new Rollout())
        ->setDisruptionBudget($osPolicyAssignmentRolloutDisruptionBudget)
        ->setMinWaitDuration($osPolicyAssignmentRolloutMinWaitDuration);
    $osPolicyAssignment = (new OSPolicyAssignment())
        ->setOsPolicies($osPolicyAssignmentOsPolicies)
        ->setInstanceFilter($osPolicyAssignmentInstanceFilter)
        ->setRollout($osPolicyAssignmentRollout);

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $osConfigZonalServiceClient->updateOSPolicyAssignment($osPolicyAssignment);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var OSPolicyAssignment $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $osPolicyAssignmentOsPoliciesId = '[ID]';
    $osPolicyAssignmentOsPoliciesMode = Mode::MODE_UNSPECIFIED;
    $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId = '[ID]';

    update_os_policy_assignment_sample(
        $osPolicyAssignmentOsPoliciesId,
        $osPolicyAssignmentOsPoliciesMode,
        $osPolicyAssignmentOsPoliciesResourceGroupsResourcesId
    );
}

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

Returns
TypeDescription
Google\ApiCore\LongRunning\OperationsClient

resumeOperation

Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.

Parameters
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

static::instanceName

Formats a string containing the fully-qualified path to represent a instance resource.

Parameters
NameDescription
project string
zone string
instance string
Returns
TypeDescription
stringThe formatted instance resource.

static::instanceOSPolicyAssignmentName

Formats a string containing the fully-qualified path to represent a instance_os_policy_assignment resource.

Parameters
NameDescription
project string
location string
instance string
assignment string
Returns
TypeDescription
stringThe formatted instance_os_policy_assignment resource.

static::inventoryName

Formats a string containing the fully-qualified path to represent a inventory resource.

Parameters
NameDescription
project string
location string
instance string
Returns
TypeDescription
stringThe formatted inventory resource.

static::locationName

Formats a string containing the fully-qualified path to represent a location resource.

Parameters
NameDescription
project string
location string
Returns
TypeDescription
stringThe formatted location resource.

static::oSPolicyAssignmentName

Formats a string containing the fully-qualified path to represent a os_policy_assignment resource.

Parameters
NameDescription
project string
location string
osPolicyAssignment string
Returns
TypeDescription
stringThe formatted os_policy_assignment resource.

static::oSPolicyAssignmentReportName

Formats a string containing the fully-qualified path to represent a os_policy_assignment_report resource.

Parameters
NameDescription
project string
location string
instance string
assignment string
Returns
TypeDescription
stringThe formatted os_policy_assignment_report resource.

static::projectLocationInstanceName

Formats a string containing the fully-qualified path to represent a project_location_instance resource.

Parameters
NameDescription
project string
location string
instance string
Returns
TypeDescription
stringThe formatted project_location_instance resource.

static::projectZoneInstanceName

Formats a string containing the fully-qualified path to represent a project_zone_instance resource.

Parameters
NameDescription
project string
zone string
instance string
Returns
TypeDescription
stringThe formatted project_zone_instance resource.

static::vulnerabilityReportName

Formats a string containing the fully-qualified path to represent a vulnerability_report resource.

Parameters
NameDescription
project string
location string
instance string
Returns
TypeDescription
stringThe formatted vulnerability_report resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • instance: projects/{project}/zones/{zone}/instances/{instance}
  • instanceOSPolicyAssignment: projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/{assignment}
  • inventory: projects/{project}/locations/{location}/instances/{instance}/inventory
  • location: projects/{project}/locations/{location}
  • oSPolicyAssignment: projects/{project}/locations/{location}/osPolicyAssignments/{os_policy_assignment}
  • oSPolicyAssignmentReport: projects/{project}/locations/{location}/instances/{instance}/osPolicyAssignments/{assignment}/report
  • projectLocationInstance: projects/{project}/locations/{location}/instances/{instance}
  • projectZoneInstance: projects/{project}/zones/{zone}/instances/{instance}
  • vulnerabilityReport: projects/{project}/locations/{location}/instances/{instance}/vulnerabilityReport

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

Constants

SERVICE_NAME

Value: 'google.cloud.osconfig.v1.OsConfigZonalService'

The name of the service.

SERVICE_ADDRESS

Value: 'osconfig.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.