Example #1
0
    def AcquireWritePermissionsLinux(cls, vm):
        """Prepare boto file on a remote Linux instance.

    If the boto file specifies a service key file, copy that service key file to
    the VM and modify the .boto file on the VM to point to the copied file.

    Args:
      vm: gce virtual machine object.
    """
        vm_pwd, _ = vm.RemoteCommand('pwd')
        home_dir = vm_pwd.strip()
        boto_src = object_storage_service.FindBotoFile()
        boto_des = posixpath.join(home_dir, posixpath.basename(boto_src))
        if vm.TryRemoteCommand(f'test -f {boto_des}'):
            return
        with open(boto_src) as f:
            boto_contents = f.read()
        match = re.search(r'gs_service_key_file\s*=\s*(.*)', boto_contents)
        if match:
            service_key_src = match.group(1)
            service_key_des = posixpath.join(
                home_dir, posixpath.basename(service_key_src))
            boto_src = cls._PrepareGcsServiceKey(vm, boto_src, service_key_src,
                                                 service_key_des)
        vm.PushFile(boto_src, boto_des)
Example #2
0
    def AcquireWritePermissionsWindows(self, vm):
        """Prepare boto file on a remote Windows instance.

    If the boto file specifies a service key file, copy that service key file to
    the VM and modify the .boto file on the VM to point to the copied file.

    Args:
      vm: gce virtual machine object.
    """
        boto_src = object_storage_service.FindBotoFile()
        boto_des = ntpath.join(vm.home_dir, posixpath.basename(boto_src))
        stdout, _ = vm.RemoteCommand(f'Test-Path {boto_des}')
        if 'True' in stdout:
            return
        with open(boto_src) as f:
            boto_contents = f.read()
        match = re.search(r'gs_service_key_file\s*=\s*(.*)', boto_contents)
        if match:
            service_key_src = match.group(1)
            service_key_des = ntpath.join(vm.home_dir,
                                          posixpath.basename(service_key_src))
            boto_src = self._PrepareGcsServiceKey(vm, boto_src,
                                                  service_key_src,
                                                  service_key_des)
        vm.PushFile(boto_src, boto_des)
Example #3
0
    def PrepareVM(self, vm):
        vm.Install('wget')
        # Unfortunately there isn't one URL scheme that works for both
        # versioned archives and "always get the latest version".
        if FLAGS.google_cloud_sdk_version is not None:
            sdk_file = ('google-cloud-sdk-%s-linux-x86_64.tar.gz' %
                        FLAGS.google_cloud_sdk_version)
            sdk_url = 'https://storage.googleapis.com/cloud-sdk-release/' + sdk_file
        else:
            sdk_file = 'google-cloud-sdk.tar.gz'
            sdk_url = 'https://dl.google.com/dl/cloudsdk/release/' + sdk_file
        vm.RemoteCommand('wget ' + sdk_url)
        vm.RemoteCommand('tar xvf ' + sdk_file)
        # Versioned and unversioned archives both unzip to a folder called
        # 'google-cloud-sdk'.
        vm.RemoteCommand('bash ./google-cloud-sdk/install.sh '
                         '--disable-installation-options '
                         '--usage-report=false '
                         '--rc-path=.bash_profile '
                         '--path-update=true '
                         '--bash-completion=true')

        vm.RemoteCommand('mkdir -p .config')
        vm.PushFile(
            object_storage_service.FindCredentialFile('~/' +
                                                      GCS_CREDENTIAL_LOCATION),
            GCLOUD_CONFIG_PATH)
        vm.PushFile(object_storage_service.FindBotoFile(),
                    object_storage_service.DEFAULT_BOTO_LOCATION)

        vm.gsutil_path, _ = vm.RemoteCommand('which gsutil', login_shell=True)
        vm.gsutil_path = vm.gsutil_path.split()[0]

        # Detect if we need to install crcmod for gcp.
        # See "gsutil help crc" for details.
        raw_result, _ = vm.RemoteCommand('%s version -l' % vm.gsutil_path)
        logging.info('gsutil version -l raw result is %s', raw_result)
        search_string = 'compiled crcmod: True'
        result_string = re.findall(search_string, raw_result)
        if len(result_string) == 0:
            logging.info('compiled crcmod is not available, installing now...')
            try:
                # Try uninstall first just in case there is a pure python version of
                # crcmod on the system already, this is required by gsutil doc:
                # https://cloud.google.com/storage/docs/
                # gsutil/addlhelp/CRC32CandInstallingcrcmod
                vm.Uninstall('crcmod')
            except errors.VirtualMachine.RemoteCommandError:
                logging.info(
                    'pip uninstall crcmod failed, could be normal if crcmod '
                    'is not available at all.')
                pass
            vm.Install('crcmod')
            vm.installed_crcmod = True
        else:
            logging.info('compiled crcmod is available, not installing again.')
            vm.installed_crcmod = False

        vm.Install('gcs_boto_plugin')
