示例#1
0
    def doWork(self):

        # checking marketplace endpoint URL
        url_is_ok = Util.checkUrlExists(ENDPOINT_MKP, 30)
        if url_is_ok is True:

            req = urllib2.Request(ENDPOINT_MKP)
            response = urllib2.urlopen(req)
            content = response.read()

            xml = Util.etree_from_text(content)

            desc_nodes = xml.iter("{" + RDF + "}Description")
            all_desc = []
            desc = {}

            for desc_node in desc_nodes:
                desc["description"] = desc_node.find('{' + DCTERMS + '}description').text
                desc["identifier"] = desc_node.find('{' + DCTERMS + '}identifier').text
                desc["creator"] = desc_node.find('{' + DCTERMS + '}creator').text
                desc["created"] = desc_node.find('{' + DCTERMS + '}created').text
                desc["os"] = desc_node.find('{' + SLTERMS + '}os').text
                desc["os-version"] = desc_node.find('{' + SLTERMS + '}os-version').text
                desc["os-arch"] = desc_node.find('{' + SLTERMS + '}os-arch').text

                # cast in str for NoneType object (otherwise, we should use try/Except)
                print "Description: " + str(desc["description"])
                print "ID: " + str(desc["identifier"])
                print "OS: " + str(desc["os"]), str(desc["os-version"]), "| Arch: " + str(desc["os-arch"])
                print "Creator: " + str(desc["creator"])
                print "Created at: " + str(desc["created"].replace("Z", "").split('T'))
                print "####\n"
                all_desc.append(desc)
示例#2
0
 def _checkImageByUrl(self, imageUrl):
     try:
         Util.checkUrlExists(imageUrl)
     except (Exceptions.ValidationException, Exceptions.ExecutionException), ex:
         raise Exceptions.ValidationException("Unable to access image '%s': %s" %
                                   (imageUrl, str(ex)))
示例#3
0
    def doWork(self):

        id = self.options.image

        # checking marketplace endpoint URL
        url_is_ok = Util.checkUrlExists(ENDPOINT_MKP, 30)
        if url_is_ok is True and id is not False:

            req = urllib2.Request(ENDPOINT_MKP)
            response = urllib2.urlopen(req)
            content = response.read()

            xml = Util.etree_from_text(content)

            desc_nodes = xml.iter("{" + RDF + "}Description")
            desc = {}

            for desc_node in desc_nodes:
                desc["identifier"] = desc_node.find('{' + DCTERMS + '}identifier').text
                if id == desc["identifier"]:

                    desc["checksum"] = {}
                    desc["checksum"]["val"] = []
                    desc["checksum"]["algo"] = []

                    desc["description"] = desc_node.find('{' + DCTERMS + '}description').text
                    desc["creator"] = desc_node.find('{' + DCTERMS + '}creator').text
                    desc["created"] = desc_node.find('{' + DCTERMS + '}created').text
                    desc["valid"] = desc_node.find('{' + DCTERMS + '}valid').text
                    desc["os"] = desc_node.find('{' + SLTERMS + '}os').text
                    desc["os-version"] = desc_node.find('{' + SLTERMS + '}os-version').text
                    desc["os-arch"] = desc_node.find('{' + SLTERMS + '}os-arch').text
                    desc["version"] = desc_node.find('{' + SLTERMS + '}version').text
                    desc["compression"] = desc_node.find('{' + DCTERMS + '}compression').text
                    desc["location"] = desc_node.find('{' + SLTERMS + '}location').text
                    desc["location"] = desc_node.find('{' + SLTERMS + '}location').text
                    desc["format"] = desc_node.find('{' + DCTERMS + '}format').text
                    desc["publisher"] = desc_node.find('{' + DCTERMS + '}publisher').text
                    desc["hypervisor"] = desc_node.find('{' + SLTERMS + '}hypervisor').text
                    for check in desc_node.findall('{' + SLREQ + '}checksum'):
                        desc["checksum"]["algo"].append(check.find('{' + SLREQ + '}algorithm').text)
                        desc["checksum"]["val"].append(check.find('{' + SLREQ + '}value').text)
                    for endorsement in desc_node.findall('{' + SLREQ + '}endorsement'):
                        for endorser in endorsement.findall('{' + SLREQ + '}endorser'):
                            desc["email"] = endorser.find('{' + SLREQ + '}email').text

                    # cast in str for None object (otherwise, I should use try/Except)
                    print "Description: " + str(desc["description"])
                    print "ID: " + str(desc["identifier"])
                    print "Creator: " + str(desc["creator"])
                    print "Created at: " + str(desc["created"].replace("Z", "").split('T'))
                    print "Validity: " + str(desc["valid"].replace("Z", "").split('T'))
                    print "OS: " + str(desc["os"]), str(desc["os-version"]), "| Arch: " + str(desc["os-arch"])
                    print "Version: " + str(desc["version"])
                    print "Compression: " + str(desc["compression"])
                    print "Location: " + str(desc["location"])
                    print "Format: " + str(desc["format"])
                    print "Publisher: " + str(desc["publisher"])
                    print "Hypervisor: " + str(desc["hypervisor"])
                    print "Endorser: " + str(desc["email"])
                    for i in range(len(desc["checksum"]["algo"])):
                        print str(desc["checksum"]["algo"][i]), str(desc["checksum"]["val"][i])
                    print "####\n"
