#!/usr/bin/env python2
# This must be run as root because I can't figure out how to switch the
# effective django user during database access. However, it should bootstrap
# the rest of itself.

import os
import sys

sys.path.extend(['/etc/maas', '/usr/share/maas'])
os.environ['MAAS_URL'] = 'http://localhost/MAAS'
os.environ['DJANGO_SETTINGS_MODULE'] = 'maas.settings'

from maasserver.models.nodegroup import NodeGroup
from provisioningserver import cache, auth, tasks

cluster = NodeGroup.objects.first()
os.environ['CLUSTER_UUID'] = cluster.uuid

creds = '%s:%s:%s' % (
    cluster.api_token.consumer.key, cluster.api_token.key,
    cluster.api_token.secret)

cache.initialize()
auth.record_api_credentials(creds)
tasks.report_boot_images()
