Exemplo n.º 1
0
    def disconnect_switch_port(self, switch_port_name, vnic_deleted,
                               delete_port):
        """Disconnects the switch port."""
        switch_svc = self._conn.Msvm_VirtualSwitchManagementService()[0]
        switch_port_path = self._get_switch_port_path_by_name(switch_port_name)
        if not switch_port_path:
            # Port not found. It happens when the VM was already deleted.
            return

        if not vnic_deleted:
            (ret_val, ) = switch_svc.DisconnectSwitchPort(
                SwitchPort=switch_port_path)
            if ret_val != 0:
                data = {
                    'switch_port_name': switch_port_name,
                    'ret_val': ret_val
                }
                raise HyperVException(
                    msg=_('Failed to disconnect port %(switch_port_name)s '
                          'with error %(ret_val)s') % data)
        if delete_port:
            (ret_val, ) = switch_svc.DeleteSwitchPort(
                SwitchPort=switch_port_path)
            if ret_val != 0:
                data = {
                    'switch_port_name': switch_port_name,
                    'ret_val': ret_val
                }
                raise HyperVException(
                    msg=_('Failed to delete port %(switch_port_name)s '
                          'with error %(ret_val)s') % data)
Exemplo n.º 2
0
    def disconnect_switch_port(self, switch_port_name, vnic_deleted,
                               delete_port):
        """Disconnects the switch port."""
        switch_svc = self._conn.Msvm_VirtualSwitchManagementService()[0]
        switch_port_path = self._get_switch_port_path_by_name(
            switch_port_name)
        if not switch_port_path:
            # Port not found. It happens when the VM was already deleted.
            return

        if not vnic_deleted:
            (ret_val, ) = switch_svc.DisconnectSwitchPort(
                SwitchPort=switch_port_path)
            if ret_val != 0:
                data = {'switch_port_name': switch_port_name,
                        'ret_val': ret_val}
                raise HyperVException(
                    msg=_('Failed to disconnect port %(switch_port_name)s '
                          'with error %(ret_val)s') % data)
        if delete_port:
            (ret_val, ) = switch_svc.DeleteSwitchPort(
                SwitchPort=switch_port_path)
            if ret_val != 0:
                data = {'switch_port_name': switch_port_name,
                        'ret_val': ret_val}
                raise HyperVException(
                    msg=_('Failed to delete port %(switch_port_name)s '
                          'with error %(ret_val)s') % data)
Exemplo n.º 3
0
    def create_default_reject_all_rules(self, switch_port_name):
        port, found = self._get_switch_port_allocation(switch_port_name, False)
        if not found:
            raise utils.HyperVException(
                msg=_('Port Allocation not found: %s') % switch_port_name)

        acls = port.associators(wmi_result_class=self._PORT_EXT_ACL_SET_DATA)
        filtered_acls = [v for v in acls if v.Action == self._ACL_ACTION_DENY]

        if len(filtered_acls) >= self._REJECT_ACLS_COUNT:
            return

        for acl in filtered_acls:
            self._remove_virt_feature(acl)

        weight = 0
        ipv4_pair = (self._ACL_TYPE_IPV4, self._IPV4_ANY)
        ipv6_pair = (self._ACL_TYPE_IPV6, self._IPV6_ANY)
        for direction in [self._ACL_DIR_IN, self._ACL_DIR_OUT]:
            for acl_type, address in [ipv4_pair, ipv6_pair]:
                for protocol in [self._TCP_PROTOCOL,
                                 self._UDP_PROTOCOL,
                                 self._ICMP_PROTOCOL]:
                    self._bind_security_rule(
                        port, direction, acl_type, self._ACL_ACTION_DENY,
                        self._ACL_DEFAULT, protocol, address, weight)
                    weight += 1
    def _provision_network(self, port_id,
                           net_uuid, network_type,
                           physical_network,
                           segmentation_id):
        LOG.info(_LI("Provisioning network %s"), net_uuid)

        vswitch_name = self._get_vswitch_name(network_type, physical_network)
        if network_type == constants.TYPE_VLAN:
            # Nothing to do
            pass
        elif network_type == constants.TYPE_NVGRE and self._nvgre_enabled:
            self._nvgre_ops.bind_nvgre_network(
                segmentation_id, net_uuid, vswitch_name)
        elif network_type == constants.TYPE_FLAT:
            # Nothing to do
            pass
        elif network_type == constants.TYPE_LOCAL:
            # TODO(alexpilotti): Check that the switch type is private
            # or create it if not existing
            pass
        else:
            raise exception.NetworkingHyperVException(
                (_("Cannot provision unknown network type %(network_type)s"
                   " for network %(net_uuid)s") %
                 dict(network_type=network_type, net_uuid=net_uuid)))

        map = {
            'network_type': network_type,
            'vswitch_name': vswitch_name,
            'ports': [],
            'vlan_id': segmentation_id}
        self._network_vswitch_map[net_uuid] = map
