Exemplo n.º 1
0
 def LoadFromFile(cls):
   """Loads a service principal from a file."""
   with open(object_storage_service.FindCredentialFile(azure_credentials.AZURE_CREDENTIAL_PROFILE_FILE), encoding='utf-8-sig') as profile_fp, \
       open(object_storage_service.FindCredentialFile(azure_credentials.AZURE_CREDENTIAL_TOKENS_FILE)) as tokens_fp:
     subscriptions = json.load(profile_fp)['subscriptions']
     subscription = [sub for sub in subscriptions if sub['isDefault']][0]
     subscription_type = subscription['user']['type']
     if subscription_type != 'servicePrincipal':
       # We are using user auth, and will probably have permission to create a
       # service principal.
       logging.info("Azure credentials are of type '%s'. "
                    'Will try to create a new service principal.',
                    subscription_type)
       return cls()
     # name and id are backwards
     name = subscription['id']
     app_id = subscription['user']['name']
     for token in json.load(tokens_fp):
       if token['servicePrincipalId'] == app_id:
         logging.info("Azure credentials are of type 'servicePrincipal'. "
                      'Will reuse them for benchmarking.')
         return cls(
             name, app_id, password=token['accessToken'], user_managed=True)
     logging.warning('No access tokens found matching Azure defaultProfile '
                     'Will try to create a new service principal.')
     return cls()
def Install(vm):
    """Copies Azure credentials to the VM."""
    vm.RemoteCommand('mkdir -p {0}'.format(AZURE_CREDENTIAL_DIRECTORY))
    vm.PushFile(
        object_storage_service.FindCredentialFile(
            AZURE_CREDENTIAL_TOKENS_FILE), AZURE_CREDENTIAL_TOKENS_FILE)
    vm.PushFile(
        object_storage_service.FindCredentialFile(
            AZURE_CREDENTIAL_PROFILE_FILE), AZURE_CREDENTIAL_PROFILE_FILE)
Exemplo n.º 3
0
def Install(vm):
    """Copies Azure credentials to the VM."""
    vm.RemoteCommand('mkdir -p {0}'.format(AZURE_CREDENTIAL_LOCATION))
    vm.PushFile(
        object_storage_service.FindCredentialFile(
            os.path.join('~', AZURE_CREDENTIAL_TOKENS_FILE)),
        AZURE_CREDENTIAL_TOKENS_FILE)
    vm.PushFile(
        object_storage_service.FindCredentialFile(
            os.path.join('~', AZURE_CREDENTIAL_PROFILE_FILE)),
        AZURE_CREDENTIAL_PROFILE_FILE)
Exemplo n.º 4
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')
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def PrepareVM(self, vm):
        vm.Install('azure_cli')

        if FLAGS.azure_lib_version:
            version_string = '==' + FLAGS.azure_lib_version
        else:
            version_string = ''
        vm.RemoteCommand('sudo pip install azure%s' % version_string)

        vm.PushFile(
            object_storage_service.FindCredentialFile(
                '~/' + AZURE_CREDENTIAL_LOCATION), AZURE_CREDENTIAL_LOCATION)
  def PrepareVM(self, vm):
    vm.Install('azure_cli')

    # CPOMMW this check causing errors if lib_version not set
    #if FLAGS.azure_lib_version:
    #  version_string = '==' + FLAGS.azure_lib_version
    #else:
    #  version_string = ''
    #vm.RemoteCommand('sudo pip install azure%s' % version_string)
    vm.RemoteCommand('sudo pip install azure')

    vm.PushFile(
        object_storage_service.FindCredentialFile('~/' +
                                                  AZURE_CREDENTIAL_LOCATION),
        AZURE_CREDENTIAL_LOCATION)
def Install(vm):
  """Copies Azure credentials to the VM."""
  credential_file = object_storage_service.FindCredentialFile(
      os.path.join('~', AZURE_CREDENTIAL_LOCATION))
  vm.PushFile(credential_file, AZURE_CREDENTIAL_LOCATION)
def FindCredentialFile(basename):
    """Return the location of the credential file with the given name."""
    return object_storage_service.FindCredentialFile(
        os.path.join(AZURE_CREDENTIAL_DIRECTORY, basename))