Example #1
0
 def _find_cluster_switch_for_vm(self, device_id):
     cluster_mor = resource_util.get_cluster_mor_for_vm(self.session,
                                                        device_id)
     cluster_path = None
     if cluster_mor:
         cluster_id = cluster_mor.value
         cluster_path = cache.VCCache.get_cluster_path_for_id(cluster_id)
     if not cluster_path:
         raise error.VcenterConfigurationError(_("Cluster for VM %s could "
                                               "not be determined")
                                               % device_id)
     switch_name = cache.VCCache.get_switch_for_cluster_path(cluster_path)
     return cluster_mor, cluster_path, switch_name
Example #2
0
 def create_port(self, network, net_id, port, virtual_nic):
     device_id = port.vm_id
     cluster_mor, cluster_path, switch = self._find_cluster_switch_for_vm(
         device_id)
     host_mors = self.is_valid_switch(cluster_mor, switch)
     if not host_mors:
         LOG.error(_LE("Invalid Switch: %(sw)s for cluster: %(cp)s."),
                   {'sw': switch, 'cp': cluster_path})
         raise error.VcenterConfigurationError("Invalid Switch: %s for "
                                               "cluster: %s." %
                                               (switch, cluster_path))
     hosts = []
     for host_mor in host_mors:
         hosts.append(model.Host(key=host_mor.value))
     vswitch = model.VirtualSwitch(switch, hosts=hosts)
     self.create_network(network, net_id, vswitch)