Exemplo n.º 5
0
 def _get_vswitch(self, vswitch_name):
     vswitch = self._conn.Msvm_VirtualEthernetSwitch(
         ElementName=vswitch_name)
     if not len(vswitch):
         raise utils.HyperVException(msg=_('VSwitch not found: %s') %
                                     vswitch_name)
     return vswitch[0]
    def _init_nvgre(self):
        # if NVGRE is enabled, self._nvgre_ops is required in order to properly
        # set the agent state (see get_agent_configrations method).

        if not CONF.NVGRE.enable_support:
            return

        if not CONF.NVGRE.provider_tunnel_ip:
            err_msg = _(
                "enable_nvgre_support is set to True, but provider "
                "tunnel IP is not configured. Check neutron.conf "
                "config file."
            )
            LOG.error(err_msg)
            raise utils.HyperVException(msg=err_msg)

        self._nvgre_enabled = True
        self._nvgre_ops = nvgre_ops.HyperVNvgreOps(list(self._physical_network_mappings.values()))

        self._nvgre_ops.init_notifier(self.context, self.client)
        self._nvgre_ops.tunnel_update(self.context, CONF.NVGRE.provider_tunnel_ip, constants.TYPE_NVGRE)

        # setup Hyper-V Agent Lookup Record update consumer
        topic = hyperv_agent_notifier.get_topic_name(self.topic, constants.LOOKUP, constants.UPDATE)
        self.connection.create_consumer(topic, self.endpoints, fanout=True)

        # the created consumer is the last connection server.
        # need to start it in order for it to consume.
        self.connection.servers[-1].start()
Exemplo n.º 7
0
    def set_vswitch_port_vlan_id(self, vlan_id, switch_port_name):
        port_alloc, found = self._get_switch_port_allocation(switch_port_name)
        if not found:
            raise utils.HyperVException(
                msg=_('Port Allocation not found: %s') % switch_port_name)

        vlan_settings = self._get_vlan_setting_data_from_port_alloc(port_alloc)
        if vlan_settings:
            if (vlan_settings.OperationMode == self._OPERATION_MODE_ACCESS and
                    vlan_settings.AccessVlanId == vlan_id):
                # VLAN already set to corect value, no need to change it.
                return

            # Removing the feature because it cannot be modified
            # due to a wmi exception.
            self._remove_virt_feature(vlan_settings)

            # remove from cache.
            self._vlan_sds.pop(port_alloc.InstanceID, None)

        vlan_settings = self._create_default_setting_data(
            self._PORT_VLAN_SET_DATA)
        vlan_settings.AccessVlanId = vlan_id
        vlan_settings.OperationMode = self._OPERATION_MODE_ACCESS
        self._add_virt_feature(port_alloc, vlan_settings)
Exemplo n.º 8
0
    def _provision_network(self, port_id, net_uuid, network_type,
                           physical_network, segmentation_id):
        LOG.info(_LI("Provisioning network %s"), net_uuid)

        vswitch_name = self._get_vswitch_name(network_type, physical_network)
        if network_type == constants.TYPE_VLAN:
            # Nothing to do
            pass
        elif network_type == constants.TYPE_NVGRE and self._nvgre_enabled:
            self._nvgre_ops.bind_nvgre_network(segmentation_id, net_uuid,
                                               vswitch_name)
        elif network_type == constants.TYPE_FLAT:
            # Nothing to do
            pass
        elif network_type == constants.TYPE_LOCAL:
            # TODO(alexpilotti): Check that the switch type is private
            # or create it if not existing
            pass
        else:
            raise exception.NetworkingHyperVException(
                (_("Cannot provision unknown network type %(network_type)s"
                   " for network %(net_uuid)s") %
                 dict(network_type=network_type, net_uuid=net_uuid)))

        map = {
            'network_type': network_type,
            'vswitch_name': vswitch_name,
            'ports': [],
            'vlan_id': segmentation_id
        }
        self._network_vswitch_map[net_uuid] = map
