Beispiel #1
0
    def _GetEncryptedPasswordFromSerialPort(self, search_modulus):
        """Returns the decrypted password from the data in the serial port."""
        encrypted_password_data = {}
        start_time = time_util.CurrentTimeSec()
        count = 1
        agent_ready = False
        while not encrypted_password_data:
            log.debug('Get Serial Port Output, Try {0}'.format(count))
            if (time_util.CurrentTimeSec() >
                (start_time + WINDOWS_PASSWORD_TIMEOUT_SEC)):
                raise utils.TimeoutError(
                    TIMEOUT_ERROR.format(time_util.CurrentDatetimeUtc()))
            serial_port_output = self._GetSerialPortOutput(port=4).split('\n')
            for line in reversed(serial_port_output):
                try:
                    encrypted_password_dict = json.loads(line)
                # Sometimes the serial port output only contains a partial entry.
                except ValueError:
                    continue

                modulus = encrypted_password_dict.get('modulus')
                if modulus or encrypted_password_dict.get('ready'):
                    agent_ready = True

                # Ignore any output that doesn't contain an encrypted password.
                if not encrypted_password_dict.get('encryptedPassword'):
                    continue

                if search_modulus == modulus:
                    encrypted_password_data = encrypted_password_dict
                    break
            if not agent_ready:
                if self.old_metadata_keys:
                    message = OLD_WINDOWS_BUILD_ERROR.format(
                        self.ref.Name(), self.ref.zone)
                    raise utils.WrongInstanceTypeError(message)
                else:
                    message = NOT_READY_ERROR
                    raise utils.InstanceNotReadyError(message)
            time_util.Sleep(POLLING_SEC)
            count += 1
        encrypted_password = encrypted_password_data['encryptedPassword']
        return encrypted_password
Beispiel #2
0
    def Run(self, args):
        start = time_utils.CurrentTimeSec()
        group_ref = self.CreateGroupReference(args)

        while True:
            responses, errors = self._GetResources(group_ref)
            if errors:
                utils.RaiseToolException(errors)
            if wait_info.IsGroupStable(responses[0]):
                break
            log.out.Print(wait_info.CreateWaitText(responses[0]))
            time_utils.Sleep(WaitUntilStable._TIME_BETWEEN_POLLS_SEC)

            if args.timeout and time_utils.CurrentTimeSec(
            ) - start > args.timeout:
                raise utils.TimeoutError(
                    'Timeout while waiting for group to become '
                    'stable.')
        log.out.Print('Group is stable')
  def Run(self, args):
    """Issues requests necessary to wait until stable on a MIG."""
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client
    start = time_util.CurrentTimeSec()
    group_ref = self.CreateGroupReference(client, holder.resources, args)

    while True:
      responses, errors = self._GetResources(client, group_ref)
      if errors:
        utils.RaiseToolException(errors)
      if wait_info.IsGroupStable(responses[0]):
        break
      log.out.Print(wait_info.CreateWaitText(responses[0]))
      time_util.Sleep(WaitUntilStable._TIME_BETWEEN_POLLS_SEC)

      if args.timeout and time_util.CurrentTimeSec() - start > args.timeout:
        raise utils.TimeoutError('Timeout while waiting for group to become '
                                 'stable.')
    log.out.Print('Group is stable')