Merge changes I95651dbd,If52f42c5
authormarchettim <mmarchetti@sandvine.com>
Tue, 20 Nov 2018 20:42:58 +0000 (21:42 +0100)
committerGerrit Code Review <root@osm.etsi.org>
Tue, 20 Nov 2018 20:42:58 +0000 (21:42 +0100)
* changes:
  Rename juju-charms -> charms
  An example of a multi-charm, multi-vdu VNF

13 files changed:
descriptor-packages/vnfd/hackfest_basic_vnf/src/hackfest_basic_vnfd.yaml
docker/LCM/Dockerfile
docker/MON/Dockerfile
docker/MON/scripts/runInstall.sh
docker/NBI/Dockerfile
docker/POL/Dockerfile
installers/docker/osm_elk/metricbeat.yml
installers/docker/osm_metrics/osm-sample-dashboard.json
installers/full_install_osm.sh
jenkins/ci-pipelines/ci_stage_3.groovy
systest/Makefile
systest/lib/vim/vim.py
tools/vmware_ovf_upload.py

index 3c18d79..4051eb3 100644 (file)
@@ -13,6 +13,9 @@ vnfd:vnfd-catalog:
         -   id: hackfest_basic-VM
             name: hackfest_basic-VM
             image: ubuntu1604
+            alternative-images:
+            -   vim-type: aws
+                image: ubuntu/images/hvm-ssd/ubuntu-artful-17.10-amd64-server-20180509
             count: '1'
             vm-flavor:
                 vcpu-count: '1'
index 1a750d3..909ea3a 100644 (file)
@@ -84,8 +84,11 @@ ENV OSMLCM_VCA_SECRET:     secret
 
 # database
 ENV OSMLCM_DATABASE_DRIVER mongo
-ENV OSMLCM_DATABASE_HOST   mongo
-ENV OSMLCM_DATABASE_PORT   27017
+ENV OSMLCM_DATABASE_URI    mongodb://mongo:27017
+#ENV OSMLCM_DATABASE_HOST    mongo
+#ENV OSMLCM_DATABASE_PORT    27017
+
+
 ENV OSMLCM_STORAGE_DRIVER  local
 ENV OSMLCM_STORAGE_PATH    /app/storage
 
index 5b9da33..c276000 100644 (file)
@@ -30,28 +30,38 @@ RUN apt-get --yes update \
  && apt-get --yes install git python python-pip python3 python3-pip libmysqlclient-dev libssl-dev libffi-dev \
  && pip3 install pip==9.0.3
 
+RUN pip3 install  'macaroonbakery>=1.1,<2.0' 'pyRFC3339>=1.0,<2.0' \
+      'pyyaml>=3.0,<4.0' 'theblues>=0.3.8,<1.0' 'websockets>=4.0,<5.0' \
+      'paramiko'   # PyNaCl
+
 ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian
 ARG RELEASE=ReleaseFOUR-daily
 ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg
 ARG REPOSITORY=testing
 
 RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add -
-RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} MON common" && apt update
+RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} MON N2VC common" && apt update
 
 ARG MON_VERSION
 ARG COMMON_VERSION
+ARG N2VC_VERSION
 
-RUN apt-get --yes update  && apt-get -y install python3-osm-common${COMMON_VERSION} python3-osm-mon${MON_VERSION}
+RUN apt-get --yes update  && apt-get -y install python3-osm-common${COMMON_VERSION} python3-osm-mon${MON_VERSION} python3-n2vc${N2VC_VERSION}
 
 COPY scripts/ scripts/
 
 ENV BROKER_URI kafka:9092
-ENV MONGO_URI mongo:27017
+ENV MONGO_URI mongodb://mongo:27017
 ENV DATABASE sqlite:///mon_sqlite.db
 ENV OS_NOTIFIER_URI localhost:8662
 ENV OS_DEFAULT_GRANULARITY 300
 ENV REQUEST_TIMEOUT 10
