Exemple #1
0
    def GetSummary(self):
        """Gets a client summary object.

    Returns:
      rdf_client.ClientSummary
    Raises:
      ValueError: on bad cloud type
    """
        summary = rdf_client.ClientSummary()
        summary.client_id = self.client_id
        summary.timestamp = self.timestamp

        summary.system_info.release = self.os_release
        summary.system_info.version = str(self.os_version or "")
        summary.system_info.kernel = self.kernel
        summary.system_info.machine = self.arch
        summary.system_info.install_date = self.install_time
        kb = self.knowledge_base
        if kb:
            summary.system_info.fqdn = kb.fqdn
            summary.system_info.system = kb.os
            summary.users = kb.users
            summary.interfaces = self.interfaces
            summary.client_info = self.startup_info.client_info
            if kb.os_release:
                summary.system_info.release = kb.os_release
                if kb.os_major_version:
                    summary.system_info.version = "%d.%d" % (
                        kb.os_major_version, kb.os_minor_version)

        hwi = self.hardware_info
        if hwi:
            summary.serial_number = hwi.serial_number
            summary.system_manufacturer = hwi.system_manufacturer
            summary.system_uuid = hwi.system_uuid

        cloud_instance = self.cloud_instance
        if cloud_instance:
            summary.cloud_type = cloud_instance.cloud_type
            if cloud_instance.cloud_type == "GOOGLE":
                summary.cloud_instance_id = cloud_instance.google.unique_id
            elif cloud_instance.cloud_type == "AMAZON":
                summary.cloud_instance_id = cloud_instance.amazon.instance_id
            else:
                raise ValueError("Bad cloud type: %s" %
                                 cloud_instance.cloud_type)
        return summary
Exemple #2
0
    def GetSummary(self):
        """Gets a client summary object.

    Returns:
      rdf_client.ClientSummary
    Raises:
      ValueError: on bad cloud type
    """
        self.max_age = 0
        summary = rdf_client.ClientSummary(client_id=self.urn)
        summary.system_info.system = self.Get(self.Schema.SYSTEM)
        summary.system_info.release = self.Get(self.Schema.OS_RELEASE)
        summary.system_info.version = str(self.Get(self.Schema.OS_VERSION, ""))
        summary.system_info.kernel = self.Get(self.Schema.KERNEL)
        summary.system_info.fqdn = self.Get(self.Schema.FQDN)
        summary.system_info.machine = self.Get(self.Schema.ARCH)
        summary.system_info.install_date = self.Get(self.Schema.INSTALL_DATE)
        kb = self.Get(self.Schema.KNOWLEDGE_BASE)
        if kb:
            summary.users = kb.users
        summary.interfaces = self.Get(self.Schema.INTERFACES)
        summary.client_info = self.Get(self.Schema.CLIENT_INFO)
        hwi = self.Get(self.Schema.HARDWARE_INFO)
        if hwi:
            summary.serial_number = hwi.serial_number
            summary.system_manufacturer = hwi.system_manufacturer
            summary.system_uuid = hwi.system_uuid
        summary.timestamp = self.age
        cloud_instance = self.Get(self.Schema.CLOUD_INSTANCE)
        if cloud_instance:
            summary.cloud_type = cloud_instance.cloud_type
            if cloud_instance.cloud_type == "GOOGLE":
                summary.cloud_instance_id = cloud_instance.google.unique_id
            elif cloud_instance.cloud_type == "AMAZON":
                summary.cloud_instance_id = cloud_instance.amazon.instance_id
            else:
                raise ValueError("Bad cloud type: %s" %
                                 cloud_instance.cloud_type)

        return summary
Exemple #3
0
    def testRdfFormatter(self):
        """Hints format RDF values with arbitrary values and attributes."""
        # Create a complex RDF value
        rdf = rdf_client.ClientSummary()
        rdf.system_info.system = "Linux"
        rdf.system_info.fqdn = "coreai.skynet.com"
        # Users (repeated)
        rdf.users = [rdf_client.User(username=u) for u in ("root", "jconnor")]
        # Interface (nested, repeated)
        addresses = [
            rdf_client.NetworkAddress(human_readable=a)
            for a in ("1.1.1.1", "2.2.2.2", "3.3.3.3")
        ]
        eth0 = rdf_client.Interface(ifname="eth0", addresses=addresses[:2])
        ppp0 = rdf_client.Interface(ifname="ppp0", addresses=addresses[2])
        rdf.interfaces = [eth0, ppp0]

        template = (
            "{system_info.system} {users.username} {interfaces.ifname} "
            "{interfaces.addresses.human_readable}\n")
        hinter = hints.Hinter(template=template)
        expected = "Linux root,jconnor eth0,ppp0 1.1.1.1,2.2.2.2,3.3.3.3"
        result = hinter.Render(rdf)
        self.assertEqual(expected, result)