Example #4
0
    def PrepareVM(self, vm):
        vm.Install('awscli')
        vm.Install('boto')

        vm.PushFile(
            object_storage_service.FindCredentialFile('~/' +
                                                      AWS_CREDENTIAL_LOCATION),
            AWS_CREDENTIAL_LOCATION)
        vm.PushFile(object_storage_service.FindBotoFile(),
                    object_storage_service.DEFAULT_BOTO_LOCATION)
Example #5
0
  def PrepareVM(self, vm):
    vm.Install('wget')
    # Unfortunately there isn't one URL scheme that works for both
    # versioned archives and "always get the latest version".
    if FLAGS.google_cloud_sdk_version is not None:
      sdk_file = ('google-cloud-sdk-%s-linux-x86_64.tar.gz' %
                  FLAGS.google_cloud_sdk_version)
      sdk_url = 'https://storage.googleapis.com/cloud-sdk-release/' + sdk_file
    else:
      sdk_file = 'google-cloud-sdk.tar.gz'
      sdk_url = 'https://dl.google.com/dl/cloudsdk/release/' + sdk_file
    vm.RemoteCommand('wget ' + sdk_url)
    vm.RemoteCommand('tar xvf ' + sdk_file)
    # Versioned and unversioned archives both unzip to a folder called
    # 'google-cloud-sdk'.
    vm.RemoteCommand('bash ./google-cloud-sdk/install.sh '
                     '--disable-installation-options '
                     '--usage-report=false '
                     '--rc-path=.bash_profile '
                     '--path-update=true '
                     '--bash-completion=true')
    vm.Install('google_cloud_storage')

    vm.RemoteCommand('mkdir -p .config')

    if FLAGS.gcs_client == GCS_CLIENT_BOTO:
      boto_file = object_storage_service.FindBotoFile()
      vm.PushFile(boto_file, object_storage_service.DEFAULT_BOTO_LOCATION)

      # If the boto file specifies a service key file, copy that service key
      # file to the VM and modify the .boto file on the VM to point to the
      # copied file.
      with open(boto_file) as f:
        boto_contents = f.read()
      match = re.search(r'gs_service_key_file\s*=\s*(.*)', boto_contents)
      if match:
        service_key_file = match.group(1)
        vm.PushFile(service_key_file, _DEFAULT_GCP_SERVICE_KEY_FILE)
        vm_pwd, _ = vm.RemoteCommand('pwd')
        vm.RemoteCommand(
            'sed -i '
            '-e "s|^gs_service_key_file.*|gs_service_key_file = %s|" %s' %
            (re.escape(
                posixpath.join(vm_pwd.strip(), _DEFAULT_GCP_SERVICE_KEY_FILE)),
             object_storage_service.DEFAULT_BOTO_LOCATION))
      vm.Install('gcs_boto_plugin')

    vm.gsutil_path, _ = vm.RemoteCommand('which gsutil', login_shell=True)
    vm.gsutil_path = vm.gsutil_path.split()[0]

    # Detect if we need to install crcmod for gcp.
    # See "gsutil help crc" for details.
    raw_result, _ = vm.RemoteCommand('%s version -l' % vm.gsutil_path)
    logging.info('gsutil version -l raw result is %s', raw_result)
    search_string = 'compiled crcmod: True'
    result_string = re.findall(search_string, raw_result)
    if not result_string:
      logging.info('compiled crcmod is not available, installing now...')
      try:
        # Try uninstall first just in case there is a pure python version of
        # crcmod on the system already, this is required by gsutil doc:
        # https://cloud.google.com/storage/docs/
        # gsutil/addlhelp/CRC32CandInstallingcrcmod
        vm.Uninstall('crcmod')
      except errors.VirtualMachine.RemoteCommandError:
        logging.info('pip uninstall crcmod failed, could be normal if crcmod '
                     'is not available at all.')
      vm.Install('crcmod')
      vm.installed_crcmod = True
    else:
      logging.info('compiled crcmod is available, not installing again.')
      vm.installed_crcmod = False