def _get_vip_vmi(self, si):
        lb = LoadbalancerSM.get(si.loadbalancer)
        if lb:
            vmi_id = lb.virtual_machine_interface
            vmi = VirtualMachineInterfaceSM.get(vmi_id)
            return vmi

        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if pool:
            vip = VirtualIpSM.get(pool.virtual_ip)
            if vip:
                vmi_id = vip.virtual_machine_interface
                vmi = VirtualMachineInterfaceSM.get(vmi_id)
                return vmi

        return None
    def _get_vip_vmi(self, si):
        lb = LoadbalancerSM.get(si.loadbalancer)
        if lb:
            vmi_id = lb.virtual_machine_interface
            vmi = VirtualMachineInterfaceSM.get(vmi_id)
            return vmi

        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if pool:
            vip = VirtualIpSM.get(pool.virtual_ip)
            if vip:
                vmi_id = vip.virtual_machine_interface
                vmi = VirtualMachineInterfaceSM.get(vmi_id)
                return vmi

        return None
    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 _get_vip_vmi(self, si):
        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if not pool:
            return None

        listener = LoadbalancerListenerSM.get(pool.loadbalancer_listener)
        if listener:
            lb = LoadbalancerSM.get(listener.loadbalancer)
            vmi_id = lb.virtual_machine_interface
            vmi = VirtualMachineInterfaceSM.get(vmi_id)
            return vmi

        vip = VirtualIpSM.get(pool.virtual_ip)
        if vip:
            vmi_id = vip.virtual_machine_interface
            vmi = VirtualMachineInterfaceSM.get(vmi_id)
            return vmi

        return None
 def cleanup_pi_connections(self, vmi_list):
     for vmi_id in vmi_list:
         try:
             vmi = VirtualMachineInterfaceSM.get(vmi_id)
             self._vnc_lib.ref_update('virtual-machine-interface', vmi.uuid,
                                      'physical-interface',
                                      vmi.physical_interface, None,
                                      'DELETE')
             PhysicalInterfaceSM.locate(vmi.physical_interface)
         except:
             pass
    def _get_interface_params(self, port_id, props):
        if port_id is None:
            return None

        if not props['address']:
            vmi = VirtualMachineInterfaceSM.get(port_id)
            for iip_id in vmi.instance_ips:
                iip = InstanceIpSM.get(iip_id)
                props['address'] = iip.address
                break

        return port_id
    def _get_interface_params(self, port_id, props):
        if port_id is None:
            return None

        if not props['address']:
            vmi = VirtualMachineInterfaceSM.get(port_id)
            for iip_id in vmi.instance_ips:
                iip = InstanceIpSM.get(iip_id)
                props['address'] = iip.address
                break

        return port_id
Ejemplo n.º 9
0
    def _get_interface_params(self, vip, props):
        port_id = vip.virtual_machine_interface
        if port_id is None:
            return None

        if not props['address']:
            vmi = VirtualMachineInterfaceSM.get(port_id)
            ip_refs = vmi.instance_ip
            if ip_refs:
                iip = InstanceIpSM.get(ip_refs)
                props['address'] = iip.address

        return port_id
    def _get_interface_params(self, vip, props):
        port_id = vip.virtual_machine_interface
        if port_id is None:
            return None

        if not props['address']:
            vmi = VirtualMachineInterfaceSM.get(port_id)
            ip_refs = vmi.instance_ip
            if ip_refs:
                iip = InstanceIpSM.get(ip_refs)
                props['address'] = iip.address

        return port_id
