def _create_default_service_appliance_set(self, sa_set_name, driver_name):
        default_gsc_name = "default-global-system-config"
        default_gsc_fq_name = [default_gsc_name]
        sa_set_fq_name = [default_gsc_name, sa_set_name]

        try:
            sa_set_obj = self._vnc_lib.service_appliance_set_read(fq_name=sa_set_fq_name)
        except vnc_exc.NoIdError:
            gsc_obj = self._vnc_lib.global_system_config_read(fq_name=default_gsc_fq_name)
            sa_set_obj = ServiceApplianceSet(sa_set_name, gsc_obj)
            sa_set_obj.set_service_appliance_driver(driver_name)
            sa_set_uuid = self._vnc_lib.service_appliance_set_create(sa_set_obj)
            ServiceApplianceSetSM.locate(sa_set_uuid)
    def _create_default_service_appliance_set(self, sa_set_name, driver_name):
        default_gsc_name = "default-global-system-config"
        default_gsc_fq_name = [default_gsc_name]
        sa_set_fq_name = [default_gsc_name, sa_set_name]

        try:
            sa_set_obj = self._vnc_lib.service_appliance_set_read(fq_name=sa_set_fq_name)
        except vnc_exc.NoIdError:
            gsc_obj = self._vnc_lib.global_system_config_read(fq_name=default_gsc_fq_name)
            sa_set_obj = ServiceApplianceSet(sa_set_name, gsc_obj)
            sa_set_obj.set_service_appliance_driver(driver_name)
            sa_set_uuid = self._vnc_lib.service_appliance_set_create(sa_set_obj)
            ServiceApplianceSetSM.locate(sa_set_uuid)
    def check_service(self, si):
        if si.max_instances>len(si.port_tuples):
            return False

        pt_list = list(si.port_tuples)
        pi_list = []
        all_possible_pi=[]

        for pt_uuid in pt_list:
            pt_obj = PortTupleSM.get(pt_uuid)
            for vmi_uuid in pt_obj.virtual_machine_interfaces:
                vmi_obj = VirtualMachineInterfaceSM.get(vmi_uuid)
                pi_list.append(vmi_obj.physical_interface)

        st_obj = ServiceTemplateSM.get(si.service_template)
        if not st_obj.service_appliance_set:
            return False

        sa_set_obj = ServiceApplianceSetSM.get(st_obj.service_appliance_set)
        for sa_uuid in sa_set_obj.service_appliances:
            sa_obj = ServiceApplianceSM.get(sa_uuid)
            for key in sa_obj.physical_interfaces:
                all_possible_pi.append(sa_obj.physical_interfaces[key])

        if not pi_list and all_possible_pi and si.max_instances>0:
            return False

        if not all_possible_pi and pi_list:
            return False

        for pi_uuid in pi_list:
            if not pi_uuid in all_possible_pi:
                return False

        return True
    def check_service(self, si):
        if si.max_instances > len(si.port_tuples):
            return False

        pt_list = list(si.port_tuples)
        pi_list = []
        all_possible_pi = []

        for pt_uuid in pt_list:
            pt_obj = PortTupleSM.get(pt_uuid)
            for vmi_uuid in pt_obj.virtual_machine_interfaces:
                vmi_obj = VirtualMachineInterfaceSM.get(vmi_uuid)
                pi_list.append(vmi_obj.physical_interface)

        st_obj = ServiceTemplateSM.get(si.service_template)
        if not st_obj.service_appliance_set:
            return False

        sa_set_obj = ServiceApplianceSetSM.get(st_obj.service_appliance_set)
        for sa_uuid in sa_set_obj.service_appliances:
            sa_obj = ServiceApplianceSM.get(sa_uuid)
            for key in sa_obj.physical_interfaces:
                all_possible_pi.append(sa_obj.physical_interfaces[key])

        if not pi_list and all_possible_pi and si.max_instances > 0:
            return False

        if not all_possible_pi and pi_list:
            return False

        for pi_uuid in pi_list:
            if not pi_uuid in all_possible_pi:
                return False

        return True
    def create_service(self, st, si):
        if not self.validate_network_config(st, si):
            return
        # if service already inited do nothing
        if self.check_service(si):
            return

        # get service appliances from service template
        if not st.service_appliance_set:
            self.logger.error("Can't find service appliances set")
            return
        sa_set_obj = ServiceApplianceSetSM.get(st.service_appliance_set)
        sa_list = list(sa_set_obj.service_appliances)

        # validation
        if not sa_list:
            self.logger.error("Can't find service appliances")
            return

        #clean all existed staff before create new
        self.clean_service(si)
        # create a fake VM for the schmea transfer to use
        vm_list = [None] * si.max_instances

        # get the port-tuple
        pt_list = [None] * si.max_instances
        if si.max_instances > len(sa_list):
            self.logger.info("There are not enough Service appliance \
                    for that Service instance " + si.uuid)
            return
        for idx, sa_uuid in enumerate(sa_list):
            if idx > si.max_instances:
                return

            vm_uuid = vm_list[idx]
            if not vm_uuid:
                vm_uuid = str(uuid.uuid4())
            vm_obj = self.link_si_to_vm(si, st, idx, vm_uuid)

            pt_uuid = pt_list[idx]
            if not pt_uuid:
                pt_uuid = str(uuid.uuid4())
            pt_obj = self.create_port_tuple(si, st, idx, pt_uuid)

            instance_name = self._get_instance_name(si, idx)
            si.state = 'launching'
            sa = ServiceApplianceSM.get(sa_uuid)
            for nic in si.vn_info:
                pi_uuid = sa.physical_interfaces.get(nic['type'], None)
                pi_obj = PhysicalInterfaceSM.get(pi_uuid)
                if not pi_obj:
                    return
                vmi_obj = self._create_svc_vm_port(nic,
                                                   instance_name,
                                                   si,
                                                   st,
                                                   vm_obj=vm_obj,
                                                   pi=pi_obj,
                                                   pt=pt_obj)
        si.state = "active"
    def create_service(self, st, si):
        if not self.validate_network_config(st, si):
            return
        # if service already inited do nothing
        if self.check_service(si):
            return

        # get service appliances from service template
        if not st.service_appliance_set:
            self.logger.error("Can't find service appliances set")
            return
        sa_set_obj = ServiceApplianceSetSM.get(st.service_appliance_set)
        sa_list = list(sa_set_obj.service_appliances)

        # validation
        if not sa_list:
            self.logger.error("Can't find service appliances")
            return

        #clean all existed staff before create new
        self.clean_service(si)
        # create a fake VM for the schmea transfer to use
        vm_list = [None]*si.max_instances

        # get the port-tuple
        pt_list = [None]*si.max_instances
        if si.max_instances > len(sa_list):
            self.logger.info(
                "There are not enough Service appliance \
                    for that Service instance "+si.uuid)
            return
        for idx, sa_uuid in enumerate(sa_list):
            if idx > si.max_instances:
                return

            vm_uuid = vm_list[idx]
            if not vm_uuid:
                vm_uuid = str(uuid.uuid4())
            vm_obj = self.link_si_to_vm(si, st, idx, vm_uuid)

            pt_uuid = pt_list[idx]
            if not pt_uuid:
                pt_uuid = str(uuid.uuid4())
            pt_obj = self.create_port_tuple(si, st, idx, pt_uuid)

            instance_name = self._get_instance_name(si, idx)
            si.state = 'launching'
            sa = ServiceApplianceSM.get(sa_uuid)
            for nic in si.vn_info:
                pi_uuid = sa.physical_interfaces.get(nic['type'], None)
                pi_obj = PhysicalInterfaceSM.get(pi_uuid)
                if not pi_obj:
                    return
                vmi_obj = self._create_svc_vm_port(nic,
                                                   instance_name, si, st,
                                                   vm_obj=vm_obj,
                                                   pi=pi_obj,
                                                   pt=pt_obj)
        si.state = "active"