Exemplo n.º 9
0
 def _get_vswitch(self, vswitch_name):
     vswitch = self._conn.Msvm_VirtualEthernetSwitch(
         ElementName=vswitch_name)
     if not len(vswitch):
         raise utils.HyperVException(msg=_('VSwitch not found: %s') %
                                     vswitch_name)
     return vswitch[0]
Exemplo n.º 10
0
    def _init_nvgre(self):
        # if NVGRE is enabled, self._nvgre_ops is required in order to properly
        # set the agent state (see get_agent_configrations method).

        if not CONF.NVGRE.enable_support:
            return

        if not CONF.NVGRE.provider_tunnel_ip:
            err_msg = _('enable_nvgre_support is set to True, but provider '
                        'tunnel IP is not configured. Check neutron.conf '
                        'config file.')
            LOG.error(err_msg)
            raise utils.HyperVException(msg=err_msg)

        self._nvgre_enabled = True
        self._nvgre_ops = nvgre_ops.HyperVNvgreOps(
            list(self._physical_network_mappings.values()))

        self._nvgre_ops.init_notifier(self.context, self.client)
        self._nvgre_ops.tunnel_update(self.context,
                                      CONF.NVGRE.provider_tunnel_ip,
                                      constants.TYPE_NVGRE)

        # setup Hyper-V Agent Lookup Record update consumer
        topic = hyperv_agent_notifier.get_topic_name(self.topic,
                                                     constants.LOOKUP,
                                                     constants.UPDATE)
        self.connection.create_consumer(topic, self.endpoints, fanout=True)

        # the created consumer is the last connection server.
        # need to start it in order for it to consume.
        self.connection.servers[-1].start()
Exemplo n.º 11
0
    def set_vswitch_port_vlan_id(self, vlan_id, switch_port_name):
        port_alloc, found = self._get_switch_port_allocation(switch_port_name)
        if not found:
            raise utils.HyperVException(
                msg=_('Port Allocation not found: %s') % switch_port_name)

        vlan_settings = self._get_vlan_setting_data_from_port_alloc(port_alloc)
        if vlan_settings:
            if (vlan_settings.OperationMode == self._OPERATION_MODE_ACCESS
                    and vlan_settings.AccessVlanId == vlan_id):
                # VLAN already set to corect value, no need to change it.
                return

            # Removing the feature because it cannot be modified
            # due to a wmi exception.
            self._remove_virt_feature(vlan_settings)

            # remove from cache.
            self._vlan_sds.pop(port_alloc.InstanceID, None)

        vlan_settings = self._get_default_setting_data(
            self._PORT_VLAN_SET_DATA)
        vlan_settings.AccessVlanId = vlan_id
        vlan_settings.OperationMode = self._OPERATION_MODE_ACCESS
        self._add_virt_feature(port_alloc, vlan_settings)
    def _provision_network(self, port_id,
                           net_uuid, network_type,
                           physical_network,
                           segmentation_id):
        LOG.info(_LI("Provisioning network %s"), net_uuid)

        vswitch_name = self._get_vswitch_name(network_type, physical_network)
        if network_type == constants.TYPE_VLAN:
            self._utils.set_switch_external_port_trunk_vlan(
                vswitch_name, segmentation_id, constants.TRUNK_ENDPOINT_MODE)
        elif network_type == constants.TYPE_FLAT:
            # Nothing to do
            pass
        elif network_type == constants.TYPE_LOCAL:
            # TODO(alexpilotti): Check that the switch type is private
            # or create it if not existing
            pass
        else:
            raise utils.HyperVException(
                msg=(_("Cannot provision unknown network type %(network_type)s"
                       " for network %(net_uuid)s") %
                     dict(network_type=network_type, net_uuid=net_uuid)))

        map = {
            'network_type': network_type,
            'vswitch_name': vswitch_name,
            'ports': [],
            'vlan_id': segmentation_id}
        self._network_vswitch_map[net_uuid] = map