Ejemplo n.º 11
0
    def _get_interface_params(self, vip, props):
        port_id = vip.virtual_machine_interface
        if port_id is None:
            return None

        if not props["address"]:
            vmi = VirtualMachineInterfaceSM.get(port_id)
            for iip_id in vmi.instance_ips:
                iip = InstanceIpSM.get(iip_id)
                props["address"] = iip.address
                break

        return port_id
 def cleanup_pi_connections(self, vmi_list):
     for vmi_id in vmi_list:
         try:
             vmi = VirtualMachineInterfaceSM.get(vmi_id)
             self._vnc_lib.ref_update('virtual-machine-interface',
                                      vmi.uuid,
                                      'physical_interface_refs',
                                      vmi.physical_interface,
                                      None,
                                      'DELETE')
             PhysicalInterfaceSM.locate(vmi.physical_interface)
         except:
             pass
    def _get_vip_vmi(self, si):
        if not si.loadbalancer_pool:
            return None

        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if not pool.virtual_ip:
            return None

        vip = VirtualIpSM.get(pool.virtual_ip)
        if not vip.virtual_machine_interface:
            return None

        vmi = VirtualMachineInterfaceSM.get(vip.virtual_machine_interface)
        return vmi
Ejemplo n.º 14
0
    def _get_vip_vmi(self, si):
        if not si.loadbalancer_pool:
            return None

        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if not pool.virtual_ip:
            return None

        vip = VirtualIpSM.get(pool.virtual_ip)
        if not vip.virtual_machine_interface:
            return None

        vmi = VirtualMachineInterfaceSM.get(vip.virtual_machine_interface)
        return vmi
 def delete_vm(self,vm):
     if vm.virtual_machine_interfaces:
         vmi_list = list(vm.virtual_machine_interfaces)
         pt_uuid = VirtualMachineInterfaceSM.get(vmi_list[0]).port_tuple
         self.cleanup_pi_connections(vmi_list)
         self.cleanup_svc_vm_ports(vmi_list)
         try:
             self._vnc_lib.port_tuple_delete(id=pt_uuid)
             PortTupleSM.delete(pt_uuid)
         except NoIdError:
             pass
     try:
         self._vnc_lib.virtual_machine_delete(id=vm.uuid)
         VirtualMachineSM.delete(vm.uuid)
     except NoIdError:
         pass
Ejemplo n.º 16
0
 def delete_vm(self, vm):
     if vm.virtual_machine_interfaces:
         vmi_list = list(vm.virtual_machine_interfaces)
         pt_uuid = VirtualMachineInterfaceSM.get(vmi_list[0]).port_tuple
         self.cleanup_pi_connections(vmi_list)
         self.cleanup_svc_vm_ports(vmi_list)
         try:
             self._vnc_lib.port_tuple_delete(id=pt_uuid)
             PortTupleSM.delete(pt_uuid)
         except NoIdError:
             pass
     try:
         self._vnc_lib.virtual_machine_delete(id=vm.uuid)
         VirtualMachineSM.delete(vm.uuid)
     except NoIdError:
         pass
Ejemplo n.º 17
0
    def _get_vip_vmi_iip(self, si):
        if not si.loadbalancer_pool:
            return None, None

        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if not pool.virtual_ip:
            return None, None

        vip = VirtualIpSM.get(pool.virtual_ip)
        if not vip.virtual_machine_interface:
            return None, None

        vmi = VirtualMachineInterfaceSM.get(vip.virtual_machine_interface)
        if not vmi.instance_ip or not vmi.virtual_network:
            return None, None

        return vmi.instance_ip, vmi.virtual_network
    def _get_vip_vmi_iip(self, si):
        if not si.loadbalancer_pool:
            return None, None

        pool = LoadbalancerPoolSM.get(si.loadbalancer_pool)
        if not pool.virtual_ip:
            return None, None

        vip = VirtualIpSM.get(pool.virtual_ip)
        if not vip.virtual_machine_interface:
            return None, None

        vmi = VirtualMachineInterfaceSM.get(vip.virtual_machine_interface)
        if not vmi.instance_ip or not vmi.virtual_network:
            return None, None

        return vmi.instance_ip, vmi.virtual_network
Ejemplo n.º 19
0
 def _get_net_uuids(self, vmi_uuids):
     return [
         VirtualMachineInterfaceSM.get(uuid).virtual_network
         for uuid in vmi_uuids
     ]