Ejemplo n.º 7
0
    def create_service(self, st, si):
        if not self.validate_network_config(st, si):
            return
        # get service appliances from service template
        sa_set = st.service_appliance_set
        if not sa_set:
            self.logger.log_error("Can't find service appliances set")
            return
        service_appliance_set = ServiceApplianceSetSM.get(sa_set)
        service_appliances = service_appliance_set.service_appliances

        # validation
        if not service_appliances:
            self.logger.log_error("Can't find service appliances")
            return

        service_appliances = list(service_appliances)
        si_obj = ServiceInstanceSM.get(si.uuid)

        # create a fake VM for the schmea transfer to use
        vm_uuid_list = list(si_obj.virtual_machines)
        vm_list = [None] * si.max_instances
        for vm_uuid in vm_uuid_list:
            vm = VirtualMachineSM.get(vm_uuid)
            if not vm:
                continue
            if (vm.index + 1) > si.max_instances:
                self.delete_service(vm)
                continue
            vm_list[vm.index] = vm_uuid

        if si.max_instances > len(service_appliances):
            self.logger.log_info("There are not enough Service appliance \
                    for that Service instance " + si.uuid)
            return
        for idx, sa_uuid in enumerate(service_appliances):
            if idx > si.max_instances:
                return
            vm_uuid = vm_list[idx]
            if not vm_uuid:
                vm_uuid = str(uuid.uuid4())
            vm_obj = self.link_si_to_vm(si, st, idx, vm_uuid)
            instance_name = self._get_instance_name(si, idx)
            si.state = 'launching'
            sa = ServiceApplianceSM.get(sa_uuid)
            for nic in si.vn_info:
                pi_uuid = sa.physical_interfaces.get(nic['type'], None)
                pi_obj = PhysicalInterfaceSM.get(pi_uuid)
                if not pi_obj:
                    return
                vmi_obj = self._create_svc_vm_port(nic,
                                                   instance_name,
                                                   si,
                                                   st,
                                                   vm_obj=vm_obj,
                                                   pi=pi_obj,
                                                   instance_id=idx)
        si.state = "active"
    def create_service(self, st, si):
        if not self.validate_network_config(st, si):
            return
        # get service appliances from service template
        sa_set = st.service_appliance_set
        if not sa_set:
            self.logger.log_error("Can't find service appliances set")
            return
        service_appliance_set = ServiceApplianceSetSM.get(sa_set)
        service_appliances = service_appliance_set.service_appliances

        # validation
        if not service_appliances:
            self.logger.log_error("Can't find service appliances")
            return

        service_appliances = list(service_appliances)
        si_obj = ServiceInstanceSM.get(si.uuid)

        # create a fake VM for the schmea transfer to use
        vm_uuid_list = list(si_obj.virtual_machines)
        vm_list = [None]*si.max_instances
        for vm_uuid in vm_uuid_list:
            vm = VirtualMachineSM.get(vm_uuid)
            if not vm:
                continue
            if (vm.index + 1) > si.max_instances:
                self.delete_service(vm)
                continue
            vm_list[vm.index] = vm_uuid

        if si.max_instances > len(service_appliances):
            self.logger.log_info(
                "There are not enough Service appliance \
                    for that Service instance "+si.uuid)
            return
        for idx, sa_uuid in enumerate(service_appliances):
            if idx > si.max_instances:
                return
            vm_uuid = vm_list[idx]
            if not vm_uuid:
                vm_uuid = str(uuid.uuid4())
            vm_obj = self.link_si_to_vm(si, st, idx, vm_uuid)
            instance_name = self._get_instance_name(si, idx)
            si.state = 'launching'
            sa = ServiceApplianceSM.get(sa_uuid)
            for nic in si.vn_info:
                pi_uuid = sa.physical_interfaces.get(nic['type'],None)
                pi_obj = PhysicalInterfaceSM.get(pi_uuid)
                if not pi_obj:
                    return
                vmi_obj = self._create_svc_vm_port(nic,
                                                   instance_name, si, st,
                                                   vm_obj = vm_obj,
                                                   pi=pi_obj,
                                                   instance_id=idx)
        si.state = "active"
 def load_drivers(self):
     for sas in ServiceApplianceSetSM.values():
         if sas.driver:
             config = self._args.config_sections
             config.add_section(sas.name)
             for kvp in sas.kvpairs or []:
                 config.set(sas.name, kvp["key"], kvp["value"])
             if sas.ha_mode:
                 config.set(sas.name, "ha_mode", str(sas.ha_mode))
             for sa in sas.service_appliances or []:
                 saobj = ServiceApplianceSM.get(sa)
                 config.set(sas.name, "device_ip", saobj.ip_address)
                 config.set(sas.name, "user", saobj.user_credential["username"])
                 config.set(sas.name, "password", saobj.user_credential["password"])
             self._loadbalancer_driver[sas.name] = importutils.import_object(
                 sas.driver, sas.name, self._svc_mon, self._vnc_lib, self._cassandra, self._args
             )
 def load_drivers(self):
     for sas in ServiceApplianceSetSM.values():
         if sas.driver:
             config = self._args.config_sections
             config.add_section(sas.name)
             for kvp in sas.kvpairs or []:
                 config.set(sas.name, kvp['key'], kvp['value'])
             if sas.ha_mode:
                 config.set(sas.name, 'ha_mode', str(sas.ha_mode))
             for sa in sas.service_appliances or []:
                 saobj = ServiceApplianceSM.get(sa)
                 config.set(sas.name, 'device_ip', saobj.ip_address)
                 config.set(sas.name, 'user',
                            saobj.user_credential['username'])
                 config.set(sas.name, 'password',
                            saobj.user_credential['password'])
             self._loadbalancer_driver[sas.name] = \
                    importutils.import_object(sas.driver, sas.name,
                        self._svc_mon, self._vnc_lib, self.lb_db, self._args)
 def load_drivers(self):
     for sas in ServiceApplianceSetSM.values():
         if sas.driver:
             config = self._args.config_sections
             config.add_section(sas.name)
             for kvp in sas.kvpairs or []:
                 config.set(sas.name, kvp['key'], kvp['value'])
             if sas.ha_mode:
                 config.set(sas.name, 'ha_mode', str(sas.ha_mode))
             for sa in sas.service_appliances or []:
                 saobj = ServiceApplianceSM.get(sa)
                 config.set(sas.name, 'device_ip', saobj.ip_address)
                 config.set(sas.name, 'user',
                            saobj.user_credential['username'])
                 config.set(sas.name, 'password',
                            saobj.user_credential['password'])
             self._loadbalancer_driver[sas.name] = \
                    importutils.import_object(sas.driver, sas.name,
                        self._svc_mon, self._vnc_lib, self.lb_db, self._args)
