Exemplo n.º 1
0
    def add_product(self, product_name, product_description, attributes,
                    metadatas):
        print 'add_product'
        url = "%s/%s" % (self.sdc_url, "catalog/product")
        headers = {
            'X-Auth-Token': self.token,
            'Tenant-Id': self.vdc,
            'Accept': "application/json",
            'Content-Type': 'application/xml'
        }

        attributes = self.__process_attributes(attributes)
        metadatas = self.__process_attributes(metadatas)

        product = Product(product_name, product_description)

        for att in attributes:
            product.add_attribute(att)

        for meta in metadatas:
            product.add_metadata(meta)

        payload = product.to_product_xml()

        response = http.post(url, headers, tostring(payload))

        ## Si la respuesta es la adecuada, creo el diccionario de los datos en JSON.
        if response.status != 200:
            print 'error to add the product sdc ' + str(response.status)
            sys.exit(1)
        else:
            self.products.append(product)
Exemplo n.º 2
0
    def get_product_info(self, product_name):
        #headers={'X-Auth-Token': self.token,
        #         'Accept': "application/json"}
        headers = {
            'X-Auth-Token': self.token,
            'Tenant-Id': self.vdc,
            'Accept': "application/json"
        }
        #get product release
        url = "%s/%s/%s" % (self.sdc_url, "catalog/product", product_name)

        response = http.get(url, headers)

        if response.status != 200:
            print 'error to get the product ' + product_name + ' ' + str(
                response.status)
            sys.exit(1)
        else:
            data = json.loads(response.read())
            print data
            if data == None:
                return None
            product = Product(data['name'], data['description'])
            try:
                for att in data['attributes']:
                    attribute = Attribute(att['key'], att['version'])
                    product.add_attribute(attribute)
            except:
                pass

            return product
Exemplo n.º 3
0
    def add_product(self, product_name, product_description, attributes, metadatas):
        url = "%s/%s" % (self.sdc_url, "catalog/product")
        headers = {'Content-Type': 'application/xml'}

        attributes = self.__process_attributes(attributes)
        metadatas = self.__process_attributes(metadatas)

        product = Product(product_name, product_description)

        for att in attributes:
            product.add_attribute(att)

        for meta in metadatas:
            product.add_metadata(meta)

        payload = product.to_product_xml()

        response = http.post(url, headers, tostring(payload))

        ## Si la respuesta es la adecuada, creo el diccionario de los datos en JSON.
        if response.status != 200:
            print 'error to add the product sdc ' + str(response.status)
            sys.exit(1)
        else:
            self.products.append(product)
Exemplo n.º 4
0
    def get_product_info(self, product_name):
        #headers={'X-Auth-Token': self.token,
        #         'Accept': "application/json"}
        headers = {'Accept': "application/json"}
        #get product release
        url = "%s/%s/%s" % (self.sdc_url, "catalog/product", product_name )

        response = http.get(url, headers)

        if response.status != 200:
            print 'error to get the product ' + product_name + ' ' + str(response.status)
            sys.exit(1)
        else:
            data = json.loads(response.read())
            print data
            if data == None:
                return None
            product = Product(data['name'], data['description'])
            try:
                for att in data['attributes']:
                    attribute = Attribute(att['key'], att['version']);
                    product.add_attribute(attribute)
            except:
                pass

            return product
Exemplo n.º 5
0
    def get_products(self):
        url = "%s/%s" % (self.sdc_url, "catalog/product")
        print url
        print self.token
        #headers={'X-Auth-Token': self.token,
        #     'Accept': "application/json"}
        headers = {
            'X-Auth-Token': self.token,
            'Tenant-Id': self.vdc,
            'Accept': "application/json"
        }
        print headers
        response = http.get(url, headers)

        ## Si la respuesta es la adecuada, creo el diccionario de los datos en JSON.
        if response.status != 200:
            print 'error to obtain the the list of product' + str(
                response.status)
            sys.exit(1)
        else:
            data = json.loads(response.read())

            products = data["product"]

            for product in products:
                var = product['name']
                prod = Product(product['name'])
                try:
                    attributes = product['attributes']
                    var = var + '  atts:'
                    for att in attributes:
                        attri = Attribute(att['key'], att['value'])
                        prod.add_attribute(attri)
                        var = var + '\t' + att['key'] + ":" + att['value']
                except:
                    pass
                try:
                    metadatas = product['metadatas']
                    var = var + '  metas:'
                    for meta in metadatas:
                        var = var + '\t' + meta['key'] + ":" + meta['value']
                except:
                    pass
                print var
Exemplo n.º 6
0
    def get_products(self):
        url = "%s/%s" % (self.sdc_url, "catalog/product")
        #headers={'X-Auth-Token': self.token,
        #     'Accept': "application/json"}
        headers = {'Accept': "application/json"}
        print url
        response = http.get(url, headers)

        ## Si la respuesta es la adecuada, creo el diccionario de los datos en JSON.
        if response.status != 200:
            print 'error to obtain the token'
            sys.exit(1)
        else:
            data = json.loads(response.read())

            products = data["product"]

            for product in products:
                var = product['name']
                prod = Product(product['name'])
                try:
                    attributes = product['attributes']
                    var = var + '  atts:'
                    for att in attributes:
                        attri = Attribute(att['key'], att['value'])
                        prod.add_attribute(attri)
                        var = var + '\t' + att['key'] + ":" + att['value']
                except:
                    pass
                try:
                    metadatas = product['metadatas']
                    var = var + '  metas:'
                    for meta in metadatas:
                        var = var + '\t' + meta['key'] + ":" + meta['value']
                except:
                    pass
                print var