in troubleshooting/create_snapshot.py [0:0]
def upload_preflight(sa_keyfile: str, bucket: str): # noqa: E999
auth_cmd = ('gcloud auth activate-service-account'
'--key-file {}'.format(sa_keyfile))
create_cmd = 'gsutil mb -c standard --retention 30d gs://{}'.format(bucket)
list_bucket_cmd = 'gsutil ls -b gs://{}'.format(bucket)
print('Authenticating as service account from key file... ', end='')
auth_return_code, auth_output = run_gsutil_cmd(auth_cmd)
if not auth_return_code:
print('[ SUCCESS ]')
print('Checking if Cloud Storage Bucket exsists... ', end='')
list_bucket_return_code, _ = run_gsutil_cmd(list_bucket_cmd)
if not list_bucket_return_code:
print('[ SUCCESS ]')
# listing the bucket was sucessful
return list_bucket_return_code
else:
print('[ FAIL ]')
print(('Creating {}... '.format(bucket)), end='')
create_return_code, create_output = run_gsutil_cmd(create_cmd)
if not create_return_code:
print('[ SUCCESS ]')
# creating the bucket was successful
return create_return_code
else:
print('[ FAIL ]')
print(create_output)
return create_return_code
else:
print('[ FAIL ]')
print(auth_output)
return auth_return_code