I'm deleting disks in GKE cluster.I'm using my JSON-key credentials to delete the disk associated with a specific cluster.
Python
from google.cloud import storage
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = storage.Client.from_service_account_json("json_key")
service = discovery.build('compute','v1',credentials=credentials)
project = #PROJECT-NAME#
zone = #ZONE-NAME#
disk = [#list of disks]
for i in disk:
request = service.disks().delete(project=project, zone=zone, disk=disk)
response = request.execute()
print(response)
While executing I'm facing an error 'Client' object has no attribute 'authorize'.Where I'm going wrong here?
How to delete the disks for a specific cluster.Is ther any other way to do this.
Thanks.
Instead of storage you can try with ServiceAccountCredentials
by following the link and try below sample:
from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
from oauth2client.service_account import ServiceAccountCredentials
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'key.json',
scopes='https://www.googleapis.com/auth/cloud-platform')
service = discovery.build('compute', 'v1', credentials=credentials)