Beispiel #1
0
    def _get_data(self):
        LOG.debug("Detecting if machine is a Vultr instance")
        if not vultr.is_vultr():
            LOG.debug("Machine is not a Vultr instance")
            return False

        LOG.debug("Machine is a Vultr instance")

        # Fetch metadata
        self.metadata = self.get_metadata()
        self.metadata['instance-id'] = self.metadata['instanceid']
        self.metadata['local-hostname'] = self.metadata['hostname']
        self.userdata_raw = self.metadata["user-data"]

        # Generate config and process data
        self.get_datasource_data(self.metadata)

        # Dump some data so diagnosing failures is manageable
        LOG.debug("Vultr Vendor Config:")
        LOG.debug(util.json_dumps(self.metadata['vendor-data']))
        LOG.debug("SUBID: %s", self.metadata['instance-id'])
        LOG.debug("Hostname: %s", self.metadata['local-hostname'])
        if self.userdata_raw is not None:
            LOG.debug("User-Data:")
            LOG.debug(self.userdata_raw)

        return True
Beispiel #2
0
    def _get_data(self):
        LOG.debug("Detecting if machine is a Vultr instance")
        if not vultr.is_vultr():
            LOG.debug("Machine is not a Vultr instance")
            return False

        LOG.debug("Machine is a Vultr instance")

        # Fetch metadata
        self.metadata = self.get_metadata()
        self.metadata["instance-id"] = self.metadata["instance-v2-id"]
        self.metadata["local-hostname"] = self.metadata["hostname"]
        region = self.metadata["region"]["regioncode"]
        if "countrycode" in self.metadata["region"]:
            region = self.metadata["region"]["countrycode"]
        self.metadata["region"] = region.lower()
        self.userdata_raw = self.metadata["user-data"]

        # Generate config and process data
        self.get_datasource_data(self.metadata)

        # Dump some data so diagnosing failures is manageable
        LOG.debug("Vultr Vendor Config:")
        LOG.debug(util.json_dumps(self.metadata["vendor-data"]))
        LOG.debug("SUBID: %s", self.metadata["instance-id"])
        LOG.debug("Hostname: %s", self.metadata["local-hostname"])
        if self.userdata_raw is not None:
            LOG.debug("User-Data:")
            LOG.debug(self.userdata_raw)

        return True
Beispiel #3
0
    def check_instance_id(self, sys_cfg):
        if not vultr.is_vultr():
            return False

        # Baremetal has no way to implement this in local
        if vultr.is_baremetal():
            return False

        subid = vultr.get_sysinfo()['subid']
        return sources.instance_id_matches_system_uuid(subid)
Beispiel #4
0
# Used to match classes to dependencies
datasources = [
    (DataSourceVultr, (sources.DEP_FILESYSTEM, )),
]


# Return a list of data sources that match this set of dependencies
def get_datasource_list(depends):
    return sources.list_from_depends(depends, datasources)


if __name__ == "__main__":
    import sys

    if not vultr.is_vultr():
        print("Machine is not a Vultr instance")
        sys.exit(1)

    md = vultr.get_metadata(BUILTIN_DS_CONFIG['url'],
                            BUILTIN_DS_CONFIG['timeout'],
                            BUILTIN_DS_CONFIG['retries'],
                            BUILTIN_DS_CONFIG['wait'],
                            BUILTIN_DS_CONFIG['user-agent'])
    config = md['vendor-data']
    sysinfo = vultr.get_sysinfo()

    print(util.json_dumps(sysinfo))
    print(util.json_dumps(config))

# vi: ts=4 expandtab