def handle_update(self, json_snippet, tmpl_diff, prop_diff): try: si_obj = self.vnc_lib().service_instance_read(id=self.resource_id) except vnc_api.NoIdError: LOG.warn(_("Service Instance %s not found.") % self.name) raise except: LOG.warn(_("Unknown error.")) raise si_prop = si_obj.get_service_instance_properties() scaleprop = prop_diff.get(self.SCALE_OUT) if scaleprop: max_instances = scaleprop.get(self.MAX_INSTANCES) auto_scale = scaleprop.get(self.AUTO_SCALE) scale_out = vnc_api.ServiceScaleOutType(max_instances=max_instances, auto_scale=auto_scale) si_prop.set_scale_out(scale_out) # allowed address pairs aapsprop = prop_diff.get(self.INTERFACE_LIST) if aapsprop: for intf in aapsprop: aaps = self._set_allowed_address_pairs(intf) if_type = vnc_api.ServiceInstanceInterfaceType( allowed_address_pairs=aaps) si_prop.add_interface_list(if_type) si_obj.set_service_instance_properties(si_prop) self.vnc_lib().service_instance_update(si_obj)
def _svc_instance_neutron_to_vnc(self, si_q): from neutron_plugin_contrail.plugins.opencontrail.vnc_client.vn_res_handler import VNetworkHandler project_id = self._project_id_neutron_to_vnc(si_q['tenant_id']) try: project_obj = self._project_read(proj_id=project_id) except vnc_exc.NoIdError: raise self._raise_contrail_exception('ProjectNotFound', project_id=project_id, resource='svc_instance') net_id = si_q['external_net'] ext_vn = VNetworkHandler(self._vnc_lib).get_vn_obj(id=net_id) scale_out = vnc_api.ServiceScaleOutType(max_instances=1, auto_scale=False) si_prop = vnc_api.ServiceInstanceType( auto_policy=True, left_virtual_network="", right_virtual_network=ext_vn.get_fq_name_str(), scale_out=scale_out) si_prop.set_scale_out(scale_out) si_vnc = vnc_api.ServiceInstance(name=si_q['name'], parent_obj=project_obj, service_instance_properties=si_prop) return si_vnc
def create_ServiceInstance(vnc, project, service_template): """ FUNCTION TO CREATE SERVICE-INSTANCE """ instance = vnc_api.ServiceInstance(name='service_nat_instance', parent_obj=project) instance_properties = vnc_api.ServiceInstanceType( scale_out=vnc_api.ServiceScaleOutType()) instance.set_service_instance_properties(instance_properties) instance.set_service_template(service_template) vnc.service_instance_create(instance)
def handle_update(self, json_snippet, tmpl_diff, prop_diff): try: si_obj = self.vnc_lib().service_instance_read(id=self.resource_id) except vnc_api.NoIdError: LOG.warn(_("Service Instance %s not found.") % self.name) raise except: LOG.warn(_("Unknown error.")) raise si_prop = si_obj.get_service_instance_properties() scaleprop = prop_diff.get(self.SCALE_OUT) if scaleprop: max_instances = scaleprop.get(self.MAX_INSTANCES) auto_scale = scaleprop.get(self.AUTO_SCALE) scale_out = vnc_api.ServiceScaleOutType(max_instances=max_instances, auto_scale=auto_scale) si_prop.set_scale_out(scale_out) si_obj.set_service_instance_properties(si_prop) self.vnc_lib().service_instance_update(si_obj)
def handle_create(self): try: st_obj = self.vnc_lib().service_template_read( id=self.properties[self.SERVICE_TEMPLATE]) except vnc_api.NoIdError: st_obj = self.vnc_lib().service_template_read( fq_name_str=self.properties[self.SERVICE_TEMPLATE]) tenant_id = self.stack.context.tenant_id project_obj = self.vnc_lib().project_read(id=str(uuid.UUID(tenant_id))) si_obj = vnc_api.ServiceInstance( name=self.properties[self.NAME], parent_obj=project_obj) svc_tmpl_if_list = st_obj.get_service_template_properties().interface_type svc_inst_if_list = self.properties[self.INTERFACE_LIST] if len(svc_tmpl_if_list) != len(svc_inst_if_list): raise vnc_api.BadRequest if_index = 0 si_prop = vnc_api.ServiceInstanceType() for intf in self.properties[self.INTERFACE_LIST]: virt_net = intf[self.VIRTUAL_NETWORK] if virt_net == "auto": vn_name = "" elif not ":" in virt_net: fq_name = self.vnc_lib().id_to_fq_name(virt_net) vn_name = ":".join(fq_name) else: vn_name = virt_net # now check for static routes on this interface routes_list = {} if svc_tmpl_if_list[if_index].get_static_route_enable( ) and self.STATIC_ROUTES in intf: routes_list['route'] = intf[self.STATIC_ROUTES] if_type = vnc_api.ServiceInstanceInterfaceType( virtual_network=vn_name,static_routes=routes_list or None) si_prop.add_interface_list(if_type) if_index = if_index + 1 if self.properties[self.SCALE_OUT] is None: max_instances = 1 auto_scale = False else: max_instances = self.properties[self.SCALE_OUT][self.MAX_INSTANCES] auto_scale = self.properties[self.SCALE_OUT][self.AUTO_SCALE] scale_out = vnc_api.ServiceScaleOutType(max_instances=max_instances, auto_scale=auto_scale) si_prop.set_scale_out(scale_out) si_prop.set_availability_zone(self.properties[self.AVAILABILITY_ZONE]) si_prop.set_ha_mode(self.properties[self.HA_MODE]) si_obj.set_service_instance_properties(si_prop) st_obj = self.vnc_lib().service_template_read(id=st_obj.uuid) si_obj.set_service_template(st_obj) si_uuid = self.vnc_lib().service_instance_create(si_obj) self.resource_id_set(si_uuid)