Ejemplo n.º 12
0
    def create_service(self, st, si):
        if not self.validate_network_config(st, si):
            return
        #get service appliances from service template
        st_sets = list(st.service_appliance_sets)
        if not st_sets:
            self.logger.log_error("Can't find service appliances set")
            return
        service_appliance_set = ServiceApplianceSetSM.get(st_sets[0])
        service_appliances = service_appliance_set.service_appliances

        #validation
        if not service_appliances:
            self.logger.log_error("Can't find service appliances")
            return

        service_appliances = list(service_appliances)
        counter = 0

        si_obj = self._vnc_lib.service_instance_read(id=si.uuid)
        vmi_si_refs = si_obj.get_virtual_machine_interface_refs()
        vmi_si_set = set()
        si_vmi_added = False

        #create a fake VM for the schmea transfer to use
        vm_si_refs = si_obj.get_virtual_machine_back_refs()
        vm_id = ""
        if vm_si_refs and len(vm_si_refs)>0:
            vm_id = vm_si_refs[0]['uuid']
        else:
            vm_id = str(uuid.uuid4())
        self.link_si_to_vm(si, st, 0, vm_id)
        vm_obj =self._vnc_lib.virtual_machine_read(id=vm_id)

        if vmi_si_refs:
            for vmi_si_ref in vmi_si_refs:
                vmi_si_set.add(vmi_si_ref['uuid'])
        for idx in range(si.max_instances):
            instance_name = self._get_instance_name(si, idx)
            if idx+1 > len(service_appliances):
                sa_uuid = service_appliances[counter]
                counter = counter + 1
                if counter + 1 > len(service_appliances):
                    counter = 0
            else:
                sa_uuid = service_appliances[idx]

            si.state = 'launching'
            sa = ServiceApplianceSM.get(sa_uuid)
            #Create VMI
            ports = []
            for nic in si.vn_info:
                vmi_obj = self._create_svc_vm_port(nic, instance_name, si, st)
                if vmi_obj.uuid not in vmi_si_set:
                    vmi_si_obj = ServiceInstanceVirtualMachineInterfaceType()
                    int_uuid = str(si.uuid).replace("-","")
                    int_uuid = int(int_uuid,16)
                    vmi_si_obj.instance_id = int_uuid
                    vmi_si_obj.interface_type = nic['type']
                    si_obj.add_virtual_machine_interface(vmi_obj,vmi_si_obj)
                    si_vmi_added = True
                vmi_obj.add_virtual_machine(vm_obj)
                ports.append(vmi_obj)

            #connects the VMI with the PI
            pi_uuid_set = list(sa.physical_interfaces)
            for i in range(0,len(ports)):
                if i <= len(pi_uuid_set):
                    self._vnc_lib.ref_update('virtual-machine-interface', 
                        vmi.uuid, 'physical_interface_refs', pi_uuid_set[i], None, 'ADD')

        #fire change of the SI
        if si_vmi_added:
            self._vnc_lib.service_instance_update(si_obj)
            si_vmi_added = False
        si.state = "active"
Ejemplo n.º 13
0
 def load_drivers(self):
     for sas in ServiceApplianceSetSM.values():
         if sas.driver:
             self._loadbalancer_driver[sas.name] = importutils.import_object(sas.driver, self._svc_mon, self._vnc_lib)