예제 #1
0
    def _get_hostname_metadata(self):
        """
        Returns a dictionnary that contains hostname metadata.
        """
        metadata = EC2.get_metadata(self.agentConfig)
        if metadata.get('hostname'):
            metadata['ec2-hostname'] = metadata.get('hostname')
            del metadata['hostname']

        if self.agentConfig.get('hostname'):
            metadata['agent-hostname'] = self.agentConfig.get('hostname')
        else:
            try:
                metadata["socket-hostname"] = socket.gethostname()
            except Exception:
                pass

        try:
            metadata["socket-fqdn"] = socket.getfqdn()
        except Exception:
            pass

        metadata["hostname"] = self.hostname
        metadata["timezones"] = self._decode_tzname(time.tzname)

        # Add cloud provider aliases
        if not metadata.get("host_aliases"):
            metadata["host_aliases"] = []

        host_aliases = GCE.get_host_aliases(self.agentConfig)
        if host_aliases:
            metadata['host_aliases'] += host_aliases

        # Try to get Azure VM ID
        host_aliases = Azure.get_host_aliases(self.agentConfig)
        if host_aliases:
            metadata['host_aliases'] += host_aliases

        try:
            metadata["host_aliases"] += CloudFoundry.get_host_aliases(
                self.agentConfig)
        except Exception:
            pass

        return metadata
예제 #2
0
    def _get_hostname_metadata(self):
        """
        Returns a dictionnary that contains hostname metadata.
        """
        metadata = EC2.get_metadata(self.agentConfig)
        if metadata.get('hostname'):
            metadata['ec2-hostname'] = metadata.get('hostname')
            del metadata['hostname']

        if self.agentConfig.get('hostname'):
            metadata['agent-hostname'] = self.agentConfig.get('hostname')
        else:
            try:
                metadata["socket-hostname"] = socket.gethostname()
            except Exception:
                pass

        try:
            metadata["socket-fqdn"] = socket.getfqdn()
        except Exception:
            pass

        metadata["hostname"] = self.hostname
        metadata["timezones"] = self._decode_tzname(time.tzname)

        # Add cloud provider aliases
        if not metadata.get("host_aliases"):
            metadata["host_aliases"] = []

        host_aliases = GCE.get_host_aliases(self.agentConfig)
        if host_aliases:
            metadata['host_aliases'] += host_aliases

        # Try to get Azure VM ID
        host_aliases = Azure.get_host_aliases(self.agentConfig)
        if host_aliases:
            metadata['host_aliases'] += host_aliases

        try:
            metadata["host_aliases"] += CloudFoundry.get_host_aliases(self.agentConfig)
        except Exception:
            pass

        return metadata