Exemplo n.º 13
0
    def set_vswitch_port_vlan_id(self, vlan_id, switch_port_name):
        port_alloc, found = self._get_switch_port_allocation(switch_port_name)
        if not found:
            raise utils.HyperVException(
                msg=_('Port Allocation not found: %s') % switch_port_name)

        vs_man_svc = self._conn.Msvm_VirtualSystemManagementService()[0]
        vlan_settings = self._get_vlan_setting_data_from_port_alloc(port_alloc)
        if vlan_settings:
            if (vlan_settings.OperationMode == self._OPERATION_MODE_ACCESS and
                    vlan_settings.AccessVlanId == vlan_id):
                # VLAN already set to corect value, no need to change it.
                return

            # Removing the feature because it cannot be modified
            # due to a wmi exception.
            (job_path, ret_val) = vs_man_svc.RemoveFeatureSettings(
                FeatureSettings=[vlan_settings.path_()])
            self._check_job_status(ret_val, job_path)

        (vlan_settings, found) = self._get_vlan_setting_data(switch_port_name)
        vlan_settings.AccessVlanId = vlan_id
        vlan_settings.OperationMode = self._OPERATION_MODE_ACCESS
        (job_path, out, ret_val) = vs_man_svc.AddFeatureSettings(
            port_alloc.path_(), [vlan_settings.GetText_(1)])
        self._check_job_status(ret_val, job_path)
Exemplo n.º 14
0
    def deprecated(self, msg, *args, **kwargs):
        """Call this method when a deprecated feature is used.

        If the system is configured for fatal deprecations then the message
        is logged at the 'critical' level and :class:`DeprecatedConfig` will
        be raised.

        Otherwise, the message will be logged (once) at the 'warn' level.

        :raises: :class:`DeprecatedConfig` if the system is configured for
                 fatal deprecations.

        """
        stdmsg = _("Deprecated: %s") % msg
        if CONF.fatal_deprecations:
            self.critical(stdmsg, *args, **kwargs)
            raise DeprecatedConfig(msg=stdmsg)

        # Using a list because a tuple with dict can't be stored in a set.
        sent_args = self._deprecated_messages_sent.setdefault(msg, list())

        if args in sent_args:
            # Already logged this message, so don't log it again.
            return

        sent_args.append(args)
        self.warn(stdmsg, *args, **kwargs)
Exemplo n.º 15
0
    def _check_job_status(self, ret_val, jobpath):
        """Poll WMI job state for completion."""
        if not ret_val:
            return
        elif ret_val not in [WMI_JOB_STATE_STARTED, WMI_JOB_STATE_RUNNING]:
            raise HyperVException(msg=_('Job failed with error %d') % ret_val)

        job_wmi_path = jobpath.replace('\\', '/')
        job = wmi.WMI(moniker=job_wmi_path)

        while job.JobState == WMI_JOB_STATE_RUNNING:
            time.sleep(0.1)
            job = wmi.WMI(moniker=job_wmi_path)
        if job.JobState != WMI_JOB_STATE_COMPLETED:
            job_state = job.JobState
            if job.path().Class == "Msvm_ConcreteJob":
                err_sum_desc = job.ErrorSummaryDescription
                err_desc = job.ErrorDescription
                err_code = job.ErrorCode
                data = {
                    'job_state': job_state,
                    'err_sum_desc': err_sum_desc,
                    'err_desc': err_desc,
                    'err_code': err_code
                }
                raise HyperVException(
                    msg=_("WMI job failed with status %(job_state)d. "
                          "Error details: %(err_sum_desc)s - %(err_desc)s - "
                          "Error code: %(err_code)d") % data)
            else:
                (error, ret_val) = job.GetError()
                if not ret_val and error:
                    data = {'job_state': job_state, 'error': error}
                    raise HyperVException(
                        msg=_("WMI job failed with status %(job_state)d. "
                              "Error details: %(error)s") % data)
                else:
                    raise HyperVException(
                        msg=_("WMI job failed with status %d. "
                              "No error description available") % job_state)

        desc = job.Description
        elap = job.ElapsedTime
        LOG.debug("WMI job succeeded: %(desc)s, Elapsed=%(elap)s", {
            'desc': desc,
            'elap': elap
        })