+ENV OSMMON_LOG_LEVEL INFO
+ENV OSMMON_KAFKA_LOG_LEVEL INFO
+ENV OSMMON_VCA_HOST localhost
+ENV OSMMON_VCA_SECRET secret
+ENV OSMMON_VCA_USER admin
 
-EXPOSE 8662
+EXPOSE 8662 8000
 
 CMD /bin/bash scripts/runInstall.sh
index 236aa3d..b3228b6 100755 (executable)
@@ -20,7 +20,6 @@
 # For those usages not covered by the Apache License, Version 2.0 please
 # contact: bdiaz@whitestack.com or glavado@whitestack.com
 ##
-/bin/bash /mon/osm_mon/plugins/vRealiseOps/vROPs_Webservice/install.sh
-python3 /usr/lib/python3/dist-packages/osm_mon/plugins/OpenStack/Aodh/notifier.py &
-python3 ./usr/lib/python3/dist-packages/osm_mon/core/message_bus/common_consumer.py
-
+osm-mon-server &
+osm-mon-evaluator &
+osm-mon-collector
index d2d0c36..04a9acd 100644 (file)
@@ -51,8 +51,10 @@ ENV OSMNBI_SOCKET_PORT     9999
 ENV OSMNBI_STORAGE_PATH    /app/storage
 # database
 ENV OSMNBI_DATABASE_DRIVER mongo
-ENV OSMNBI_DATABASE_HOST   mongo
-ENV OSMNBI_DATABASE_PORT   27017
+ENV OSMNBI_DATABASE_URI   mongodb://mongo:27017
+#ENV OSMNBI_DATABASE_HOST   mongo
+#ENV OSMNBI_DATABASE_PORT   27017
+
 # web
 ENV OSMNBI_STATIC_DIR      /app/osm_nbi/html_public
 # logs
index f5ce057..1eb8634 100644 (file)
@@ -52,8 +52,7 @@ ENV OSMPOL_MESSAGE_HOST kafka
 ENV OSMPOL_MESSAGE_PORT 9092
 
 ENV OSMPOL_DATABASE_DRIVER mongo
-ENV OSMPOL_DATABASE_HOST mongo
-ENV OSMPOL_DATABASE_PORT 27017
+ENV OSMPOL_DATABASE_URI mongodb://mongo:27017
 
 ENV OSMPOL_SQL_DATABASE_URI sqlite:///mon_sqlite.db
 
index 61feaef..907253e 100644 (file)
@@ -54,7 +54,7 @@ fields:
 output.elasticsearch:
   hosts: ["elasticsearch:9200"]
 
-logging.level: debug
+logging.level: info
 logging.to_files: true
 logging.files:
   path: /var/log/metricbeat
