Example #1
0
def parse_server_string(server_str):
    """Parses the given server_string and returns a tuple of host and port.
    If it's not a combination of host part and port, the port element
    is an empty string. If the input is invalid expression, return a tuple of
    two empty strings.
    """
    try:
        # First of all, exclude pure IPv6 address (w/o port).
        if netaddr.valid_ipv6(server_str):
            return (server_str, '')

        # Next, check if this is IPv6 address with a port number combination.
        if server_str.find("]:") != -1:
            (address, port) = server_str.replace('[', '', 1).split(']:')
            return (address, port)

        # Third, check if this is a combination of an address and a port
        if server_str.find(':') == -1:
            return (server_str, '')

        # This must be a combination of an address and a port
        (address, port) = server_str.split(':')
        return (address, port)

    except (ValueError, netaddr.AddrFormatError):
        LOG.error(_LE('Invalid server_string: %s'), server_str)
        return ('', '')
Example #2
0
 def run(self):
     try:
         self._copy()
     except IOError as err:
         self._stopped.set()
         # Invalid argument error means that the vm console pipe was closed,
         # probably the vm was stopped. The worker can stop it's execution.
         if err.errno != errno.EINVAL:
             LOG.error(_LE("Error writing vm console log file from " "serial console pipe. Error: %s") % err)
 def _get_conn_v2(self, host='localhost'):
     try:
         return wmi.WMI(moniker='//%s/root/virtualization/v2' % host)
     except wmi.x_wmi as ex:
         LOG.exception(_LE('Get version 2 connection error'))
         if ex.com_error.hresult == -2147217394:
             msg = (_('Live migration is not supported on target host "%s"')
                    % host)
         elif ex.com_error.hresult == -2147023174:
             msg = (_('Target live migration host "%s" is unreachable')
                    % host)
         else:
             msg = _('Live migration failed: %s') % ex.message
         raise exceptions.HyperVException(msg)
Example #4
0
    def set_switch_external_port_trunk_vlan(self, vswitch_name, vlan_id,
                                            desired_endpoint_mode):
        vswitch_external_port = self._get_vswitch_external_port(vswitch_name)
        if vswitch_external_port:
            vlan_endpoint = vswitch_external_port.associators(
                wmi_association_class=self._BINDS_TO)[0]
            vlan_endpoint_settings = vlan_endpoint.associators(
                wmi_result_class=self._VLAN_ENDPOINT_SET_DATA)[0]
            if vlan_id not in vlan_endpoint_settings.TrunkedVLANList:
                vlan_endpoint_settings.TrunkedVLANList += (vlan_id,)
                vlan_endpoint_settings.put()

            if (desired_endpoint_mode not in
                    vlan_endpoint.SupportedEndpointModes):
                LOG.error(_LE("'Trunk' VLAN endpoint mode is not supported by "
                              "the switch / physycal network adapter. Correct "
                              "this issue or use flat networks instead."))
                return
            if vlan_endpoint.DesiredEndpointMode != desired_endpoint_mode:
                vlan_endpoint.DesiredEndpointMode = desired_endpoint_mode
                vlan_endpoint.put()