-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into alarconesparza-chore-update-practices-345846215
- Loading branch information
Showing
112 changed files
with
2,966 additions
and
4,729 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package snippets | ||
|
||
// [START compute_consistency_group_add_disk] | ||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
compute "cloud.google.com/go/compute/apiv1" | ||
computepb "cloud.google.com/go/compute/apiv1/computepb" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
// cloneConsistencyGroup clones all disks in consistency group for a project in a given region. | ||
func cloneConsistencyGroup(w io.Writer, projectID, region, groupName string) error { | ||
// projectID := "your_project_id" | ||
// region := "europe-west4" | ||
// groupName := "your_group_name" | ||
|
||
ctx := context.Background() | ||
disksClient, err := compute.NewRegionDisksRESTClient(ctx) | ||
if err != nil { | ||
return fmt.Errorf("NewResourcePoliciesRESTClient: %w", err) | ||
} | ||
defer disksClient.Close() | ||
|
||
consistencyGroupUrl := fmt.Sprintf("projects/%s/regions/%s/resourcePolicies/%s", projectID, region, groupName) | ||
|
||
req := &computepb.BulkInsertRegionDiskRequest{ | ||
Project: projectID, | ||
BulkInsertDiskResourceResource: &computepb.BulkInsertDiskResource{ | ||
SourceConsistencyGroupPolicy: proto.String(consistencyGroupUrl), | ||
}, | ||
Region: region, | ||
} | ||
|
||
op, err := disksClient.BulkInsert(ctx, req) | ||
if err != nil { | ||
return fmt.Errorf("unable to add disk: %w", err) | ||
} | ||
|
||
if err = op.Wait(ctx); err != nil { | ||
return fmt.Errorf("unable to wait for the operation: %w", err) | ||
} | ||
|
||
fmt.Fprintf(w, "Group cloned\n") | ||
|
||
return nil | ||
} | ||
|
||
// [END compute_consistency_group_add_disk] |
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,67 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package snippets | ||
|
||
// [START compute_consistency_group_list] | ||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
compute "cloud.google.com/go/compute/apiv1" | ||
computepb "cloud.google.com/go/compute/apiv1/computepb" | ||
"google.golang.org/api/iterator" | ||
) | ||
|
||
// listConsistencyGroup get list of disks in consistency group for a project in a given region. | ||
func listConsistencyGroup(w io.Writer, projectID, region, groupName string) error { | ||
// projectID := "your_project_id" | ||
// region := "europe-west4" | ||
// groupName := "your_group_name" | ||
|
||
ctx := context.Background() | ||
disksClient, err := compute.NewRegionDisksRESTClient(ctx) | ||
if err != nil { | ||
return fmt.Errorf("NewResourcePoliciesRESTClient: %w", err) | ||
} | ||
defer disksClient.Close() | ||
|
||
req := &computepb.ListRegionDisksRequest{ | ||
Project: projectID, | ||
Region: region, | ||
} | ||
|
||
it := disksClient.List(ctx, req) | ||
for { | ||
disk, err := it.Next() | ||
if err == iterator.Done { | ||
break | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, diskPolicy := range disk.GetResourcePolicies() { | ||
if strings.Contains(diskPolicy, groupName) { | ||
fmt.Fprintf(w, "- %s\n", disk.GetName()) | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// [END compute_consistency_group_list] |
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 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package snippets | ||
|
||
// [START compute_consistency_group_stop_replication] | ||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
compute "cloud.google.com/go/compute/apiv1" | ||
computepb "cloud.google.com/go/compute/apiv1/computepb" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
// stopReplicationConsistencyGroup stop replication for a consistency group for a project in a given region. | ||
func stopReplicationConsistencyGroup(w io.Writer, projectID, region, groupName string) error { | ||
// projectID := "your_project_id" | ||
// region := "europe-west4" | ||
// groupName := "your_group_name" | ||
|
||
ctx := context.Background() | ||
disksClient, err := compute.NewRegionDisksRESTClient(ctx) | ||
if err != nil { | ||
return fmt.Errorf("NewResourcePoliciesRESTClient: %w", err) | ||
} | ||
defer disksClient.Close() | ||
|
||
consistencyGroupUrl := fmt.Sprintf("projects/%s/regions/%s/resourcePolicies/%s", projectID, region, groupName) | ||
|
||
req := &computepb.StopGroupAsyncReplicationRegionDiskRequest{ | ||
Project: projectID, | ||
DisksStopGroupAsyncReplicationResourceResource: &computepb.DisksStopGroupAsyncReplicationResource{ | ||
ResourcePolicy: proto.String(consistencyGroupUrl), | ||
}, | ||
Region: region, | ||
} | ||
|
||
op, err := disksClient.StopGroupAsyncReplication(ctx, req) | ||
if err != nil { | ||
return fmt.Errorf("unable to stop replication: %w", err) | ||
} | ||
|
||
if err = op.Wait(ctx); err != nil { | ||
return fmt.Errorf("unable to wait for the operation: %w", err) | ||
} | ||
|
||
fmt.Fprintf(w, "Group stopped replicating\n") | ||
|
||
return nil | ||
} | ||
|
||
// [END compute_consistency_group_stop_replication] |
Oops, something went wrong.