def _delete_svc_instance(self, vm_uuid, proj_name, si_fq_str=None, virt_type=None): self.logger.log("Deleting VM %s %s" % (proj_name, vm_uuid)) try: if virt_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm_uuid, proj_name) elif virt_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm_uuid) except KeyError: self.db.cleanup_table_remove(vm_uuid) return # remove from launch table and queue into cleanup list self.db.virtual_machine_remove(vm_uuid) self.db.cleanup_table_insert(vm_uuid, { 'proj_name': proj_name, 'type': virt_type }) self.logger.uve_svc_instance(si_fq_str, status='DELETE', vm_uuid=vm_uuid)
def delete_service_instance(self, vm): self.logger.info("Deleting VM %s %s for SI %s" % ((':').join(vm.fq_name), vm.uuid, vm.service_id)) try: if vm.virtualization_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm) elif vm.virtualization_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm) elif vm.virtualization_type == 'vrouter-instance': self.vrouter_manager.delete_service(vm) elif vm.virtualization_type == 'physical-device': self.ps_manager.delete_service(vm) self.logger.info("Deleted VM %s %s for SI %s" % ((':').join(vm.fq_name), vm.uuid, vm.service_id)) except Exception: cgitb_error_log(self) # generate UVE si_fq_name = vm.display_name.split('__')[:-2] si_fq_str = (':').join(si_fq_name) self.logger.uve_svc_instance(si_fq_str, status='DELETE', vms=[{ 'uuid': vm.uuid }]) return True
def cleanup_callback(monitor): delete_list = monitor.db.cleanup_table_list() if not delete_list: return for uuid, info in delete_list or []: if info["type"] == svc_info.get_vm_instance_type() or info["type"] == svc_info.get_netns_instance_type(): monitor._delete_svc_instance(uuid, info["proj_name"], virt_type=info["type"]) elif info["type"] == "vn": monitor._delete_shared_vn(uuid, info["proj_name"])
def cleanup_callback(monitor): delete_list = monitor.db.cleanup_table_list() if not delete_list: return for uuid, info in delete_list or []: if info['type'] == svc_info.get_vm_instance_type() or \ info['type'] == svc_info.get_netns_instance_type(): monitor._delete_svc_instance(uuid, info['proj_name'], virt_type=info['type']) elif info['type'] == 'vn': monitor._delete_shared_vn(uuid, info['proj_name'])
def _delete_svc_instance(self, vm_uuid, proj_name, si_fq_str=None, virt_type=None): self.logger.log("Deleting VM %s %s" % (proj_name, vm_uuid)) try: if virt_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm_uuid, proj_name) elif virt_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm_uuid) except KeyError: return True # generate UVE self.logger.uve_svc_instance(si_fq_str, status='DELETE', vms=[{'uuid': vm_uuid}]) return False
def _delete_svc_instance(self, vm_uuid, proj_name, si_fq_str=None, virt_type=None): self.logger.log("Deleting VM %s %s" % (proj_name, vm_uuid)) try: if virt_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm_uuid, proj_name) elif virt_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm_uuid) except KeyError: self.db.cleanup_table_remove(vm_uuid) return # remove from launch table and queue into cleanup list self.db.virtual_machine_remove(vm_uuid) self.db.cleanup_table_insert(vm_uuid, {"proj_name": proj_name, "type": virt_type}) self.logger.uve_svc_instance(si_fq_str, status="DELETE", vm_uuid=vm_uuid)
def _delete_service_instance(self, vm): self.logger.log_info("Deleting VM %s %s" % ((':').join(vm.proj_fq_name), vm.uuid)) if vm.virtualization_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm) elif vm.virtualization_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm) elif vm.virtualization_type == 'vrouter-instance': self.vrouter_manager.delete_service(vm) # generate UVE si_fq_name = vm.display_name.split('__')[:-2] si_fq_str = (':').join(si_fq_name) self.logger.uve_svc_instance(si_fq_str, status='DELETE', vms=[{'uuid': vm.uuid}]) return True
def _delete_service_instance(self, vm): self.logger.log_info("Deleting VM %s %s" % ((":").join(vm.proj_fq_name), vm.uuid)) try: if vm.virtualization_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm) elif vm.virtualization_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm) elif vm.virtualization_type == "vrouter-instance": self.vrouter_manager.delete_service(vm) elif vm.virtualization_type == "physical-device": self.ps_manager.delete_service(vm) except Exception: cgitb_error_log(self) # generate UVE si_fq_name = vm.display_name.split("__")[:-2] si_fq_str = (":").join(si_fq_name) self.logger.uve_svc_instance(si_fq_str, status="DELETE", vms=[{"uuid": vm.uuid}]) return True
def delete_service_instance(self, vm): self.logger.info("Deleting VM %s %s for SI %s" % ((':').join(vm.fq_name), vm.uuid, vm.service_id)) try: if vm.virtualization_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(vm) elif vm.virtualization_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(vm) elif vm.virtualization_type == 'vrouter-instance': self.vrouter_manager.delete_service(vm) elif vm.virtualization_type == 'physical-device': self.ps_manager.delete_service(vm) self.logger.info("Deleted VM %s %s for SI %s" % ((':').join(vm.fq_name), vm.uuid, vm.service_id)) except Exception: cgitb_error_log(self) # generate UVE si_fq_name = vm.display_name.split('__')[:-2] si_fq_str = (':').join(si_fq_name) self.logger.uve_svc_instance(si_fq_str, status='DELETE', vms=[{'uuid': vm.uuid}]) return True
def _delete_svc_instance(self, vm_uuid, proj_name, si_fq_str=None, virt_type=None): self.logger.log("Deleting VM %s %s" % (proj_name, vm_uuid)) try: if virt_type == svc_info.get_vm_instance_type(): self.vm_manager.delete_service(si_fq_str, vm_uuid, proj_name) elif virt_type == svc_info.get_netns_instance_type(): self.netns_manager.delete_service(si_fq_str, vm_uuid) elif virt_type == 'vrouter-instance': self.vrouter_manager.delete_service(si_fq_str, vm_uuid) except KeyError: return True # generate UVE self.logger.uve_svc_instance(si_fq_str, status='DELETE', vms=[{ 'uuid': vm_uuid }]) return False
def create_service(self, st_obj, si_obj): si_props = si_obj.get_service_instance_properties() st_props = st_obj.get_service_template_properties() if st_props is None: self.logger.log("Cannot find service template associated to " "service instance %s" % si_obj.get_fq_name_str()) return # populate nic information nics = self._get_nic_info(si_obj, si_props, st_props) # set max instances local_prefs = None max_instances = 1 if si_props.get_ha_mode() == 'active-standby': max_instances = 2 local_prefs = self._get_local_prefs(si_obj, max_instances) elif si_props.get_scale_out(): max_instances = si_props.get_scale_out().get_max_instances() # Create virtual machines, associate them to the service instance and # schedule them to different virtual routers for inst_count in range(0, max_instances): # Create a virtual machine instance_name = self._get_instance_name(si_obj, inst_count) try: vm_obj = self._vnc_lib.virtual_machine_read(fq_name=[instance_name]) self.logger.log("Info: VM %s already exists" % (instance_name)) except NoIdError: vm_obj = VirtualMachine(instance_name) self._vnc_lib.virtual_machine_create(vm_obj) self.logger.log("Info: VM %s created" % (instance_name)) si_refs = vm_obj.get_service_instance_refs() if (si_refs is None) or (si_refs[0]['to'][0] == 'ERROR'): vm_obj.set_service_instance(si_obj) self._vnc_lib.virtual_machine_update(vm_obj) self.logger.log("Info: VM %s updated with SI %s" % (instance_name, si_obj.get_fq_name_str())) # Create virtual machine interfaces with an IP on networks row_entry = {} local_preference = None row_entry['local_preference'] = str(0) if local_prefs: local_preference = local_prefs[inst_count] row_entry['local_preference'] = str(local_preference) for nic in nics: user_visible = True if nic['type'] == svc_info.get_left_if_str(): user_visible = False if vmi_obj.get_virtual_machine_refs() is None: vmi_obj = self._create_svc_vm_port(nic, instance_name, st_obj, si_obj, int(local_preference), user_visible) vmi_obj.set_virtual_machine(vm_obj) self._vnc_lib.virtual_machine_interface_update(vmi_obj) self.logger.log("Info: VMI %s updated with VM %s" % (vmi_obj.get_fq_name_str(), instance_name)) # store NetNS instance in db use for linking when NetNS # is up. If the 'vrouter_name' key does not exist that means the # NetNS was not scheduled to a vrouter row_entry['si_fq_str'] = si_obj.get_fq_name_str() row_entry['instance_name'] = instance_name row_entry['instance_type'] = svc_info.get_netns_instance_type() # Associate instance on the scheduled vrouter chosen_vr_fq_name = None row_entry['vrouter_name'] = 'None' if vm_obj.get_virtual_router_back_refs() is None: chosen_vr_fq_name = self.vrouter_scheduler.schedule( si_obj.uuid, vm_obj.uuid) if chosen_vr_fq_name: row_entry['vrouter_name'] = chosen_vr_fq_name[-1] self.logger.log("Info: VRouter %s updated with VM %s" % (':'.join(chosen_vr_fq_name), instance_name)) self.db.virtual_machine_insert(vm_obj.uuid, row_entry) # uve trace if chosen_vr_fq_name: self.logger.uve_svc_instance(si_obj.get_fq_name_str(), status='CREATE', vm_uuid=vm_obj.uuid, st_name=st_obj.get_fq_name_str(), vr_name=':'.join(chosen_vr_fq_name)) else: self.logger.uve_svc_instance(si_obj.get_fq_name_str(), status='CREATE', vm_uuid=vm_obj.uuid, st_name=st_obj.get_fq_name_str())
def create_service(self, st_obj, si_obj): si_props = si_obj.get_service_instance_properties() st_props = st_obj.get_service_template_properties() if st_props is None: self.logger.log( "Cannot find service template associated to " "service instance %s" % si_obj.get_fq_name_str() ) return """TODO: add check for lb and snat. Need a new class to drive this if (st_props.get_service_type() != svc_info.get_snat_service_type()): self.logger.log("Only service type 'source-nat' is supported " "with 'network-namespace' service " "virtualization type") return """ # populate nic information nics = self._get_nic_info(si_obj, si_props, st_props) # Create virtual machines, associate them to the service instance and # schedule them to different virtual routers if si_props.get_scale_out(): max_instances = si_props.get_scale_out().get_max_instances() else: max_instances = 1 for inst_count in range(0, max_instances): # Create a virtual machine instance_name = si_obj.name + "_" + str(inst_count + 1) proj_fq_name = si_obj.get_parent_fq_name() vm_name = "__".join(proj_fq_name + [instance_name]) try: vm_obj = self._vnc_lib.virtual_machine_read(fq_name=[vm_name]) self.logger.log("Info: VM %s already exists" % (vm_name)) except NoIdError: vm_obj = VirtualMachine(vm_name) self._vnc_lib.virtual_machine_create(vm_obj) self.logger.log("Info: VM %s created" % (vm_name)) vm_obj.set_service_instance(si_obj) self._vnc_lib.virtual_machine_update(vm_obj) self.logger.log("Info: VM %s updated with SI %s" % (instance_name, si_obj.get_fq_name_str())) # Create virtual machine interfaces with an IP on networks for nic in nics: vmi_obj = self._create_svc_vm_port(nic, instance_name, st_obj, si_obj) vmi_obj.set_virtual_machine(vm_obj) self._vnc_lib.virtual_machine_interface_update(vmi_obj) self.logger.log("Info: VMI %s updated with VM %s" % (vmi_obj.get_fq_name_str(), instance_name)) # store NetNS instance in db use for linking when NetNS # is up. If the 'vrouter_name' key does not exist that means the # NetNS was not scheduled to a vrouter row_entry = {} row_entry["si_fq_str"] = si_obj.get_fq_name_str() row_entry["instance_name"] = instance_name row_entry["instance_type"] = svc_info.get_netns_instance_type() # Associate instance on the scheduled vrouter chosen_vr_fq_name = self.vrouter_scheduler.schedule(si_obj.uuid, vm_obj.uuid) if chosen_vr_fq_name: row_entry["vrouter_name"] = chosen_vr_fq_name[-1] self.logger.log("Info: VRouter %s updated with VM %s" % (":".join(chosen_vr_fq_name), instance_name)) self.db.virtual_machine_insert(vm_obj.uuid, row_entry) # uve trace if chosen_vr_fq_name: self.logger.uve_svc_instance( si_obj.get_fq_name_str(), status="CREATE", vm_uuid=vm_obj.uuid, st_name=st_obj.get_fq_name_str(), vr_name=":".join(chosen_vr_fq_name), ) else: self.logger.uve_svc_instance( si_obj.get_fq_name_str(), status="CREATE", vm_uuid=vm_obj.uuid, st_name=st_obj.get_fq_name_str() )
def create_service(self, st_obj, si_obj): si_props = si_obj.get_service_instance_properties() st_props = st_obj.get_service_template_properties() if st_props is None: self.logger.log("Cannot find service template associated to " "service instance %s" % si_obj.get_fq_name_str()) return '''TODO: add check for lb and snat. Need a new class to drive this if (st_props.get_service_type() != svc_info.get_snat_service_type()): self.logger.log("Only service type 'source-nat' is supported " "with 'network-namespace' service " "virtualization type") return ''' # populate nic information nics = self._get_nic_info(si_obj, si_props, st_props) # Create virtual machines, associate them to the service instance and # schedule them to different virtual routers if si_props.get_scale_out(): max_instances = si_props.get_scale_out().get_max_instances() else: max_instances = 1 for inst_count in range(0, max_instances): # Create a virtual machine instance_name = si_obj.name + '_' + str(inst_count + 1) proj_fq_name = si_obj.get_parent_fq_name() vm_name = "__".join(proj_fq_name + [instance_name]) try: vm_obj = self._vnc_lib.virtual_machine_read(fq_name=[vm_name]) self.logger.log("Info: VM %s already exists" % (vm_name)) except NoIdError: vm_obj = VirtualMachine(vm_name) self._vnc_lib.virtual_machine_create(vm_obj) self.logger.log("Info: VM %s created" % (vm_name)) vm_obj.set_service_instance(si_obj) self._vnc_lib.virtual_machine_update(vm_obj) self.logger.log("Info: VM %s updated with SI %s" % (instance_name, si_obj.get_fq_name_str())) # Create virtual machine interfaces with an IP on networks for nic in nics: vmi_obj = self._create_svc_vm_port(nic, instance_name, st_obj, si_obj) vmi_obj.set_virtual_machine(vm_obj) self._vnc_lib.virtual_machine_interface_update(vmi_obj) self.logger.log("Info: VMI %s updated with VM %s" % (vmi_obj.get_fq_name_str(), instance_name)) # store NetNS instance in db use for linking when NetNS # is up. If the 'vrouter_name' key does not exist that means the # NetNS was not scheduled to a vrouter row_entry = {} row_entry['si_fq_str'] = si_obj.get_fq_name_str() row_entry['instance_name'] = instance_name row_entry['instance_type'] = svc_info.get_netns_instance_type() # Associate instance on the scheduled vrouter chosen_vr_fq_name = self.vrouter_scheduler.schedule( si_obj.uuid, vm_obj.uuid) if chosen_vr_fq_name: row_entry['vrouter_name'] = chosen_vr_fq_name[-1] self.logger.log("Info: VRouter %s updated with VM %s" % (':'.join(chosen_vr_fq_name), instance_name)) self.db.virtual_machine_insert(vm_obj.uuid, row_entry) # uve trace if chosen_vr_fq_name: self.logger.uve_svc_instance( si_obj.get_fq_name_str(), status='CREATE', vm_uuid=vm_obj.uuid, st_name=st_obj.get_fq_name_str(), vr_name=':'.join(chosen_vr_fq_name)) else: self.logger.uve_svc_instance(si_obj.get_fq_name_str(), status='CREATE', vm_uuid=vm_obj.uuid, st_name=st_obj.get_fq_name_str())