def Attach(self):
    """Attach to an existing extstorage device.

    This method maps the extstorage volume that matches our name with
    a corresponding block device and then attaches to this device.

    """
    self.attached = False

    # Call the External Storage's attach script,
    # to attach an existing Volume to a block device under /dev
    result = _ExtStorageAction(constants.ES_ACTION_ATTACH,
                               self.unique_id, self.ext_params,
                               name=self.name, uuid=self.uuid)

    # Attach script returns the block device path and optionally
    # the URIs to be used for userspace access (one URI for
    # each hypervisor supported).
    # If the provider doesn't support userspace access, then
    # the 'uris' variable will be an empty list.
    result = result.split("\n")
    self.dev_path = result[0]
    self.uris = result[1:]

    if not self.dev_path:
      logging.info("A local block device is not available")
      self.dev_path = None
      if not self.uris:
        logging.error("Neither a block device nor a userspace URI is available")
        return False

      self.attached = True
      return True

    # Verify that dev_path exists and is a block device
    try:
      st = os.stat(self.dev_path)
    except __HOLE__, err:
      logging.error("Error stat()'ing %s: %s", self.dev_path, str(err))
      return False

    if not stat.S_ISBLK(st.st_mode):
      logging.error("%s is not a block device", self.dev_path)
      return False

    self.major = os.major(st.st_rdev)
    self.minor = utils.osminor(st.st_rdev)
    self.attached = True

    return True
dataset/ETHPy150Open ganeti/ganeti/lib/storage/extstorage.py/ExtStorageDevice.Attach