示例#4
0
    def doWork(self):

        key_criteria = {"creator": "",
                        "email": "",
                        "os": "",
                        "description": "",
                        "regexp": "",
                        "arch": ""}

        use_regexp = False

        if self.options.creator is not None:
            creator = self.options.creator
            key_criteria["creator"] = creator
        if self.options.email is not None:
            email = self.options.email
            key_criteria["email"] = email
        if self.options.os is not None:
            os = self.options.os
            key_criteria["os"] = os
        if self.options.description is not None:
            description = self.options.description
            key_criteria["description"] = description
        description_compile = None
        if self.options.regexp is not None:
            regexp = self.options.regexp
            use_regexp = True
            key_criteria["description"] = regexp
            description_compile = re.compile(regexp)
        if self.options.arch is not None:
            arch = self.options.arch
            key_criteria["arch"] = arch

        # checking marketplace endpoint URL
        url_is_ok = Util.checkUrlExists(ENDPOINT_MKP, 30)
        if url_is_ok is True:

            req = urllib2.Request(ENDPOINT_MKP)
            response = urllib2.urlopen(req)
            content = response.read()

            xml = Util.etree_from_text(content)

            desc_nodes = xml.iter("{" + RDF + "}Description")
            desc = {}

            found = 0

            for desc_node in desc_nodes:

                if key_criteria["creator"] != "":
                    desc["creator"] = desc_node.find('{' + DCTERMS + '}creator').text
                    if key_criteria["creator"] == desc["creator"]:
                        if found < 1:
                            print "####"
                        found += 1
                        print "CREATOR FOUND"

                if key_criteria["os"] != "":
                    desc["os"] = desc_node.find('{' + SLTERMS + '}os').text
                    if key_criteria["os"] == desc["os"]:
                        if found < 1:
                            print "####"
                        found += 1
                        print "OS FOUND"

                if key_criteria["arch"] != "":
                    desc["arch"] = desc_node.find('{' + SLTERMS + '}os-arch').text
                    if key_criteria["arch"] == desc["arch"]:
                        if found < 1:
                            print "####"
                        found += 1
                        print "ARCH FOUND"

                if key_criteria["description"] != "":
                    desc["description"] = desc_node.find('{' + DCTERMS + '}description').text
                    if use_regexp is False:
                        if key_criteria["description"] == desc["description"]:
                            if found < 1:
                                print "####"
                            found += 1
                            print "DESCRIPTION FOUND"
                    else:
                        if desc["description"] is not None and description_compile is not None:
                            if description_compile.search(desc["description"]):
                                if found < 1:
                                    print "####"
                                found += 1
                                print "DESCRIPTION[REGEXP] FOUND"

                if key_criteria["email"] != "":
                    for endorsement in desc_node.findall('{' + SLREQ + '}endorsement'):
                        for endorser in endorsement.findall('{' + SLREQ + '}endorser'):
                            desc["email"] = endorser.find('{' + SLREQ + '}email').text
                    if key_criteria["email"] == desc["email"]:
                        if found < 1:
                            print "####"
                        found += 1
                        print "EMAIL FOUND"

                if found >= 1:
                    print "%d critera match your search for this image" % found
                    print "####"
                    self._print_image(desc_node)

                found = 0