Exemplo n.º 16
0
    def _check_job_status(self, ret_val, jobpath):
        """Poll WMI job state for completion."""
        if not ret_val:
            return
        elif ret_val not in [WMI_JOB_STATE_STARTED, WMI_JOB_STATE_RUNNING]:
            raise HyperVException(msg=_('Job failed with error %d') % ret_val)

        job_wmi_path = jobpath.replace('\\', '/')
        job = wmi.WMI(moniker=job_wmi_path)

        while job.JobState == WMI_JOB_STATE_RUNNING:
            time.sleep(0.1)
            job = wmi.WMI(moniker=job_wmi_path)
        if job.JobState != WMI_JOB_STATE_COMPLETED:
            job_state = job.JobState
            if job.path().Class == "Msvm_ConcreteJob":
                err_sum_desc = job.ErrorSummaryDescription
                err_desc = job.ErrorDescription
                err_code = job.ErrorCode
                data = {'job_state': job_state,
                        'err_sum_desc': err_sum_desc,
                        'err_desc': err_desc,
                        'err_code': err_code}
                raise HyperVException(
                    msg=_("WMI job failed with status %(job_state)d. "
                          "Error details: %(err_sum_desc)s - %(err_desc)s - "
                          "Error code: %(err_code)d") % data)
            else:
                (error, ret_val) = job.GetError()
                if not ret_val and error:
                    data = {'job_state': job_state,
                            'error': error}
                    raise HyperVException(
                        msg=_("WMI job failed with status %(job_state)d. "
                              "Error details: %(error)s") % data)
                else:
                    raise HyperVException(
                        msg=_("WMI job failed with status %d. "
                              "No error description available") % job_state)

        desc = job.Description
        elap = job.ElapsedTime
        LOG.debug("WMI job succeeded: %(desc)s, Elapsed=%(elap)s",
                  {'desc': desc, 'elap': elap})
Exemplo n.º 17
0
    def _is_port_vm_started(self, port):
        vmsettings = port.associators(
            wmi_result_class=self._VIRTUAL_SYSTEM_SETTING_DATA)
        # See http://msdn.microsoft.com/en-us/library/cc160706%28VS.85%29.aspx
        (ret_val, summary_info) = self._vs_man_svc.GetSummaryInformation(
            [self._VM_SUMMARY_ENABLED_STATE], [v.path_() for v in vmsettings])
        if ret_val or not summary_info:
            raise utils.HyperVException(msg=_('Cannot get VM summary data '
                                              'for: %s') % port.ElementName)

        return summary_info[0].EnabledState is self._HYPERV_VM_STATE_ENABLED
Exemplo n.º 18
0
    def _is_port_vm_started(self, port):
        vmsettings = port.associators(
            wmi_result_class=self._VIRTUAL_SYSTEM_SETTING_DATA)
        # See http://msdn.microsoft.com/en-us/library/cc160706%28VS.85%29.aspx
        (ret_val, summary_info) = self._vs_man_svc.GetSummaryInformation(
            [self._VM_SUMMARY_ENABLED_STATE],
            [v.path_() for v in vmsettings])
        if ret_val or not summary_info:
            raise utils.HyperVException(msg=_('Cannot get VM summary data '
                                              'for: %s') % port.ElementName)

        return summary_info[0].EnabledState is self._HYPERV_VM_STATE_ENABLED
Exemplo n.º 19
0
 def _create_switch_port(self, vswitch_name, switch_port_name):
     """Creates a switch port."""
     switch_svc = self._conn.Msvm_VirtualSwitchManagementService()[0]
     vswitch_path = self._get_vswitch(vswitch_name).path_()
     (new_port,
      ret_val) = switch_svc.CreateSwitchPort(Name=switch_port_name,
                                             FriendlyName=switch_port_name,
                                             ScopeOfResidence="",
                                             VirtualSwitch=vswitch_path)
     if ret_val != 0:
         raise HyperVException(msg=_('Failed creating port for %s') %
                               vswitch_name)
     return new_port
Exemplo n.º 20
0
 def _create_switch_port(self, vswitch_name, switch_port_name):
     """Creates a switch port."""
     switch_svc = self._conn.Msvm_VirtualSwitchManagementService()[0]
     vswitch_path = self._get_vswitch(vswitch_name).path_()
     (new_port, ret_val) = switch_svc.CreateSwitchPort(
         Name=switch_port_name,
         FriendlyName=switch_port_name,
         ScopeOfResidence="",
         VirtualSwitch=vswitch_path)
     if ret_val != 0:
         raise HyperVException(
             msg=_('Failed creating port for %s') % vswitch_name)
     return new_port
