def vnc_pod_vmi_create(self, pod_id, pod_name, pod_namespace, pod_node, node_ip, vm_obj, vn_obj, vm_vmi, idx, nw_name=''): vmi_uuid = self._create_vmi(pod_name, pod_namespace, pod_id, vm_obj, vn_obj, vm_vmi, idx, nw_name) vmi = VirtualMachineInterfaceKM.get(vmi_uuid) if self._is_pod_nested() and vm_vmi: # Pod is nested. # Link the pod VMI to the VMI of the underlay VM. self._vnc_lib.ref_update('virtual-machine-interface', vm_vmi.uuid, 'virtual-machine-interface', vmi_uuid, None, 'ADD') self._vnc_lib.ref_update('virtual-machine-interface', vmi_uuid, 'virtual-machine-interface', vm_vmi.uuid, None, 'ADD') # get host id for vm vmi vr_uuid = None for vr in VirtualRouterKM.values(): if vr.name == vm_vmi.host_id: vr_uuid = vr.uuid break if not vr_uuid: # Unable to determine VRouter for the parent VM. # # HACK ALERT # # It is possible that this is a case of FQDN mismatch between # the host name associated with the VM and the host name # associated with the corresponding vrouter. So try to look for # vrouter again with a non-FQDN name. # # This needs to be removed when provisioning can guarantee that # FQDN will be uniform across all config objects. # if '.' in vm_vmi.host_id: # Host name on VM is a FQNAME. Ignore domain name. host_id_prefix = vm_vmi.host_id.split('.')[0] for vr in VirtualRouterKM.values(): if vr.name == host_id_prefix: vr_uuid = vr.uuid break if not vr_uuid: self._logger.error("No virtual-router object found for host: " + vm_vmi.host_id + ". Unable to add VM reference to a" + " valid virtual-router") return self._vnc_lib.ref_update('virtual-router', vr_uuid, 'virtual-machine', vm_obj.uuid, None, 'ADD') iip_obj = self._create_iip(pod_name, pod_namespace, vn_obj, vmi) return vmi_uuid
def _link_vm_to_node(self, vm_obj, pod_node, node_ip): if node_ip is None: return vm = VirtualMachineKM.locate(vm_obj.uuid) if vm: vm.node_ip = node_ip vr_uuid = VirtualRouterKM.get_ip_addr_to_uuid(node_ip) if vr_uuid is None: for vr in VirtualRouterKM.values(): if vr.name == pod_node: vr_uuid = vr.uuid if vr_uuid is None: self._logger.debug("%s - Vrouter %s Not Found for Pod %s" %(self._name, node_ip, vm_obj.uuid)) return try: vrouter_obj = self._vnc_lib.virtual_router_read(id=vr_uuid) except Exception as e: self._logger.debug("%s - Vrouter %s Not Found for Pod %s" %(self._name, node_ip, vm_obj.uuid)) string_buf = StringIO() cgitb_hook(file=string_buf, format="text") err_msg = string_buf.getvalue() self._logger.error("_link_vm_to_node: %s - %s" %(self._name, err_msg)) return self._vnc_lib.ref_update('virtual-router', vrouter_obj.uuid, 'virtual-machine', vm_obj.uuid, None, 'ADD') if vm: vm.virtual_router = vrouter_obj.uuid
def _link_vm_to_node(self, vm_obj, pod_node, node_ip): if node_ip is None: return vm = VirtualMachineKM.locate(vm_obj.uuid) if vm: vm.node_ip = node_ip vr_uuid = VirtualRouterKM.get_ip_addr_to_uuid(node_ip) if vr_uuid is None: for vr in VirtualRouterKM.values(): if vr.name == pod_node: vr_uuid = vr.uuid if vr_uuid is None: self._logger.debug("%s - Vrouter %s Not Found for Pod %s" %(self._name, node_ip, vm_obj.uuid)) return try: vrouter_obj = self._vnc_lib.virtual_router_read(id=vr_uuid) except Exception as e: self._logger.debug("%s - Vrouter %s Not Found for Pod %s" %(self._name, node_ip, vm_obj.uuid)) string_buf = StringIO() cgitb_hook(file=string_buf, format="text") err_msg = string_buf.getvalue() self._logger.error("_link_vm_to_node: %s - %s" %(self._name, err_msg)) return self._vnc_lib.ref_update('virtual-router', vrouter_obj.uuid, 'virtual-machine', vm_obj.uuid, None, 'ADD') if vm: vm.virtual_router = vrouter_obj.uuid
def vnc_pod_add(self, pod_id, pod_name, pod_namespace, pod_node, node_ip, labels, vm_vmi): vm = VirtualMachineKM.get(pod_id) if vm: vm.pod_namespace = pod_namespace if not vm.virtual_router: self._link_vm_to_node(vm, pod_node, node_ip) self._set_label_to_pod_cache(labels, vm) return vm else: self._check_pod_uuid_change(pod_id, pod_name) vn_obj = self._get_network(pod_id, pod_name, pod_namespace) if not vn_obj: return vm_obj = self._create_vm(pod_namespace, pod_id, pod_name, labels) vmi_uuid = self._create_vmi(pod_name, pod_namespace, vm_obj, vn_obj, vm_vmi) vmi = VirtualMachineInterfaceKM.get(vmi_uuid) if self._is_pod_nested() and vm_vmi: # Pod is nested. # Link the pod VMI to the VMI of the underlay VM. self._vnc_lib.ref_update('virtual-machine-interface', vm_vmi.uuid, 'virtual-machine-interface', vmi_uuid, None, 'ADD') self._vnc_lib.ref_update('virtual-machine-interface', vmi_uuid, 'virtual-machine-interface', vm_vmi.uuid, None, 'ADD') # get host id for vm vmi vr_uuid = None for vr in VirtualRouterKM.values(): if vr.name == vm_vmi.host_id: vr_uuid = vr.uuid break if not vr_uuid: self._logger.error( "No virtual-router object found for host: " + vm_vmi.host_id + ". Unable to add VM reference to a" + " valid virtual-router") return self._vnc_lib.ref_update('virtual-router', vr_uuid, 'virtual-machine', vm_obj.uuid, None, 'ADD') self._create_iip(pod_name, pod_namespace, vn_obj, vmi) if not self._is_pod_nested(): self._link_vm_to_node(vm_obj, pod_node, node_ip) vm = VirtualMachineKM.locate(pod_id) if vm: vm.pod_namespace = pod_namespace vm.pod_node = pod_node vm.node_ip = node_ip self._set_label_to_pod_cache(labels, vm) return vm
def vnc_pod_add(self, pod_id, pod_name, pod_namespace, pod_node, node_ip, labels, vm_vmi): vm = VirtualMachineKM.get(pod_id) if vm: vm.pod_namespace = pod_namespace if not vm.virtual_router: self._link_vm_to_node(vm, pod_node, node_ip) self._set_label_to_pod_cache(labels, vm) return vm else: self._check_pod_uuid_change(pod_id, pod_name) vn_obj = self._get_network(pod_id, pod_name, pod_namespace) if not vn_obj: return vm_obj = self._create_vm(pod_namespace, pod_id, pod_name, labels) vmi_uuid = self._create_vmi(pod_name, pod_namespace, vm_obj, vn_obj, vm_vmi) vmi = VirtualMachineInterfaceKM.get(vmi_uuid) if self._is_pod_nested() and vm_vmi: # Pod is nested. # Link the pod VMI to the VMI of the underlay VM. self._vnc_lib.ref_update('virtual-machine-interface', vm_vmi.uuid, 'virtual-machine-interface', vmi_uuid, None, 'ADD') self._vnc_lib.ref_update('virtual-machine-interface', vmi_uuid, 'virtual-machine-interface', vm_vmi.uuid, None, 'ADD') # get host id for vm vmi vr_uuid = None for vr in VirtualRouterKM.values(): if vr.name == vm_vmi.host_id: vr_uuid = vr.uuid break if not vr_uuid: self._logger.error("No virtual-router object found for host: " + vm_vmi.host_id + ". Unable to add VM reference to a" + " valid virtual-router") return self._vnc_lib.ref_update('virtual-router', vr_uuid, 'virtual-machine', vm_obj.uuid, None, 'ADD') self._create_iip(pod_name, pod_namespace, vn_obj, vmi) if self._is_pod_network_isolated(pod_namespace): self._create_cluster_service_fip(pod_name, pod_namespace, vmi_uuid) if not self._is_pod_nested(): self._link_vm_to_node(vm_obj, pod_node, node_ip) vm = VirtualMachineKM.locate(pod_id) if vm: vm.pod_namespace = pod_namespace vm.pod_node = pod_node vm.node_ip = node_ip self._set_label_to_pod_cache(labels, vm) return vm