def get_data(self):
        found = None
        md = {}
        ud = ""

        defaults = {"instance-id": DEFAULT_IID, "dsmode": "pass"}

        if os.path.isdir(self.seeddir):
            try:
                (md, ud) = read_config_drive_dir(self.seeddir)
                found = self.seeddir
            except nonConfigDriveDir:
                pass

        if not found:
            dev = cfg_drive_device()
            if dev:
                try:
                    (md, ud) = util.mount_callback_umount(dev,
                        read_config_drive_dir)
                    found = dev
                except (nonConfigDriveDir, util.mountFailedError):
                    pass

        if not found:
            return False

        if 'dsconfig' in md:
            self.cfg = md['dscfg']

        md = util.mergedict(md, defaults)

        # update interfaces and ifup only on the local datasource
        # this way the DataSourceConfigDriveNet doesn't do it also.
        if 'network-interfaces' in md and self.dsmode == "local":
            if md['dsmode'] == "pass":
                log.info("updating network interfaces from configdrive")
            else:
                log.debug("updating network interfaces from configdrive")

            util.write_file("/etc/network/interfaces",
                md['network-interfaces'])
            try:
                (out, err) = util.subp(['ifup', '--all'])
                if len(out) or len(err):
                    log.warn("ifup --all had stderr: %s" % err)

            except subprocess.CalledProcessError as exc:
                log.warn("ifup --all failed: %s" % (exc.output[1]))

        self.seed = found
        self.metadata = md
        self.userdata_raw = ud

        if md['dsmode'] == self.dsmode:
            return True

        log.debug("%s: not claiming datasource, dsmode=%s" %
            (self, md['dsmode']))
        return False
    def get_data(self):
        defaults = {
            "instance-id": "nocloud", "dsmode": self.dsmode
        }

        found = []
        md = {}
        ud = ""

        try:
            # parse the kernel command line, getting data passed in
            if parse_cmdline_data(self.cmdline_id, md):
                found.append("cmdline")
        except:
            util.logexc(log)
            return False

        # check to see if the seeddir has data.
        seedret = {}
        if util.read_optional_seed(seedret, base=self.seeddir + "/"):
            md = util.mergedict(md, seedret['meta-data'])
            ud = seedret['user-data']
            found.append(self.seeddir)
            log.debug("using seeded cache data in %s" % self.seeddir)

        # if the datasource config had a 'seedfrom' entry, then that takes
        # precedence over a 'seedfrom' that was found in a filesystem
        # but not over external medi
        if 'seedfrom' in self.ds_cfg and self.ds_cfg['seedfrom']:
            found.append("ds_config")
            md["seedfrom"] = self.ds_cfg['seedfrom']

        fslist = util.find_devs_with("TYPE=vfat")
        fslist.extend(util.find_devs_with("TYPE=iso9660"))

        label_list = util.find_devs_with("LABEL=cidata")
        devlist = list(set(fslist) & set(label_list))
        devlist.sort(reverse=True)

        for dev in devlist:
            try:
                (newmd, newud) = util.mount_callback_umount(dev,
                    util.read_seeded)
                md = util.mergedict(newmd, md)
                ud = newud

                # for seed from a device, the default mode is 'net'.
                # that is more likely to be what is desired.
                # If they want dsmode of local, then they must
                # specify that.
                if 'dsmode' not in md:
                    md['dsmode'] = "net"

                log.debug("using data from %s" % dev)
                found.append(dev)
                break
            except OSError, e:
                if e.errno != errno.ENOENT:
                    raise
            except util.mountFailedError:
                log.warn("Failed to mount %s when looking for seed" % dev)
    def get_data(self):
        found = None
        md = {}
        ud = ""

        defaults = {"instance-id": DEFAULT_IID, "dsmode": "pass"}

        if os.path.isdir(self.seeddir):
            try:
                (md, ud) = read_config_drive_dir(self.seeddir)
                found = self.seeddir
            except nonConfigDriveDir:
                pass

        if not found:
            dev = cfg_drive_device()
            if dev:
                try:
                    (md,
                     ud) = util.mount_callback_umount(dev,
                                                      read_config_drive_dir)
                    found = dev
                except (nonConfigDriveDir, util.mountFailedError):
                    pass

        if not found:
            return False

        if 'dsconfig' in md:
            self.cfg = md['dscfg']

        md = util.mergedict(md, defaults)

        # update interfaces and ifup only on the local datasource
        # this way the DataSourceConfigDriveNet doesn't do it also.
        if 'network-interfaces' in md and self.dsmode == "local":
            if md['dsmode'] == "pass":
                log.info("updating network interfaces from configdrive")
            else:
                log.debug("updating network interfaces from configdrive")

            util.write_file("/etc/network/interfaces",
                            md['network-interfaces'])
            try:
                (out, err) = util.subp(['ifup', '--all'])
                if len(out) or len(err):
                    log.warn("ifup --all had stderr: %s" % err)

            except subprocess.CalledProcessError as exc:
                log.warn("ifup --all failed: %s" % (exc.output[1]))

        self.seed = found
        self.metadata = md
        self.userdata_raw = ud

        if md['dsmode'] == self.dsmode:
            return True

        log.debug("%s: not claiming datasource, dsmode=%s" %
                  (self, md['dsmode']))
        return False