Exemplo n.º 21
0
    def _init_nvgre(self):
        # if NVGRE is enabled, self._nvgre_ops is required in order to properly
        # set the agent state (see get_agent_configrations method).

        if not CONF.NVGRE.enable_support:
            return

        if not CONF.NVGRE.provider_tunnel_ip:
            err_msg = _('enable_nvgre_support is set to True, but provider '
                        'tunnel IP is not configured. Check neutron.conf '
                        'config file.')
            LOG.error(err_msg)
            raise exception.NetworkingHyperVException(err_msg)

        self._nvgre_enabled = True
        self._nvgre_ops = nvgre_ops.HyperVNvgreOps(
            list(self._physical_network_mappings.values()))

        self._nvgre_ops.init_notifier(self.context, self.client)
        self._nvgre_ops.tunnel_update(self.context,
                                      CONF.NVGRE.provider_tunnel_ip,
                                      constants.TYPE_NVGRE)
    def _init_nvgre(self):
        # if NVGRE is enabled, self._nvgre_ops is required in order to properly
        # set the agent state (see get_agent_configrations method).

        if not CONF.NVGRE.enable_support:
            return

        if not CONF.NVGRE.provider_tunnel_ip:
            err_msg = _('enable_nvgre_support is set to True, but provider '
                        'tunnel IP is not configured. Check neutron.conf '
                        'config file.')
            LOG.error(err_msg)
            raise exception.NetworkingHyperVException(err_msg)

        self._nvgre_enabled = True
        self._nvgre_ops = nvgre_ops.HyperVNvgreOps(
            list(self._physical_network_mappings.values()))

        self._nvgre_ops.init_notifier(self.context, self.client)
        self._nvgre_ops.tunnel_update(self.context,
                                      CONF.NVGRE.provider_tunnel_ip,
                                      constants.TYPE_NVGRE)
Exemplo n.º 23
0
def _find_facility_from_conf():
    facility_names = logging.handlers.SysLogHandler.facility_names
    facility = getattr(logging.handlers.SysLogHandler,
                       CONF.syslog_log_facility,
                       None)

    if facility is None and CONF.syslog_log_facility in facility_names:
        facility = facility_names.get(CONF.syslog_log_facility)

    if facility is None:
        valid_facilities = facility_names.keys()
        consts = ['LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRON', 'LOG_DAEMON',
                  'LOG_FTP', 'LOG_KERN', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS',
                  'LOG_AUTH', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP',
                  'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3',
                  'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7']
        valid_facilities.extend(consts)
        raise TypeError(_('syslog facility must be one of: %s') %
                        ', '.join("'%s'" % fac
                                  for fac in valid_facilities))

    return facility
Exemplo n.º 24
0
    def set_vswitch_port_vsid(self, vsid, switch_port_name):
        port_alloc, found = self._get_switch_port_allocation(switch_port_name)
        if not found:
            raise utils.HyperVException(
                msg=_('Port Allocation not found: %s') % switch_port_name)

        vsid_settings = self._get_security_setting_data_from_port_alloc(
            port_alloc)

        if vsid_settings:
            if vsid_settings.VirtualSubnetId == vsid:
                # VSID already added, no need to readd it.
                return
            # Removing the feature because it cannot be modified
            # due to a wmi exception.
            self._remove_virt_feature(vsid_settings)

            # remove from cache.
            self._vsid_sds.pop(port_alloc.InstanceID, None)

        vsid_settings = self._create_default_setting_data(
            self._PORT_SECURITY_SET_DATA)
        vsid_settings.VirtualSubnetId = vsid
        self._add_virt_feature(port_alloc, vsid_settings)
Exemplo n.º 25
0
    def set_vswitch_port_vsid(self, vsid, switch_port_name):
        port_alloc, found = self._get_switch_port_allocation(switch_port_name)
        if not found:
            raise utils.HyperVException(
                msg=_('Port Allocation not found: %s') % switch_port_name)

        vsid_settings = self._get_security_setting_data_from_port_alloc(
            port_alloc)

        if vsid_settings:
            if vsid_settings.VirtualSubnetId == vsid:
                # VSID already added, no need to readd it.
                return
            # Removing the feature because it cannot be modified
            # due to a wmi exception.
            self._remove_virt_feature(vsid_settings)

            # remove from cache.
            self._vsid_sds.pop(port_alloc.InstanceID, None)

        vsid_settings = self._get_default_setting_data(
            self._PORT_SECURITY_SET_DATA)
        vsid_settings.VirtualSubnetId = vsid
        self._add_virt_feature(port_alloc, vsid_settings)
Exemplo n.º 26
0
from oslo_config import cfg
from oslo_log import log as logging

from hyperv.common.i18n import _, _LI, _LW, _LE  # noqa
from hyperv.neutron import constants
from hyperv.neutron import utilsv2

# Check needed for unit testing on Unix
if sys.platform == 'win32':
    import wmi

agent_opts = [
    cfg.StrOpt('neutron_metadata_address',
               default='169.254.169.254',
               help=_('Specifies the address which will serve the metadata for'
                      ' the instance.')),
]

