Exemplo n.º 1
0
def read_password(path, default=None):
    """
    Return ProtectedPassword wrapping value of a sysfs attribute, or default if
    default is specified and the attribute does not exists.

    Raises:
        EnviromentError if reading the attribute fails, or default was not
            specified and the attribute does not exist.
    """
    value = read(path, default)
    return password.ProtectedPassword(value)
Exemplo n.º 2
0
Arquivo: v2v.py Projeto: minqf/vdsm
 def __init__(self, vminfo, vmid, irs):
     self._vminfo = vminfo
     self._vmid = vmid
     self._irs = irs
     self._prepared_volumes = []
     self._passwd_file = os.path.join(_V2V_DIR, "%s.tmp" % vmid)
     self._password = password.ProtectedPassword('')
     self._base_command = [_VIRT_V2V.cmd, '-v', '-x']
     self._query_v2v_caps()
     if 'qcow2_compat' in vminfo:
         qcow2_compat = vminfo['qcow2_compat']
         if qcow2_compat not in _QCOW2_COMPAT_SUPPORTED:
             logging.error('Invalid QCOW2 compat version %r' % qcow2_compat)
             raise ValueError('Invalid QCOW2 compat version %r' %
                              qcow2_compat)
         if 'vdsm-compat-option' in self._v2v_caps:
             self._base_command.extend(['--vdsm-compat', qcow2_compat])
         elif qcow2_compat != '0.10':
             # Note: qcow2 is only a suggestion from the engine
             # if virt-v2v doesn't support it we fall back to default
             logging.info(
                 'virt-v2v not supporting qcow2 compat version: '
                 '%r', qcow2_compat)
Exemplo n.º 3
0
def read_tpm_data(vm_id, last_modified):
    """
    Return TPM data of the given VM.

    If data is not newer than `last_modified`, return None.
    In addition to data, the last detected data modification time is
    returned; the returned data may be newer, but never older than the
    returned time.

    :param vm_id: VM id
    :type vm_id: string
    :param last_modified: if data file system time stamp is not
      newer than this time in seconds, None is returned
    :type last_modified: float
    :returns: tuple (DATA, MODIFIED) where DATA is encoded TPM data suitable to
      use in `write_tpm_data()`, wrapped by `password.ProtectedPassword`,
      or None, and MODIFIED is DATA modification time (which may be older than
      actual modification time)
    :rtype: tuple
    """
    accessor = filedata.DirectoryData(filedata.tpm_path(vm_id), compress=False)
    currently_modified = accessor.last_modified()
    data = accessor.retrieve(last_modified=last_modified)
    return password.ProtectedPassword(data), currently_modified
Exemplo n.º 4
0
    'displayPort': -1,
    'displaySecurePort': -1,
    'display': 'qxl',
    'displayIp': '127.0.0.1',
    'vmType': 'kvm',
    'memSize': 1024
}

_TICKET_PARAMS = {
    'userName': '******',
    'userId': 'fdfc627c-d875-11e0-90f0-83df133b58cc'
}

_GRAPHICS_DEVICE_PARAMS = {
    'deviceType': hwclass.GRAPHICS,
    'password': password.ProtectedPassword('12345678'),
    'ttl': 0,
    'existingConnAction': 'disconnect',
    'params': _TICKET_PARAMS
}


@expandPermutations
class TestVmOperations(XMLTestCase):
    # just numbers, no particular meaning
    UPDATE_OFFSETS = [-3200, 3502, -2700, 3601]
    BASE_OFFSET = 42

    VNC_DEVICE = {'type': 'graphics', 'device': 'vnc', 'port': '-1'}
    SPICE_DEVICE = {'type': 'graphics', 'device': 'spice', 'port': '-1'}
Exemplo n.º 5
0
def read_nvram_data(vm_id, last_modified):
    accessor = filedata.FileData(filedata.nvram_path(vm_id))
    currently_modified = accessor.last_modified()
    data = accessor.retrieve(last_modified=last_modified)
    return password.ProtectedPassword(data), currently_modified
Exemplo n.º 6
0
 def test_read_password_missing_default(self):
     self.assertEqual(sysfs.read_password("/no/such/path", ""),
                      password.ProtectedPassword(""))
Exemplo n.º 7
0
 def test_read_password_strip(self):
     with temporaryPath(data=b" password\n ") as path:
         self.assertEqual(sysfs.read_password(path),
                          password.ProtectedPassword("password"))