Ejemplo n.º 20
0
    def add_snat_instance(self, router_obj):
        try:
            vnc_rtr_obj = self._vnc_lib.logical_router_read(id=router_obj.uuid)
        except vnc_exc.NoIdError:
            # msg="Unable to read logical router to set the default gateway")
            return

        try:
            project_obj = self._vnc_lib.project_read(id=router_obj.parent_uuid)
        except vnc_exc.NoIdError:
            # msg="Unable to read project to set the default gateway")
            return

        # Get netns SNAT service template
        try:
            st_obj = self._vnc_lib.service_template_read(
                fq_name=SNAT_SERVICE_TEMPLATE_FQ_NAME)
        except vnc_exc.NoIdError:
            # msg="Unable to read template to set the default gateway")
            return

        # Get the service instance if it exists
        si_name = 'si_' + router_obj.uuid
        si_fq_name = project_obj.fq_name + [si_name]
        try:
            si_obj = self._vnc_lib.service_instance_read(fq_name=si_fq_name)
            si_uuid = si_obj.uuid
        except vnc_exc.NoIdError:
            si_obj = None

        # Get route table for default route it it exists
        rt_name = 'rt_' + router_obj.uuid
        rt_fq_name = project_obj.fq_name + [rt_name]
        try:
            rt_obj = self._vnc_lib.route_table_read(fq_name=rt_fq_name)
            rt_uuid = rt_obj.uuid
        except vnc_exc.NoIdError:
            rt_obj = None

        # Set the service instance
        si_created = False
        if not si_obj:
            si_obj = ServiceInstance(si_name, parent_obj=project_obj)
            si_created = True
        si_prop_obj = ServiceInstanceType(scale_out=ServiceScaleOutType(
            max_instances=2, auto_scale=True),
                                          auto_policy=True)

        # set right interface in order of [right, left] to match template
        left_if = ServiceInstanceInterfaceType()
        virtual_network = router_obj.virtual_network
        vn_obj = VirtualNetworkSM.get(virtual_network)
        right_if = ServiceInstanceInterfaceType(
            virtual_network=':'.join(vn_obj.fq_name))
        si_prop_obj.set_interface_list([right_if, left_if])
        si_prop_obj.set_ha_mode('active-standby')

        si_obj.set_service_instance_properties(si_prop_obj)
        si_obj.set_service_template(st_obj)
        if si_created:
            si_uuid = self._vnc_lib.service_instance_create(si_obj)
        else:
            self._vnc_lib.service_instance_update(si_obj)

        # Set the route table
        route_obj = RouteType(prefix="0.0.0.0/0",
                              next_hop=si_obj.get_fq_name_str())
        rt_created = False
        if not rt_obj:
            rt_obj = RouteTable(name=rt_name, parent_obj=project_obj)
            rt_created = True
        rt_obj.set_routes(RouteTableType.factory([route_obj]))
        if rt_created:
            rt_uuid = self._vnc_lib.route_table_create(rt_obj)
        else:
            self._vnc_lib.route_table_update(rt_obj)

        # Associate route table to all private networks connected onto
        # that router
        for intf in router_obj.virtual_machine_interfaces or []:
            vmi_obj = VirtualMachineInterfaceSM.locate(intf)
            net_id = vmi_obj.virtual_network
            try:
                net_obj = self._vnc_lib.virtual_network_read(id=net_id)
            except vnc_exc.NoIdError:
                continue
            net_obj.set_route_table(rt_obj)
            self._vnc_lib.virtual_network_update(net_obj)

        # Add logical gateway virtual network
        vnc_rtr_obj.set_service_instance(si_obj)
        self._vnc_lib.logical_router_update(vnc_rtr_obj)
Ejemplo n.º 21
0
 def _get_net_uuids(self, vmi_uuids):
      return [
          VirtualMachineInterfaceSM.get(uuid).virtual_network
          for uuid in vmi_uuids]