From: bayramov Date: Wed, 28 Sep 2016 13:16:55 +0000 (+0400) Subject: fixed issue relayted to upload multiply files. X-Git-Tag: v1.0.0~17 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=163f1ae369767e20bb7d6b73de455f03a6e3c233;p=osm%2FRO.git fixed issue relayted to upload multiply files. Signed-off-by: bayramov --- diff --git a/vimconn_vmware.py b/vimconn_vmware.py index ff457ce7..64a1542e 100644 --- a/vimconn_vmware.py +++ b/vimconn_vmware.py @@ -364,7 +364,7 @@ class vimconnector(vimconn.vimconnector): else: raise vimconn.vimconnException("Failed create tenant {}".format(tenant_name)) - def delete_tenant(self, tenant_id, ): + def delete_tenant(self, tenant_id=None): """Delete a tenant from VIM""" 'Returns the tenant identifier' raise vimconn.vimconnNotImplemented("Should have implemented this") @@ -767,8 +767,7 @@ class vimconnector(vimconn.vimconnector): media = mediaType.parseString(response.content, True) link = \ filter(lambda link: link.get_rel() == 'upload:default', - media.get_Files().get_File()[0].get_Link())[ - 0] + media.get_Files().get_File()[0].get_Link())[0] headers = vca.vcloud_session.get_vcloud_headers() headers['Content-Type'] = 'Content-Type text/xml' response = Http.put(link.get_href(), data=open(media_file_name, 'rb'), headers=headers, @@ -791,49 +790,47 @@ class vimconnector(vimconn.vimconnector): logger=self.logger) if response.status_code == requests.codes.ok: media = mediaType.parseString(response.content, True) - link = \ - filter(lambda link: link.get_rel() == 'upload:default', - media.get_Files().get_File()[0].get_Link())[ - 0] - - # The OVF file and VMDK must be in a same directory - head, tail = os.path.split(media_file_name) - filevmdk = head + '/' + os.path.basename(link.get_href()) - - os.path.isfile(filevmdk) - statinfo = os.stat(filevmdk) - - # TODO debug output remove it - # print media.get_Files().get_File()[0].get_Link()[0].get_href() - # print media.get_Files().get_File()[1].get_Link()[0].get_href() - # print link.get_href() - - # in case first element is pointer to OVF. - hrefvmdk = link.get_href().replace("descriptor.ovf", "Cirros-disk1.vmdk") - - f = open(filevmdk, 'rb') - bytes_transferred = 0 - while bytes_transferred < statinfo.st_size: - my_bytes = f.read(chunk_bytes) - if len(my_bytes) <= chunk_bytes: - headers = vca.vcloud_session.get_vcloud_headers() - headers['Content-Range'] = 'bytes %s-%s/%s' % ( - bytes_transferred, len(my_bytes) - 1, statinfo.st_size) - headers['Content-Length'] = str(len(my_bytes)) - response = Http.put(hrefvmdk, - headers=headers, - data=my_bytes, - verify=vca.verify, - logger=None) - if response.status_code == requests.codes.ok: - bytes_transferred += len(my_bytes) - self.logger.debug('transferred %s of %s bytes' % (str(bytes_transferred), - str(statinfo.st_size))) - else: - self.logger.debug('file upload failed with error: [%s] %s' % (response.status_code, - response.content)) - return False - f.close() + links_list = filter(lambda link: link.get_rel() == 'upload:default', + media.get_Files().get_File()[0].get_Link()) + + for link in links_list: + # The OVF file and VMDK must be in a same directory + head, tail = os.path.split(media_file_name) + media_file_name = link.get_href() + if 'ovf' in media_file_name: + print "skiping {}".format(media_file_name) + continue + file_vmdk = head + '/' + os.path.basename(link.get_href()) + os.path.isfile(file_vmdk) + statinfo = os.stat(file_vmdk) + + # in case first element is pointer to OVF. + hrefvmdk = link.get_href().replace("descriptor.ovf", media_file_name) + print("Uploading file {}".format(hrefvmdk)) + + f = open(file_vmdk, 'rb') + bytes_transferred = 0 + while bytes_transferred < statinfo.st_size: + my_bytes = f.read(chunk_bytes) + if len(my_bytes) <= chunk_bytes: + headers = vca.vcloud_session.get_vcloud_headers() + headers['Content-Range'] = 'bytes %s-%s/%s' % ( + bytes_transferred, len(my_bytes) - 1, statinfo.st_size) + headers['Content-Length'] = str(len(my_bytes)) + response = Http.put(hrefvmdk, + headers=headers, + data=my_bytes, + verify=vca.verify, + logger=None) + if response.status_code == requests.codes.ok: + bytes_transferred += len(my_bytes) + self.logger.debug('transferred %s of %s bytes' % (str(bytes_transferred), + str(statinfo.st_size))) + else: + self.logger.debug('file upload failed with error: [%s] %s' % (response.status_code, + response.content)) + return False + f.close() return True else: self.logger.debug("Failed retrieve vApp template for catalog name {} for OVF {}". diff --git a/vmwarerecli.py b/vmwarerecli.py index 547abf96..c332cdb6 100755 --- a/vmwarerecli.py +++ b/vmwarerecli.py @@ -527,8 +527,10 @@ def boot_image(vim=None, image_name=None, vm_name=None): The image name can be UUID of name. Args: - image_name - image identified by UUID or text string. - vm_name + vim - vim connector + image_name - image identified by UUID or text string. + vm_name - vmname + Returns: The return true if image uploaded correctly