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
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
def get_products(self): url = "%s/%s" % (self.sdc_url, "catalog/product") headers = {'Accept': "application/json"} #headers={'X-Auth-Token': self.token, # 'Accept': "application/json"} 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_string = data["product"] for product_string in products_string: product = Product(product_string['name']) try: attributes = product['attributes'] var = var + ' atts:' for att in attributes: 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
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)
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
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)
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
def __process_environment(self, env): environment = Environment(env['name'], env['description']) try: tiers_string = env['tierDtos'] except: environment.to_string() return environment if isinstance(tiers_string, list): for tier_string in tiers_string: tier = Tier(tier_string['name'], self.image, tier_string['region']) try: products_string = tier_string['productReleaseDtos'] if isinstance(products_string, list): for product_string in products_string: product = ProductRelease(product_string['productName'], product_string['version']) tier.add_product(product) else: product = ProductRelease(products_string['productName'], products_string['version']) tier.add_product(product) except: pass environment.add_tier(tier) else: tier = Tier(tiers_string['name'], self.image) try: products_string = tiers_string['productReleaseDtos'] if isinstance(products_string, list): for product_string in products_string: producte = Product(product_string['productName']) product_release = ProductRelease(producte, product_string['version']) tier.add_product(product_release) else: product = ProductRelease(products_string['productName'], products_string['version']) tier.add_product(product) environment.add_tier(tier) except: print 'error' pass environment.to_string() return environment
def add_product_release(self, product_name, version): url = "%s/%s/%s/%s" % (self.sdc_url, "catalog/product", product_name, "release") headers = {'Content-Type': 'application/xml'} # product = self.get_product_info (product_name) product = Product(product_name) product_release = ProductRelease(product, version) payload = product_release.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 release to sdc ' + str( response.status) sys.exit(1) else: self.products.append(product)