CONF = cfg.CONF
CONF.register_opts(agent_opts, "AGENT")

LOG = logging.getLogger(__name__)


class NvgreUtils(object):
    _HYPERV_VIRT_ADAPTER = 'Hyper-V Virtual Ethernet Adapter'
    _IPV4_ADDRESS_FAMILY = 2

    _WNV_BIND_NAME = 'Wnv'
    _TRANSLATE_NAT = 0
    _TRANSLATE_ENCAP = 1
Exemplo n.º 27
0
 def _get_vswitch(self, vswitch_name):
     vswitch = self._conn.Msvm_VirtualSwitch(ElementName=vswitch_name)
     if not vswitch:
         raise HyperVException(msg=_('VSwitch not found: %s') %
                               vswitch_name)
     return vswitch[0]
Exemplo n.º 28
0
 def enable_control_metrics(self, switch_port_name):
     raise NotImplementedError(
         _("Metrics collection is not supported on "
           "this version of Hyper-V"))
Exemplo n.º 29
0
from oslo_config import cfg
from oslo_log import log as logging
import six

from hyperv.common.i18n import _, _LE, _LI  # noqa
from hyperv.neutron import constants
from hyperv.neutron import hyperv_agent_notifier
from hyperv.neutron import nvgre_ops
from hyperv.neutron import utils
from hyperv.neutron import utilsfactory

nvgre_opts = [
    cfg.BoolOpt('enable_support',
                default=False,
                help=_('Enables Hyper-V NVGRE. '
                       'Requires Windows Server 2012 or above.')),
    cfg.IntOpt('provider_vlan_id',
               default=0,
               help=_('Specifies the VLAN ID of the physical network, required'
                      ' for setting the NVGRE Provider Address.')),
    cfg.StrOpt('provider_tunnel_ip',
               default=None,
               help=_('Specifies the tunnel IP which will be used and '
                      'reported by this host for NVGRE networks.')),
]

CONF = cfg.CONF
CONF.register_opts(nvgre_opts, "NVGRE")

LOG = logging.getLogger(__name__)
from oslo_config import cfg
from oslo_log import log as logging
import six

from hyperv.common.i18n import _, _LE, _LI  # noqa
from hyperv.neutron import constants
from hyperv.neutron import hyperv_agent_notifier
from hyperv.neutron import nvgre_ops
from hyperv.neutron import utils
from hyperv.neutron import utilsfactory

nvgre_opts = [
    cfg.BoolOpt('enable_support',
                default=False,
                help=_('Enables Hyper-V NVGRE. '
                       'Requires Windows Server 2012 or above.')),
    cfg.IntOpt('provider_vlan_id',
               default=0,
               help=_('Specifies the VLAN ID of the physical network, required'
                      ' for setting the NVGRE Provider Address.')),
    cfg.StrOpt('provider_tunnel_ip',
               default=None,
               help=_('Specifies the tunnel IP which will be used and '
                      'reported by this host for NVGRE networks.')),
]

CONF = cfg.CONF
CONF.register_opts(nvgre_opts, "NVGRE")

LOG = logging.getLogger(__name__)
Exemplo n.º 31
0
from oslo_config import cfg
from oslo_log import log as logging

from hyperv.common.i18n import _, _LI, _LW, _LE  # noqa
from hyperv.neutron import constants
from hyperv.neutron import utilsv2

# Check needed for unit testing on Unix
if sys.platform == 'win32':
    import wmi

agent_opts = [
    cfg.StrOpt('neutron_metadata_address',
               default='169.254.169.254',
               help=_('Specifies the address which will serve the metadata for'
                      ' the instance.')),
]

CONF = cfg.CONF
CONF.register_opts(agent_opts, "AGENT")

LOG = logging.getLogger(__name__)


class NvgreUtils(object):
    _HYPERV_VIRT_ADAPTER = 'Hyper-V Virtual Ethernet Adapter'
    _IPV4_ADDRESS_FAMILY = 2

    _WNV_BIND_NAME = 'Wnv'
    _TRANSLATE_NAT = 0
    _TRANSLATE_ENCAP = 1
Exemplo n.º 32
0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg

from hyperv.common.i18n import _

