Exemple #1
0
    def _get_data(self):
        url_params = self.get_url_params()
        network_context = noop()
        if self.perform_dhcp_setup:
            network_context = EphemeralDHCPv4(self.fallback_interface)
        with network_context:
            ret = util.log_time(
                LOG.debug,
                "Crawl of GCE metadata service",
                read_md,
                kwargs={
                    "address": self.metadata_address,
                    "url_params": url_params,
                },
            )

        if not ret["success"]:
            if ret["platform_reports_gce"]:
                LOG.warning(ret["reason"])
            else:
                LOG.debug(ret["reason"])
            return False
        self.metadata = ret["meta-data"]
        self.userdata_raw = ret["user-data"]
        return True
    def _get_data(self):
        if not self._is_platform_viable():
            return False

        self.system_uuid = _read_system_uuid()

        # network may be configured if iscsi root.  If that is the case
        # then read_initramfs_config will return non-None.
        fetch_vnics_data = self.ds_cfg.get(
            "configure_secondary_nics",
            BUILTIN_DS_CONFIG["configure_secondary_nics"],
        )
        network_context = noop()
        if not _is_iscsi_root():
            network_context = dhcp.EphemeralDHCPv4(
                iface=net.find_fallback_nic(),
                connectivity_url_data={
                    "url": METADATA_PATTERN.format(version=2, path="instance"),
                    "headers": V2_HEADERS,
                },
            )
        with network_context:
            fetched_metadata = read_opc_metadata(
                fetch_vnics_data=fetch_vnics_data)

        data = self._crawled_metadata = fetched_metadata.instance_data
        self.metadata_address = METADATA_ROOT.format(
            version=fetched_metadata.version)
        self._vnics_data = fetched_metadata.vnics_data

        self.metadata = {
            "availability-zone": data["ociAdName"],
            "instance-id": data["id"],
            "launch-index": 0,
            "local-hostname": data["hostname"],
            "name": data["displayName"],
        }

        if "metadata" in data:
            user_data = data["metadata"].get("user_data")
            if user_data:
                self.userdata_raw = base64.b64decode(user_data)
            self.metadata["public_keys"] = data["metadata"].get(
                "ssh_authorized_keys")

        return True