コード例 #1
0
ファイル: api.py プロジェクト: koomar/kingpin
    def find_server_arrays(self, name, exact=True):
        """Search for a list of ServerArray by name and return the resources.

        Args:
            name: RightScale ServerArray Name
            exact: Return a single exact match, or multiple matching resources.

        Returns:
            <rightscale.Resource object(s)>
        """
        log.debug('Searching for ServerArrays matching: %s (exact match: %s)' %
                  (name, exact))

        found_arrays = rightscale_util.find_by_name(
            self._client.server_arrays, name, exact=exact)

        if not found_arrays:
            log.debug('ServerArray matching "%s" not found' % name)
            return

        if isinstance(found_arrays, list):
            names = [s.soul['name'] for s in found_arrays]
        else:
            names = [found_arrays.soul['name']]

        log.debug('Got ServerArray(s): %s' % ', '.join(names))

        return found_arrays
コード例 #2
0
ファイル: api.py プロジェクト: rajibmitra/kingpin
    def find_server_arrays(self, name, exact=True):
        """Search for a list of ServerArray by name and return the resources.

        Args:
            name: RightScale ServerArray Name
            exact: Return a single exact match, or multiple matching resources.

        Returns:
            <rightscale.Resource object(s)>
        """
        log.debug('Searching for ServerArrays matching: %s (exact match: %s)' %
                  (name, exact))

        found_arrays = rightscale_util.find_by_name(self._client.server_arrays,
                                                    name,
                                                    exact=exact)

        if not found_arrays:
            log.debug('ServerArray matching "%s" not found' % name)
            return

        if isinstance(found_arrays, list):
            names = [s.soul['name'] for s in found_arrays]
        else:
            names = [found_arrays.soul['name']]

        log.debug('Got ServerArray(s): %s' % ', '.join(names))

        return found_arrays
コード例 #3
0
def test_find_by_name_returns_none():
    """
    find_by_name() should return none for no results
    """
    # empty set
    col = mock.MagicMock()
    col.index.return_value = []
    ret = find_by_name(col, 'dummy')
    assert ret is None

    # non-empty, but no matches
    nada = mock.MagicMock()
    nada.soul = {'name': 'nada'}
    col = mock.MagicMock()
    col.index.return_value = [nada, nada, nada]
    ret = find_by_name(col, 'dummy', exact=True)
    assert ret is None
コード例 #4
0
def test_not_exact_return_all():
    """
    find_by_name() should return all matches when not exact
    """
    nada = mock.MagicMock()
    nada.soul = {'name': 'nada'}
    exp = [nada, nada, nada]
    col = mock.MagicMock()
    col.index.return_value = exp
    ret = find_by_name(col, 'dummy', exact=False)
    assert exp == ret
コード例 #5
0
def test_return_exact_of_multiple():
    """
    find_by_name() should return exact match when multiple found
    """
    exp_name = 'dummy'
    exact = mock.MagicMock()
    exact.soul = {'name': exp_name}
    notme = mock.MagicMock()
    notme.soul = {'name': 'not me'}
    col = mock.MagicMock()
    col.index.return_value = [notme, exact, notme]
    ret = find_by_name(col, exp_name)
    assert exact == ret
コード例 #6
0
ファイル: api.py プロジェクト: koomar/kingpin
    def find_right_script(self, name):
        """Search for a RightScript by-name and return the resource.

        Args:
            name: RightScale RightScript Name

        Return:
            rightscale.Resource object
        """
        log.debug('Searching for RightScript matching: %s' % name)
        found_script = rightscale_util.find_by_name(
            self._client.right_scripts, name, exact=True)

        if not found_script:
            log.debug('RightScript matching "%s" could not be found.' % name)
            return

        log.debug('Got RightScript: %s' % found_script)

        return found_script
コード例 #7
0
ファイル: api.py プロジェクト: rajibmitra/kingpin
    def find_right_script(self, name):
        """Search for a RightScript by-name and return the resource.

        Args:
            name: RightScale RightScript Name

        Return:
            rightscale.Resource object
        """
        log.debug('Searching for RightScript matching: %s' % name)
        found_script = rightscale_util.find_by_name(self._client.right_scripts,
                                                    name,
                                                    exact=True)

        if not found_script:
            log.debug('RightScript matching "%s" could not be found.' % name)
            return

        log.debug('Got RightScript: %s' % found_script)

        return found_script