HYPERV_AGENT_OPTS = [
    cfg.ListOpt('physical_network_vswitch_mappings',
                default=[],
                help=_('List of <physical_network>:<vswitch> '
                       'where the physical networks can be expressed with '
                       'wildcards, e.g.: ."*:external"')),
    cfg.StrOpt('local_network_vswitch',
               default='private',
               help=_('Private vswitch name used for local networks')),
    cfg.IntOpt('polling_interval',
               default=2,
               min=1,
               help=_("The number of seconds the agent will wait between "
                      "polling for local device changes.")),
    cfg.IntOpt('worker_count',
               default=10,
               min=1,
               help=_("The number of worker threads allowed to run in "
                      "parallel to process port binding.")),
    cfg.IntOpt('worker_retry',
from oslo.config import cfg

from hyperv.common.i18n import _, _LW  # noqa
from hyperv.common import log as logging
from hyperv.neutron import utils
from hyperv.neutron import utilsv2

# Check needed for unit testing on Unix
if sys.platform == 'win32':
    import wmi

hyper_opts = [
    cfg.BoolOpt('force_hyperv_utils_v1',
                default=False,
                help=_('Force V1 WMI utility classes')),
]

CONF = cfg.CONF
CONF.register_opts(hyper_opts, 'hyperv')

LOG = logging.getLogger(__name__)


def _get_windows_version():
    return wmi.WMI(moniker='//./root/cimv2').Win32_OperatingSystem()[0].Version


def _check_min_windows_version(major, minor, build=0):
    version_str = _get_windows_version()
    return map(int, version_str.split('.')) >= [major, minor, build]
import re
import time

from oslo_config import cfg
from oslo_log import log as logging

from hyperv.common.i18n import _, _LE, _LI  # noqa
from hyperv.neutron import constants
from hyperv.neutron import hyperv_agent_notifier
from hyperv.neutron import nvgre_ops
from hyperv.neutron import utils
from hyperv.neutron import utilsfactory

nvgre_opts = [
    cfg.BoolOpt(
        "enable_support", default=False, help=_("Enables Hyper-V NVGRE. " "Requires Windows Server 2012 or above.")
    ),
    cfg.IntOpt(
        "provider_vlan_id",
        default=0,
        help=_("Specifies the VLAN ID of the physical network, required" " for setting the NVGRE Provider Address."),
    ),
    cfg.StrOpt(
        "provider_tunnel_ip",
        default=None,
        help=_("Specifies the tunnel IP which will be used and " "reported by this host for NVGRE networks."),
    ),
]

CONF = cfg.CONF
CONF.register_opts(nvgre_opts, "NVGRE")
Exemplo n.º 35
0
 def enable_control_metrics(self, switch_port_name):
     raise NotImplementedError(_("Metrics collection is not supported on "
                                 "this version of Hyper-V"))
Exemplo n.º 36
0
 def _get_vswitch(self, vswitch_name):
     vswitch = self._conn.Msvm_VirtualSwitch(ElementName=vswitch_name)
     if not vswitch:
         raise HyperVException(msg=_('VSwitch not found: %s') %
                               vswitch_name)
     return vswitch[0]
Exemplo n.º 37
0
 def _get_vnic_settings(self, vnic_name):
     vnic_settings = self._conn.Msvm_SyntheticEthernetPortSettingData(
         ElementName=vnic_name)
     if not vnic_settings:
         raise HyperVException(msg=_('Vnic not found: %s') % vnic_name)
     return vnic_settings[0]
Exemplo n.º 38
0
 def _get_vnic_settings(self, vnic_name):
     vnic_settings = self._conn.Msvm_SyntheticEthernetPortSettingData(
         ElementName=vnic_name)
     if not vnic_settings:
         raise HyperVException(msg=_('Vnic not found: %s') % vnic_name)
     return vnic_settings[0]
Exemplo n.º 39
0
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from oslo_config import cfg

from hyperv.common.i18n import _

HYPERV_AGENT_OPTS = [
    cfg.ListOpt(
        'physical_network_vswitch_mappings',
        default=[],
        help=_('List of <physical_network>:<vswitch> '
               'where the physical networks can be expressed with '
               'wildcards, e.g.: ."*:external"')),
    cfg.StrOpt(
        'local_network_vswitch',
        default='private',
        help=_('Private vswitch name used for local networks')),
    cfg.IntOpt('polling_interval', default=2,
               help=_("The number of seconds the agent will wait between "
                      "polling for local device changes.")),
    cfg.IntOpt('worker_count', default=10,
               help=_("The number of worker processes allowed to run in "
                      "parallel to process port binding.")),
    cfg.IntOpt('worker_retry', default=3,
               help=_("The number of times worker process will retry "
                      "port binding.")),
    cfg.BoolOpt('enable_metrics_collection',