def file_exists_on_remote(remote_file_location): file_copied = GCloud.copy_file_from_remote(remote_file_location, './temp.txt') if file_copied: System.run_command('rm ./temp.txt') return True return False
def copy_file_from_remote(remote_file_location, local_target): try: System.run_command('gcloud compute scp {}:~/{} {}'.format( INSTANCE_NAME, remote_file_location, local_target)) return True except: return False
def prompt_for_billing_id(project_id): os.system('gcloud alpha billing accounts list') billing_account_id = input( "Enter billing Account ID from above (if none exist create one here https://cloud.google.com/billing/docs/how-to/manage-billing-account): " ) System.run_command( 'gcloud beta billing projects link {} --billing-account={}'.format( project_id, billing_account_id))
def is_authenticated(): account = System.run_command( 'gcloud config list account --format value(core.account)') if len(account): return True else: return False
def upload_directory_to_bucket(directory, bucket_name): buckets_list = System.run_command('gsutil ls') if bucket_name not in buckets_list: System.run_command('gsutil mb gs://{}/'.format(bucket_name)) System.run_command('gsutil cp -r {} gs://{}/'.format( directory, bucket_name))
def upload_file_to_bucket(file_location, bucket_name): buckets_list = System.run_command('gsutil ls') if bucket_name not in buckets_list: System.run_command('gsutil mb gs://{}/'.format(bucket_name)) System.run_command('gsutil cp {} gs://{}/'.format( file_location, bucket_name))
def create_project(project_id, project_name): System.run_command( 'gcloud projects create {} --name="{}" --set-as-default'.format( project_id, project_name)) System.run_command('gcloud config set project {}'.format(project_id))
def login(): System.run_command('gcloud auth login')
def update_sdk(): System.run_command('gcloud components update')