/usr/lib/python2.7/dist-packages/provisioningserver/boot_images.py is in python-maas-provisioningserver 1.5.4+bzr2294-0ubuntu1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | # Copyright 2012-2014 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Dealing with boot images."""
from __future__ import (
absolute_import,
print_function,
unicode_literals,
)
str = None
__metaclass__ = type
__all__ = [
'report_to_server',
]
import json
from logging import getLogger
from apiclient.maas_client import (
MAASClient,
MAASDispatcher,
MAASOAuth,
)
from provisioningserver.auth import get_recorded_api_credentials
from provisioningserver.boot import tftppath
from provisioningserver.cluster_config import (
get_cluster_uuid,
get_maas_url,
)
from provisioningserver.config import BootConfig
logger = getLogger(__name__)
def get_cached_knowledge():
"""Return cached items required to report to the server.
:return: Tuple of cached items: (maas_url, api_credentials). Either may
be None if the information has not been received from the server yet.
"""
maas_url = get_maas_url()
if maas_url is None:
logger.debug("Not reporting boot images: don't have API URL yet.")
api_credentials = get_recorded_api_credentials()
if api_credentials is None:
logger.debug("Not reporting boot images: don't have API key yet.")
return maas_url, api_credentials
def submit(maas_url, api_credentials, images):
"""Submit images to server."""
path = 'api/1.0/nodegroups/%s/boot-images/' % get_cluster_uuid()
MAASClient(MAASOAuth(*api_credentials), MAASDispatcher(), maas_url).post(
path=path, op='report_boot_images', images=json.dumps(images))
def report_to_server():
"""For master worker only: report available netboot images."""
maas_url, api_credentials = get_cached_knowledge()
if not all([maas_url, api_credentials]):
return
images = tftppath.list_boot_images(
BootConfig.load_from_cache()['boot']['storage'] + '/current/')
submit(maas_url, api_credentials, images)
|