Ejemplo n.º 1
0
    def get_server_ip(cls, server, validation_resources=None):
        """Get the server fixed or floating IP.

        Based on the configuration we're in, return a correct ip
        address for validating that a guest is up.

        :param server: The server dict as returned by the API
        :param validation_resources: The dict of validation resources
            provisioned for the server.
        """
        if CONF.validation.connect_method == 'floating':
            if validation_resources:
                return validation_resources['floating_ip']['ip']
            else:
                msg = ('When validation.connect_method equals floating, '
                       'validation_resources cannot be None')
                raise lib_exc.InvalidParam(invalid_param=msg)
        elif CONF.validation.connect_method == 'fixed':
            addresses = server['addresses'][CONF.validation.network_for_ssh]
            for address in addresses:
                if address['version'] == CONF.validation.ip_version_for_ssh:
                    return address['addr']
            raise exceptions.ServerUnreachable(server_id=server['id'])
        else:
            raise lib_exc.InvalidConfiguration()
Ejemplo n.º 2
0
    def get_server_ip(self, server):
        """Get the server fixed or floating IP.

        Based on the configuration we're in, return a correct ip
        address for validating that a guest is up.
        """
        if CONF.validation.connect_method == 'floating':
            # The tests calling this method don't have a floating IP
            # and can't make use of the validation resources. So the
            # method is creating the floating IP there.
            return self.create_floating_ip(server)['ip']
        elif CONF.validation.connect_method == 'fixed':
            # Determine the network name to look for based on config or creds
            # provider network resources.
            if CONF.validation.network_for_ssh:
                addresses = server['addresses'][
                    CONF.validation.network_for_ssh]
            else:
                creds_provider = self._get_credentials_provider()
                net_creds = creds_provider.get_primary_creds()
                network = getattr(net_creds, 'network', None)
                addresses = (server['addresses'][network['name']]
                             if network else [])
            for address in addresses:
                if (address['version'] == CONF.validation.ip_version_for_ssh
                        and address['OS-EXT-IPS:type'] == 'fixed'):
                    return address['addr']
            raise exceptions.ServerUnreachable(server_id=server['id'])
        else:
            raise lib_exc.InvalidConfiguration()
Ejemplo n.º 3
0
 def __init__(self,
              server,
              username,
              password=None,
              pkey=None,
              key_filename=None):
     ssh_timeout = CONF.validation.ssh_timeout
     network = CONF.compute.network_for_ssh
     ip_version = CONF.validation.ip_version_for_ssh
     connect_timeout = CONF.validation.connect_timeout
     if isinstance(server, six.string_types):
         ip_address = server
     else:
         addresses = server['addresses'][network]
         for address in addresses:
             if address['version'] == ip_version:
                 ip_address = address['addr']
                 break
         else:
             raise exceptions.ServerUnreachable()
     if CONF.compute.ssh_auth_method == 'keypair' and pkey == None:
         key_filename = CONF.compute.path_to_private_key if \
             CONF.compute.path_to_private_key else None
     self.ssh_client = ssh.Client(ip_address,
                                  username,
                                  password=None,
                                  timeout=ssh_timeout,
                                  pkey=pkey,
                                  key_filename=key_filename,
                                  channel_timeout=connect_timeout)
Ejemplo n.º 4
0
 def __init__(self,
              server,
              username,
              password=None,
              pkey=None,
              gws=None,
              keep_connection=True):
     LOG.info("Using our remote client...")
     ssh_timeout = CONF.compute.ssh_timeout
     network = CONF.compute.network_for_ssh
     ip_version = CONF.compute.ip_version_for_ssh
     ssh_channel_timeout = CONF.compute.ssh_channel_timeout
     if isinstance(server, six.string_types):
         ip_address = server
     else:
         addresses = server['addresses'][network]
         for address in addresses:
             if address['version'] == ip_version:
                 ip_address = address['addr']
                 break
         else:
             raise exceptions.ServerUnreachable()
     self.ssh_client = ssh.Client(ip_address,
                                  username,
                                  password,
                                  ssh_timeout,
                                  pkey=pkey,
                                  channel_timeout=ssh_channel_timeout,
                                  gws=gws,
                                  keep_connection=keep_connection)
Ejemplo n.º 5
0
    def get_server_ip(cls, server):
        """Get the server fixed or floating IP.

        Based on the configuration we're in, return a correct ip
        address for validating that a guest is up.
        """
        if CONF.validation.connect_method == 'floating':
            return cls.validation_resources['floating_ip']['ip']
        elif CONF.validation.connect_method == 'fixed':
            addresses = server['addresses'][CONF.validation.network_for_ssh]
            for address in addresses:
                if address['version'] == CONF.validation.ip_version_for_ssh:
                    return address['addr']
            raise exceptions.ServerUnreachable(server_id=server['id'])
        else:
            raise lib_exc.InvalidConfiguration()
Ejemplo n.º 6
0
 def __init__(self, server, username, password=None, pkey=None):
     ssh_timeout = CONF.compute.ssh_timeout
     network = CONF.compute.network_for_ssh
     ip_version = CONF.compute.ip_version_for_ssh
     ssh_channel_timeout = CONF.compute.ssh_channel_timeout
     if isinstance(server, basestring):
         ip_address = server
     else:
         addresses = server['addresses'][network]
         for address in addresses:
             if address['version'] == ip_version:
                 ip_address = address['addr']
                 break
         else:
             raise exceptions.ServerUnreachable()
     self.ssh_client = ssh.Client(ip_address,
                                  username,
                                  password,
                                  ssh_timeout,
                                  pkey=pkey,
                                  channel_timeout=ssh_channel_timeout)