Merge branch 'v1.1' 74/1074/1
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 7 Feb 2017 09:30:32 +0000 (10:30 +0100)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 7 Feb 2017 09:30:32 +0000 (10:30 +0100)
1  2 
httpserver.py
vimconn_openvim.py

diff --combined httpserver.py
@@@ -483,14 -483,14 +483,14 @@@ def http_get_datacenter_id(tenant_id, d
                      try:
                          config_dict = yaml.load(vim_tenant['config'])
                          vim_tenant['config'] = config_dict
 -                    except Exception, e:
 +                    except Exception as e:
                          logger.error("Exception '%s' while trying to load config information", str(e))
  
          if datacenter['config'] != None:
              try:
                  config_dict = yaml.load(datacenter['config'])
                  datacenter['config'] = config_dict
 -            except Exception, e:
 +            except Exception as e:
                  logger.error("Exception '%s' while trying to load config information", str(e))
          #change_keys_http2db(content, http2db_datacenter, reverse=True)
          convert_datetime2str(datacenter)
@@@ -996,14 -996,14 +996,14 @@@ def http_post_scenarios(tenant_id)
  def http_post_scenario_action(tenant_id, scenario_id):
      '''take an action over a scenario'''
      logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
-     #check valid tenant_id
+     # parse input data
+     http_content, _ = format_in(scenario_action_schema)
+     r = utils.remove_extra_items(http_content, scenario_action_schema)
+     if r:
+         logger.debug("Remove received extra items %s", str(r))
      try:
-         nfvo.check_tenant(mydb, tenant_id) 
-         #parse input data
-         http_content,_ = format_in( scenario_action_schema )
-         r = utils.remove_extra_items(http_content, scenario_action_schema)
-         if r:
-             logger.debug("Remove received extra items %s", str(r))
+         # check valid tenant_id
+         nfvo.check_tenant(mydb, tenant_id)
          if "start" in http_content:
              data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['start']['instance_name'], \
                          http_content['start'].get('description',http_content['start']['instance_name']),
@@@ -1086,10 -1086,11 +1086,11 @@@ def http_get_scenario_id(tenant_id, sce
  @bottle.route(url_base + '/<tenant_id>/scenarios/<scenario_id>', method='DELETE')
  def http_delete_scenario_id(tenant_id, scenario_id):
      '''delete a scenario from database, can use both uuid or name'''
+     logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
      try:
          #check valid tenant_id
          if tenant_id != "any":
-             nfvo.check_tenant(mydb, tenant_id) 
+             nfvo.check_tenant(mydb, tenant_id)
          #obtain data
          data = mydb.delete_scenario(scenario_id, tenant_id)
          #print json.dumps(data, indent=4)
@@@ -1126,15 -1127,15 +1127,15 @@@ def http_put_scenario_id(tenant_id, sce
  def http_post_instances(tenant_id):
      '''create an instance-scenario'''
      logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+     # parse input data
+     http_content, used_schema = format_in(instance_scenario_create_schema_v01)
+     r = utils.remove_extra_items(http_content, used_schema)
+     if r is not None:
+         logger.warning("http_post_instances: Warning: remove extra items %s", str(r))
      try:
          #check valid tenant_id
          if tenant_id != "any":
              nfvo.check_tenant(mydb, tenant_id) 
-         #parse input data
-         http_content,used_schema = format_in( instance_scenario_create_schema_v01)
-         r = utils.remove_extra_items(http_content, used_schema)
-         if r is not None:
-             logger.warning("http_post_instances: Warning: remove extra items %s", str(r))
          data = nfvo.create_instance(mydb, tenant_id, http_content["instance"])
          return format_out(data)
      except (nfvo.NfvoException, db_base_Exception) as e:
@@@ -1225,16 -1226,16 +1226,16 @@@ def http_delete_instance_id(tenant_id, 
  def http_post_instance_scenario_action(tenant_id, instance_id):
      '''take an action over a scenario instance'''
      logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+     # parse input data
+     http_content, _ = format_in(instance_scenario_action_schema)
+     r = utils.remove_extra_items(http_content, instance_scenario_action_schema)
+     if r:
+         logger.debug("Remove received extra items %s", str(r))
      try:
          #check valid tenant_id
          if tenant_id != "any":
              nfvo.check_tenant(mydb, tenant_id) 
  
-         #parse input data
-         http_content,_ = format_in( instance_scenario_action_schema )
-         r = utils.remove_extra_items(http_content, instance_scenario_action_schema)
-         if r:
-             logger.debug("Remove received extra items %s", str(r))
          #print "http_post_instance_scenario_action input: ", http_content
          #obtain data
          instance = mydb.get_instance_scenario(instance_id, tenant_id)
diff --combined vimconn_openvim.py
@@@ -377,7 -377,7 +377,7 @@@ class vimconnector(vimconn.vimconnector
              js_v(client_data, schema)
              #print "Input data: ", str(client_data)
              return True, client_data
 -        except js_e.ValidationError, exc:
 +        except js_e.ValidationError as exc:
              print "validate_in error, jsonschema exception ", exc.message, "at", exc.path
              return False, ("validate_in error, jsonschema exception ", exc.message, "at", exc.path)
      
          payload_req = vm_data
          try:
              vim_response = requests.post(self.url+'/'+self.tenant+'/servers', headers = self.headers_req, data=payload_req)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              print "new_vminstancefromJSON Exception: ", e.args
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print vim_response
                  #TODO ip, security groups
          Returns the instance identifier
          '''
+         self.logger.debug("new_vminstance input: image='%s' flavor='%s' nics='%s'", image_id, flavor_id, str(net_list))
          try:
              self._get_my_tenant()
  #            net_list = []
          url=self.url+'/hosts'
          try:
              vim_response = requests.get(url)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              print "get_hosts_info Exception: ", e.args
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
              url=self.url+'/hosts/'+host['id']
              try:
                  vim_response = requests.get(url)
 -            except requests.exceptions.RequestException, e:
 +            except requests.exceptions.RequestException as e:
                  print "get_hosts_info Exception: ", e.args
                  return -vimconn.HTTP_Not_Found, str(e.args[0])
              print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
          url=self.url+'/hosts'
          try:
              vim_response = requests.get(url)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              print "get_hosts Exception: ", e.args
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
              url=self.url+'/' + vim_tenant + '/servers?hostId='+host['id']
              try:
                  vim_response = requests.get(url)
 -            except requests.exceptions.RequestException, e:
 +            except requests.exceptions.RequestException as e:
                  print "get_hosts Exception: ", e.args
                  return -vimconn.HTTP_Not_Found, str(e.args[0])
              print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
          url=self.url+'/processor_ranking'
          try:
              vim_response = requests.get(url)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              print "get_processor_rankings Exception: ", e.args
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print "vim get", url, "response:", vim_response.status_code, vim_response.json()
          payload_req = port_data
          try:
              vim_response = requests.post(self.url_admin+'/ports', headers = self.headers_req, data=payload_req)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              self.logger.error("new_external_port Exception: ", str(e))
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print vim_response
          payload_req = '{"network":{"name": "' + net_name + '","shared":true,"type": "' + net_type + '"}}'
          try:
              vim_response = requests.post(self.url+'/networks', headers = self.headers_req, data=payload_req)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              self.logger.error( "new_external_network Exception: ", e.args)
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print vim_response
              url= self.url
          try:
              vim_response = requests.put(url +'/ports/'+port_id, headers = self.headers_req, data=payload_req)
 -        except requests.exceptions.RequestException, e:
 +        except requests.exceptions.RequestException as e:
              print "connect_port_network Exception: ", e.args
              return -vimconn.HTTP_Not_Found, str(e.args[0])
          print vim_response