Merge branch 'vio' into v2.0 25/2125/1
authorkate <akate@vmware.com>
Wed, 6 Sep 2017 06:26:28 +0000 (23:26 -0700)
committerkate <akate@vmware.com>
Wed, 6 Sep 2017 06:26:28 +0000 (23:26 -0700)
Change-Id: I380d554f9e9f03b0c4425fd998123fda300b81ff
Signed-off-by: kate <akate@vmware.com>
1  2 
osm_ro/vimconn_openstack.py

@@@ -35,7 -35,7 +35,8 @@@ import netadd
  import time
  import yaml
  import random
 +import sys
+ import re
  
  from novaclient import client as nClient, exceptions as nvExceptions
  from keystoneauth1.identity import v2, v3
@@@ -97,10 -102,22 +107,22 @@@ class vimconnector(vimconn.vimconnector
          self.glancev1 = self.session.get('glancev1')
          self.keystone = self.session.get('keystone')
          self.api_version3 = self.session.get('api_version3')
+         self.vim_type = self.config.get("vim_type")
+         if self.vim_type:
+             self.vim_type = self.vim_type.upper()
+         if self.config.get("use_internal_endpoint"):
+             self.endpoint_type = "internalURL"
+         else:
+             self.endpoint_type = None
  
          self.logger = logging.getLogger('openmano.vim.openstack')
+         ####### VIO Specific Changes #########
+         if self.vim_type == "VIO":
+             self.logger = logging.getLogger('openmano.vim.vio')
          if log_level:
-             self.logger.setLevel( getattr(logging, log_level) )
 -            self.logger.setLevel(getattr(logging, log_level))
++            self.logger.setLevel( getattr(logging, log_level))
  
      def __getitem__(self, index):
          """Get individuals parameters.
                                     tenant_id=self.tenant_id)
              sess = session.Session(auth=auth, verify=not self.insecure)
              if self.api_version3:
-                 self.keystone = ksClient_v3.Client(session=sess)
+                 self.keystone = ksClient_v3.Client(session=sess, endpoint_type=self.endpoint_type)
              else:
-                 self.keystone = ksClient_v2.Client(session=sess)
+                 self.keystone = ksClient_v2.Client(session=sess, endpoint_type=self.endpoint_type)
              self.session['keystone'] = self.keystone
 -            self.nova = self.session['nova'] = nClient.Client("2.1", session=sess, endpoint_type=self.endpoint_type)
 +            # In order to enable microversion functionality an explicit microversion must be specified in 'config'.
 +            # This implementation approach is due to the warning message in
 +            # https://developer.openstack.org/api-guide/compute/microversions.html
 +            # where it is stated that microversion backwards compatibility is not guaranteed and clients should
 +            # always require an specific microversion.
 +            # To be able to use 'device role tagging' functionality define 'microversion: 2.32' in datacenter config
 +            version = self.config.get("microversion")
 +            if not version:
 +                version = "2.1"
-             self.nova = self.session['nova'] = nClient.Client(str(version), session=sess)
-             self.neutron = self.session['neutron'] = neClient.Client('2.0', session=sess)
-             self.cinder = self.session['cinder'] = cClient.Client(2, session=sess)
-             self.glance = self.session['glance'] = glClient.Client(2, session=sess)
-             self.glancev1 = self.session['glancev1'] = glClient.Client('1', session=sess)
++            self.nova = self.session['nova'] = nClient.Client(str(version), session=sess, endpoint_type=self.endpoint_type)
+             self.neutron = self.session['neutron'] = neClient.Client('2.0', session=sess, endpoint_type=self.endpoint_type)
+             self.cinder = self.session['cinder'] = cClient.Client(2, session=sess, endpoint_type=self.endpoint_type)
+             if self.endpoint_type == "internalURL":
+                 glance_service_id = self.keystone.services.list(name="glance")[0].id
+                 glance_endpoint = self.keystone.endpoints.list(glance_service_id, interface="internal")[0].url
+             else:
+                 glance_endpoint = None
+             self.glance = self.session['glance'] = glClient.Client(2, session=sess, endpoint=glance_endpoint)
+             #using version 1 of glance client in new_image()
+             self.glancev1 = self.session['glancev1'] = glClient.Client('1', session=sess,
+                                                                        endpoint=glance_endpoint)
              self.session['reload_client'] = False
              self.persistent_info['session'] = self.session
 +            # add availablity zone info inside  self.persistent_info
 +            self._set_availablity_zones()
 +            self.persistent_info['availability_zone'] = self.availability_zone
  
      def __net_os2mano(self, net_list_dict):
          '''Transform the net openstack format to mano format
                              #     if interface["dedicated"]=="yes":
                              #         raise vimconn.vimconnException("Passthrough interfaces are not supported for the openstack connector", http_code=vimconn.HTTP_Service_Unavailable)
                              #     #TODO, add the key 'pci_passthrough:alias"="<label at config>:<number ifaces>"' when a way to connect it is available
 -
 -                #create flavor
 -                new_flavor=self.nova.flavors.create(name,
 -                                ram,
 -                                vcpus,
 +                                
 +                #create flavor                 
 +                new_flavor=self.nova.flavors.create(name, 
 +                                ram, 
 +                                vcpus, 
                                  flavor_data.get('disk',1),
                                  is_public=flavor_data.get('is_public', True)
-                             ) 
+                             )
                  #add metadata
                  if numa_properties:
                      new_flavor.set_keys(numa_properties)
          if self.debug:
              print "get_hosts " + error_text
          return error_value, error_text        
 +  
 +