コード例 #1
0
ファイル: osystems.py プロジェクト: ocni-dtu/maas
def validate_license_key(osystem, release, key):
    """Validate license key for the given OS and release.

    Checks all rack controllers to determine if the license key is valid. Only
    one rack controller has to say the license key is valid.

    :param osystem: The name of the operating system.
    :param release: The release for the operating system.
    :param key: The license key to validate.

    :return: True if valid, False otherwise.
    """
    responses = asynchronous.gather(
        partial(
            client,
            ValidateLicenseKey,
            osystem=osystem,
            release=release,
            key=key,
        ) for client in getAllClients())

    # Only one cluster needs to say the license key is valid, for it
    # to considered valid. Must go through all responses so they are all
    # marked handled.
    is_valid = False
    for response in suppress_failures(responses):
        is_valid = is_valid or response["is_valid"]
    return is_valid
コード例 #2
0
ファイル: test_asynchronous.py プロジェクト: zhangrb/maas
 def test_gather_from_calls_without_errors(self):
     values = [
         self.getUniqueInteger(),
         self.getUniqueString(),
     ]
     calls = [self.wrap(lambda v=value: v) for value in values]
     results = list(asynchronous.gather(calls))
     self.assertItemsEqual(values, results)
コード例 #3
0
ファイル: test_asynchronous.py プロジェクト: zhangrb/maas
 def test_gather_nothing(self):
     time_before = time()
     results = list(asynchronous.gather([], timeout=10))
     time_after = time()
     self.assertThat(results, Equals([]))
     # gather() should return well within 9 seconds; this shows
     # that the call is not timing out.
     self.assertThat(time_after - time_before, LessThan(9))
コード例 #4
0
ファイル: test_asynchronous.py プロジェクト: tai271828/maas
    def test_gather_from_calls_with_errors(self):
        calls = [(lambda: sentinel.okay), (lambda: 1 / 0)]  # ZeroDivisionError
        calls = [self.wrap(call) for call in calls]
        results = list(asynchronous.gather(calls))

        self.assertThat(results, Contains(sentinel.okay))
        results.remove(sentinel.okay)
        self.assertThat(results, HasLength(1))
        failure = results[0]
        self.assertThat(failure, IsInstance(Failure))
        self.assertThat(failure.type, Is(ZeroDivisionError))
コード例 #5
0
def _get_available_boot_images():
    """Obtain boot images available on connected rack controllers."""
    listimages_v1 = lambda client: partial(client, ListBootImages)
    listimages_v2 = lambda client: partial(client, ListBootImagesV2)
    clients_v2 = getAllClients()
    responses_v2 = gather(map(listimages_v2, clients_v2))
    clients_v1 = []
    for i, response in enumerate(responses_v2):
        if (isinstance(response, Failure)
                and response.check(UnhandledCommand) is not None):
            clients_v1.append(clients_v2[i])
        elif not isinstance(response, Failure):
            # Convert each image to a frozenset of its items.
            yield frozenset(
                frozenset(image.items()) for image in response["images"])
    responses_v1 = gather(map(listimages_v1, clients_v1))
    for response in suppress_failures(responses_v1):
        # Convert each image to a frozenset of its items.
        yield frozenset(
            frozenset(image.items()) for image in response["images"])
コード例 #6
0
ファイル: boot_images.py プロジェクト: casual-lemon/maas
def _get_available_boot_images():
    """Obtain boot images available on connected rack controllers."""
    def listimages(client):
        return partial(client, ListBootImages)

    clients = getAllClients()
    responses = gather(map(listimages, clients))
    for i, response in enumerate(responses):
        if not isinstance(response, Failure):
            # Convert each image to a frozenset of its items.
            yield frozenset(
                frozenset(image.items()) for image in response["images"])
コード例 #7
0
ファイル: boot_images.py プロジェクト: casual-lemon/maas
def is_import_boot_images_running():
    """Return True if any rack controller is currently import boot images."""
    responses = gather(
        partial(client, IsImportBootImagesRunning)
        for client in getAllClients())

    # Only one rack controller needs to say its importing image, for this
    # method to return True. Must go through all responses so they are all
    # marked handled.
    running = False
    for response in suppress_failures(responses):
        running = running or response["running"]
    return running
コード例 #8
0
ファイル: osystems.py プロジェクト: ocni-dtu/maas
def gen_all_known_operating_systems():
    """Generator yielding details on OSes supported by any cluster.

    Each item yielded takes the same form as the ``osystems`` value from
    the :py:class:`provisioningserver.rpc.cluster.ListOperatingSystems`
    RPC command. Exactly matching duplicates are suppressed.
    """
    seen = defaultdict(list)
    responses = asynchronous.gather(
        partial(client, ListOperatingSystems) for client in getAllClients())
    for response in suppress_failures(responses):
        for osystem in response["osystems"]:
            name = osystem["name"]
            if osystem not in seen[name]:
                seen[name].append(osystem)
                if name == "custom":
                    osystem = fix_custom_osystem_release_titles(osystem)
                yield osystem