index cb9ca06..415a7cd 100644 (file)
@@ -54,7 +54,7 @@
       "steppedLine": false,
       "targets": [
         {
-          "expr": "cpu_utilization",
+          "expr": "osm_cpu_utilization",
           "format": "time_series",
           "interval": "",
           "intervalFactor": 1,
       "steppedLine": false,
       "targets": [
         {
-          "expr": "average_memory_utilization",
+          "expr": "osm_average_memory_utilization",
           "format": "time_series",
           "interval": "",
           "intervalFactor": 1,
       "steppedLine": false,
       "targets": [
         {
-          "expr": "load",
+          "expr": "osm_load",
           "format": "time_series",
           "interval": "",
           "intervalFactor": 1,
       "steppedLine": false,
       "targets": [
         {
-          "expr": "users",
+          "expr": "osm_users",
           "format": "time_series",
           "interval": "",
           "intervalFactor": 1,
index fbfa12a..f67ba08 100755 (executable)
@@ -892,9 +892,10 @@ function deploy_lightweight() {
 
 function deploy_elk() {
     echo "Pulling docker images for ELK"
-    sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
-    sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
-    sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
+    sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:${ELASTIC_VERSION}" || FATAL "cannot get elasticsearch docker image"
+    sg docker -c "docker pull docker.elastic.co/beats/metricbeat:${ELASTIC_VERSION}" || FATAL "cannot get metricbeat docker image"
+    sg docker -c "docker pull docker.elastic.co/beats/filebeat:${ELASTIC_VERSION}" || FATAL "cannot get filebeat docker image"
+    sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:${ELASTIC_VERSION}" || FATAL "cannot get kibana docker image"
     echo "Finished pulling elk docker images"
     $WORKDIR_SUDO mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk"
     $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk
@@ -918,21 +919,21 @@ function deploy_elk() {
         echo "ELK is up and running. Trying to create index pattern..."
         #Create index pattern
         curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
-          "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
-          -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
+          "http://127.0.0.1:5601/api/saved_objects/index-pattern/filebeat-*" \
+          -d"{\"attributes\":{\"title\":\"filebeat-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
         #Make it the default index
         curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
           "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
-          -d"{\"value\":\"logstash-*\"}" 2>/dev/null
+          -d"{\"value\":\"filebeat-*\"}" 2>/dev/null
     else
         echo "Cannot connect to Kibana to create index pattern."
         echo "Once Kibana is running, you can use the following instructions to create index pattern:"
         echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
-          "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
-          -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
+          "http://127.0.0.1:5601/api/saved_objects/index-pattern/filebeat-*" \
+          -d"{\"attributes\":{\"title\":\"filebeat-*\",\"timeFieldName\":\"@timestamp\"}}"'
         echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
           "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
-          -d"{\"value\":\"logstash-*\"}"'
+          -d"{\"value\":\"filebeat-*\"}"'
     fi
     echo "Finished deployment of ELK stack"
     return 0
@@ -1143,6 +1144,7 @@ KAFKA_TAG=2.11-1.0.2
 PROMETHEUS_TAG=v2.4.3
 KEYSTONEDB_TAG=10
 OSM_DATABASE_COMMONKEY=
+ELASTIC_VERSION=6.4.2
 
 while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:w:t:" o; do
     case "${o}" in
index 6d0d00e..47ab0e1 100644 (file)
@@ -225,6 +225,11 @@ node("${params.NODE}") {
                         release = "-R ${params.RELEASE}"
                     }
              
+                    if ( params.REPOSITORY_BASE )
+                    {
+                        repo_base_url = "-u ${params.REPOSITORY_BASE}"
+                    }
+             
                     sh """
                         export PATH=$PATH:/snap/bin
                         installers/full_install_osm.sh -y -s ${container_name} --test --nolxd --nodocker --nojuju --nohostports --nohostclient \
index 75ab556..a5b6303 100644 (file)
@@ -193,7 +193,7 @@ endif
 %.openstack: check_openstack_env
        $(Q)$(MAKE) $*
 
-%s.vcd: check_vcd_env
+%.vcd: check_vcd_env
        $(Q)$(MAKE) $*
 
 cirros: check_OSM_HOSTNAME \
index f3d1753..0ac9525 100644 (file)
@@ -23,4 +23,7 @@ class Vim():
         try:
             osm.get_api().vim.get(self.vim_name)
         except ClientException:
-            osm.get_api().vim.create(self.vim_name,openstack.get_access())
+            if vmware._os_access['vim-url'] and vmware._os_access['vim-type'] == 'vmware':
+                osm.get_api().vim.create(self.vim_name,vmware.get_access())
+            else:
+                osm.get_api().vim.create(self.vim_name,openstack.get_access())
index 4737415..4f3f0e7 100755 (executable)
 ##
 
 
-from pyvcloud.vcloudair import VCA
-from pyvcloud import Http
 from xml.etree import ElementTree as XmlElementTree
-from pyvcloud.schema.vcd.v1_5.schemas.vcloud import mediaType
+from pyvcloud.vcd.client import BasicLoginCredentials,Client
+from pyvcloud.vcd.vdc import VDC
+from pyvcloud.vcd.org import Org
 import sys,os
 import logging
 import requests
 import time
 import re
+import hashlib
+from progressbar import Percentage, Bar, ETA, FileTransferSpeed, ProgressBar
 
 
-STANDALONE = 'standalone'
-VCAVERSION = '5.9'
+API_VERSION = '5.6'
 
 class vCloudconfig(object):
     def __init__(self, host=None, user=None, password=None,orgname=None, logger=None):
@@ -42,7 +43,8 @@ class vCloudconfig(object):
         self.user = user
         self.password = password
         self.org = orgname
-        self.logger = logger
+        self.logger = logging.getLogger('vmware_ovf_upload')
+        self.logger.setLevel(10)
 
     def connect(self):
         """ Method connect as normal user to vCloud director.
@@ -52,87 +54,164 @@ class vCloudconfig(object):
         """
 
         try:
-            self.logger.debug("Logging in to a vca {} as {} to datacenter {}.".format(self.org,
-                                                                                      self.user,
-                                                                                      self.org))
-            vca = VCA(host=self.url,
-                      username=self.user,
-                      service_type=STANDALONE,
-                      version=VCAVERSION,
-                      verify=False,
-                      log=False)
-
-            result = vca.login(password=self.password, org=self.org)
-            if not result:
-                raise vimconn.vimconnConnectionException("Can't connect to a vCloud director as: {}".format(self.user))
-            result = vca.login(token=vca.token, org=self.org, org_url=vca.vcloud_session.org_url)
-            if result is True:
-                self.logger.info(
-                    "Successfully logged to a vcloud direct org: {} as user: {}".format(self.org, self.user))
-
+            self.logger.debug("Logging in to a vcd {} as user {}".format(self.org,
+                                                                       self.user))
+            client = Client(self.url, verify_ssl_certs=False)
+            client.set_credentials(BasicLoginCredentials(self.user, self.org, self.password))
         except:
-            raise vimconn.vimconnConnectionException("Can't connect to a vCloud director org: "
+            raise Exception("Can't connect to a vCloud director org: "
                                                      "{} as user: {}".format(self.org, self.user))
 
-        return vca
+        return client
+
+    def get_catalog_id_from_path(self, catalog_name=None, path=None, progress=False):
+        """
+        Args
+            catalog - catalog name to be created
+            path: - valid path to OVF file.
+            progress - boolean progress bar show progress bar.
+
+        Return: if image uploaded correct method will provide image catalog UUID.
+        """
+        if not path:
+            raise Exception("Image path can't be None.")
+
+        if not os.path.isfile(path):
+            raise Exception("Can't read file. File not found.")
+
+        if not os.access(path, os.R_OK):
+            raise Exception("Can't read file. Check file permission to read.")
+
+        self.logger.debug("get_catalog_id_from_path() client requesting {} ".format(path))
 
-    def upload_ovf(self, catalog_name=None, image_name=None, media_file_name=None,
+        dirpath, filename = os.path.split(path)
+        flname, file_extension = os.path.splitext(path)
+        if file_extension != '.ovf':
+            self.logger.debug("Wrong file extension {} connector support only OVF container.".format(file_extension))
+            raise Exception("Wrong container.  vCloud director supports only OVF.")
+
+        self.logger.debug("File name {} Catalog Name {} file path {} ".format(filename,
+                                                                          catalog_name,
+                                                                                 path))
+        try:
+            client = self.connect()
+            if not client:
+                raise Exception("Failed to connect vCD") 
+            org = Org(client, resource=client.get_org())
+            catalogs = org.list_catalogs()
+        except Exception as exp:
+            self.logger.debug("Failed get catalogs() with Exception {} ".format(exp))
+            raise Exception("Failed get catalogs() with Exception {} ".format(exp))
+
+        if len(catalogs) == 0:
+            self.logger.info("Creating a new catalog entry {} in vcloud director".format(catalog_name))
+            result = org.create_catalog(catalog_name, catalog_name)
+            if result is None:
+                raise Exception("Failed to create new catalog {} ".format(catalog_name))
+            result = self.upload_ovf(org=org, catalog_name=catalog_name, image_name=filename.split(".")[0],
+                               media_file_name=path, description='medial_file_name', progress=progress)
+            if not result:
+                raise Exception("Failed to create vApp template for catalog {} ".format(catalog_name))
+            return self.get_catalogid(catalog_name, catalogs)
+        else:
+            for catalog in catalogs:
+                # search for existing catalog if we find same name we return ID
+                if catalog['name'] == catalog_name:
+                    self.logger.debug("Found existing catalog entry for {} "
+                                        "catalog id {}".format(catalog_name,
+                                  self.get_catalogid(catalog_name, catalogs)))
+                    return self.get_catalogid(catalog_name, catalogs)
+
+        # if we didn't find existing catalog we create a new one and upload image.
+        self.logger.debug("Creating new catalog entry {} - {}".format(catalog_name, catalog_name))
+        result = org.create_catalog(catalog_name, catalog_name) 
+        if result is None:
+            raise Exception("Failed to create new catalog {} ".format(catalog_name))
+
+        result = self.upload_ovf(org=org, catalog_name=catalog_name, image_name=filename.split(".")[0],
+                               media_file_name=path, description='medial_file_name', progress=progress)
+        if not result:
+            raise Exception("Failed create vApp template for catalog {} ".format(catalog_name))
+
+    def get_catalogid(self, catalog_name=None, catalogs=None):
+        """  Method check catalog and return catalog ID in UUID format.
+
+        Args
+            catalog_name: catalog name as string
+            catalogs:  list of catalogs.
+
+        Return: catalogs uuid
+        """
+
+        for catalog in catalogs:
+            if catalog['name'] == catalog_name:
+                catalog_id = catalog['id']
+                return catalog_id
+        return None
+
+    def upload_ovf(self, org=None, catalog_name=None, image_name=None, media_file_name=None,
                    description='', progress=False, chunk_bytes=128 * 1024):
         """
         Uploads a OVF file to a vCloud catalog
 
+        org : organization object
         catalog_name: (str): The name of the catalog to upload the media.
         media_file_name: (str): The name of the local media file to upload.
         return: (bool) True if the media file was successfully uploaded, false otherwise.
         """
-        vca = self.connect()   
-
-        # Creating new catalog in vCD
-        task = vca.create_catalog(catalog_name, catalog_name)
-        result = vca.block_until_completed(task)
-        if not result:
-            return False
+        client = self.connect()
+        if not client:
+            raise Exception("Failed to connect vCD!")
 
         os.path.isfile(media_file_name)
         statinfo = os.stat(media_file_name)
 
-
         #  find a catalog entry where we upload OVF.
         #  create vApp Template and check the status if vCD able to read OVF it will respond with appropirate
         #  status change.
         #  if VCD can parse OVF we upload VMDK file
         try:
-            for catalog in vca.get_catalogs():
-                if catalog_name != catalog.name:
+            for catalog in org.list_catalogs():
+                if catalog_name != catalog['name']:
                     continue
-                link = filter(lambda link: link.get_type() == "application/vnd.vmware.vcloud.media+xml" and
-                                           link.get_rel() == 'add', catalog.get_Link())
-                assert len(link) == 1
+                catalog_href = "{}/api/catalog/{}/action/upload".format(self.url, catalog['id'])
                 data = """
                 <UploadVAppTemplateParams name="{}" xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"><Description>{} vApp Template</Description></UploadVAppTemplateParams>
-                """.format(catalog_name, catalog_name)
-                headers = vca.vcloud_session.get_vcloud_headers()
-                headers['Content-Type'] = 'application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml'
-                response = Http.post(link[0].get_href(), headers=headers, data=data, verify=vca.verify, logger=self.logger)
+                """.format(catalog_name, description)
+
+                if client:
+                    headers = {'Accept':'application/*+xml;version=' + API_VERSION,
+                           'x-vcloud-authorization': client._session.headers['x-vcloud-authorization']}
+                    headers['Content-Type'] = 'application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml'
+
+                response = requests.post(url=catalog_href,
+                                          headers=headers,
+                                                data=data,
+                                             verify=False)
+                if response.status_code != 201:
+                    self.logger.debug("Failed to create vApp template")
+                    raise Exception("Failed to create vApp template")   
+
                 if response.status_code == requests.codes.created:
                     catalogItem = XmlElementTree.fromstring(response.content)
                     entity = [child for child in catalogItem if
                               child.get("type") == "application/vnd.vmware.vcloud.vAppTemplate+xml"][0]
                     href = entity.get('href')
                     template = href
-                    response = Http.get(href, headers=vca.vcloud_session.get_vcloud_headers(),
-                                        verify=vca.verify, logger=self.logger)
 
+                    response = requests.get(url=href,
+                                    headers=headers,
+                                       verify=False)
                     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]
-                        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,
-                                            verify=vca.verify, logger=self.logger)
+                        result = re.search('rel="upload:default"\shref="(.*?\/descriptor.ovf)"',response.content)
+                        if result:
+                            transfer_href = result.group(1)
+
+                        response = requests.put(url=transfer_href, headers=headers,
+                                        data=open(media_file_name, 'rb'),
+                                                            verify=False)
+
                         if response.status_code != requests.codes.ok:
                             self.logger.debug(
                                 "Failed create vApp template for catalog name {} and image {}".format(catalog_name,
@@ -146,80 +225,72 @@ class vCloudconfig(object):
 
                     # uploading VMDK file
                     # check status of OVF upload and upload remaining files.
-                    response = Http.get(template,
-                                        headers=vca.vcloud_session.get_vcloud_headers(),
-                                        verify=vca.verify,
-                                        logger=self.logger)
+
+                    response = requests.get(url=template,
+                                         headers=headers,
+                                            verify=False)
 
                     if response.status_code == requests.codes.ok:
-                        media = mediaType.parseString(response.content, True)
-                        number_of_files = len(media.get_Files().get_File())
-                        for index in xrange(0, number_of_files):
-                            links_list = filter(lambda link: link.get_rel() == 'upload:default',
-                                                media.get_Files().get_File()[index].get_Link())
-                            for link in links_list:
-                                # we skip ovf since it already uploaded.
-                                if 'ovf' in link.get_href():
-                                    continue
-                                # The OVF file and VMDK must be in a same directory
-                                head, tail = os.path.split(media_file_name)
-                                file_vmdk = head + '/' + link.get_href().split("/")[-1]
-                                if not os.path.isfile(file_vmdk):
-                                    return False
-                                statinfo = os.stat(file_vmdk)
-                                if statinfo.st_size == 0:
+                        result = re.search('rel="upload:default"\s*href="(.*?vmdk)"',response.content)
+                        if result:
+                            link_href = result.group(1)
+                        # we skip ovf since it already uploaded.
+                        if 'ovf' in link_href:
+                            continue
+                        # The OVF file and VMDK must be in a same directory
+                        head, tail = os.path.split(media_file_name)
+                        file_vmdk = head + '/' + link_href.split("/")[-1]
+                        if not os.path.isfile(file_vmdk):
+                            return False
+                        statinfo = os.stat(file_vmdk)
+                        if statinfo.st_size == 0:
+                            return False
+                        hrefvmdk = link_href
+                        if progress:
+                            widgets = ['Uploading file: ', Percentage(), ' ', Bar(), ' ', ETA(), ' ',
+                                           FileTransferSpeed()]
+                            progress_bar = ProgressBar(widgets=widgets, maxval=statinfo.st_size).start()
+
+                        bytes_transferred = 0
+                        f = open(file_vmdk, 'rb')
+                        while bytes_transferred < statinfo.st_size:
+                            my_bytes = f.read(chunk_bytes)
+                            if len(my_bytes) <= chunk_bytes:
+                                headers['Content-Range'] = 'bytes %s-%s/%s' % (
+                                    bytes_transferred, len(my_bytes) - 1, statinfo.st_size)
+                                headers['Content-Length'] = str(len(my_bytes))
+                                response = requests.put(url=hrefvmdk,
+                                                         headers=headers,
+                                                         data=my_bytes,
+                                                         verify=False)
+                                if response.status_code == requests.codes.ok:
+                                    bytes_transferred += len(my_bytes)
+                                    if progress:
+                                        progress_bar.update(bytes_transferred)
+                                else:
+                                    self.logger.debug(
+                                        'file upload failed with error: [%s] %s' % (response.status_code,
+                                                                                        response.content))
+
+                                    f.close()
                                     return False
-                                hrefvmdk = link.get_href()
-
-                                if progress:
-                                    print("Uploading file: {}".format(file_vmdk))
-                                if progress:
-                                    widgets = ['Uploading file: ', Percentage(), ' ', Bar(), ' ', ETA(), ' ',
-                                               FileTransferSpeed()]
-                                    progress_bar = ProgressBar(widgets=widgets, maxval=statinfo.st_size).start()
-
-                                bytes_transferred = 0
-                                f = open(file_vmdk, 'rb')
-                                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)
-                                            if progress:
-                                                progress_bar.update(bytes_transferred)
-                                        else:
-                                            self.logger.debug(
-                                                'file upload failed with error: [%s] %s' % (response.status_code,
-                                                                                            response.content))
-
-                                            f.close()
-                                            return False
-                                f.close()
-                                if progress:
-                                    progress_bar.finish()
-                                time.sleep(15)
-                        self.logger.debug("OVF image sucessfully uploaded to the VMware vCloud Director")
-                        return True
-                    else:
-                        self.logger.debug("Failed retrieve vApp template for catalog name {} for OVF {}".
-                                          format(catalog_name, media_file_name))
-                        return False
+                        f.close()
+                        if progress:
+                            progress_bar.finish()
+                            time.sleep(60)
+                    return True
+                else:
+                    self.logger.debug("Failed retrieve vApp template for catalog name {} for OVF {}".
+                                      format(catalog_name, media_file_name))
+                    return False 
         except Exception as exp:
             self.logger.debug("Failed while uploading OVF to catalog {} for OVF file {} with Exception {}"
                 .format(catalog_name,media_file_name, exp))
-            raise Exception("Failed while uploading OVF to catalog {} for OVF file {} with Exception {}" \
-                .format(catalog_name,media_file_name, exp))
-
+            raise Exception(
+                "Failed while uploading OVF to catalog {} for OVF file {} with Exception {}"
+                .format(catalog_name,media_file_name, exp))  
+        self.logger.debug("Failed to retrieve catalog name {} for OVF file {}".format(catalog_name, media_file_name))
+        return False   
 
 if __name__ == "__main__":
 
@@ -255,10 +326,6 @@ if __name__ == "__main__":
     match = re.search("image:\s'(.*?)'\n",rh.read())
     if match: catalog = match.group(1)
 
-
     if file_extension == '.ovf':
-        result = obj.upload_ovf(catalog_name=catalog, image_name='linux',
-                                                media_file_name=ovf_file_path,
-                                               description='', progress=False,
-                                                       chunk_bytes=128 * 1024)
-    
+        obj.get_catalog_id_from_path(catalog_name=catalog, path=ovf_file_path,
+                                                               progress=True)