~blake-rouse/maas/add-system-to-node-html-js

« back to all changes in this revision

Viewing changes to src/maasserver/api.py

  • Committer: Blake Rouse
  • Date: 2014-05-14 13:07:13 UTC
  • Revision ID: blake.rouse@canonical.com-20140514130713-anvjhkj9mdmw0oto
Add osystem selection to NodeForm and start api.

Show diffs side-by-side

added added

removed removed

Lines of Context:
246
246
from piston.handler import typemapper
247
247
from piston.utils import rc
248
248
from provisioningserver.kernel_opts import KernelParameters
 
249
from provisioningserver.driver import (
 
250
    BOOT_IMAGE_PURPOSE,
 
251
    OperatingSystemRegistry,
 
252
    )
249
253
from provisioningserver.power_schema import UNKNOWN_POWER_TYPE
250
254
import simplejson as json
251
255
 
403
407
            available to the nodes through the metadata service.
404
408
        :type user_data: base64-encoded unicode
405
409
        :param distro_series: If present, this parameter specifies the
406
 
            Ubuntu Release the node will use.
 
410
            os relase the node will use.
407
411
        :type distro_series: unicode
408
412
 
409
413
        Ideally we'd have MIME multipart and content-transfer-encoding etc.
2321
2325
        context_instance=RequestContext(request))
2322
2326
 
2323
2327
 
2324
 
def get_boot_purpose(node):
 
2328
def get_boot_purpose(node, osystem, arch, subarch, series, label):
2325
2329
    """Return a suitable "purpose" for this boot, e.g. "install"."""
2326
2330
    # XXX: allenap bug=1031406 2012-07-31: The boot purpose is still in
2327
2331
    # flux. It may be that there will just be an "ephemeral" environment and
2341
2345
            if node.should_use_traditional_installer():
2342
2346
                return "install"
2343
2347
            else:
2344
 
                return "xinstall"
 
2348
                # Check that the booting operating system, actually supports
 
2349
                # fast-path installation. If it does not then, we need to
 
2350
                # return normal install.
 
2351
                osystem_obj = OperatingSystemRegistry[osystem]
 
2352
                purposes = osystem_obj.get_boot_image_purposes(
 
2353
                    arch, subarch, series, label)
 
2354
                if BOOT_IMAGE_PURPOSE.XINSTALL in purposes:
 
2355
                    return "xinstall"
 
2356
                return "install"
2345
2357
        else:
2346
2358
            return "local"  # TODO: Investigate.
2347
2359
    else:
2409
2421
    node = get_node_from_mac_string(request.GET.get('mac', None))
2410
2422
 
2411
2423
    if node is None or node.status == NODE_STATUS.COMMISSIONING:
 
2424
        osystem = Config.objects.get_config('commissioning_osystem')
2412
2425
        series = Config.objects.get_config('commissioning_distro_series')
2413
2426
    else:
 
2427
        osystem = node.get_osystem()
2414
2428
        series = node.get_distro_series()
2415
2429
 
2416
 
    purpose = get_boot_purpose(node)
2417
 
 
2418
2430
    if node:
2419
2431
        arch, subarch = node.architecture.split('/')
2420
2432
        preseed_url = compose_preseed_url(node)
2440
2452
                # current series. If nothing is found, fall back to i386 like
2441
2453
                # we used to. LP #1181334
2442
2454
                image = BootImage.objects.get_default_arch_image_in_nodegroup(
2443
 
                    nodegroup, 'ubuntu', series, purpose=purpose)
 
2455
                    nodegroup, osystem, series, purpose='commissioning')
2444
2456
                if image is None:
2445
2457
                    arch = 'i386'
2446
2458
                else:
2448
2460
 
2449
2461
        subarch = get_optional_param(request.GET, 'subarch', 'generic')
2450
2462
 
 
2463
    # Get the purpose, checking that if node is using xinstall, the operating
 
2464
    # system actaully supports that mode. We pass None for the label, here
 
2465
    # because it is unknown which label will be used yet.
 
2466
    purpose = get_boot_purpose(node, osystem, arch, subarch, series, None)
 
2467
 
2451
2468
    # We use as our default label the label of the most recent image for
2452
2469
    # the criteria we've assembled above. If there is no latest image
2453
2470
    # (which should never happen in reality but may happen in tests), we
2454
2471
    # fall back to using 'no-such-image' as our default.
2455
2472
    latest_image = BootImage.objects.get_latest_image(
2456
 
        nodegroup, 'ubuntu', arch, subarch, series, purpose)
 
2473
        nodegroup, osystem, arch, subarch, series, purpose)
2457
2474
    if latest_image is None:
2458
2475
        # XXX 2014-03-18 gmb bug=1294131:
2459
2476
        #     We really ought to raise an exception here so that client
2465
2482
        latest_label = latest_image.label
2466
2483
    label = get_optional_param(request.GET, 'label', latest_label)
2467
2484
 
 
2485
    # Now that we have the correct label, lets check the boot purpose again
 
2486
    # to make sure that the boot image with that label, is the correct purpose.
 
2487
    purpose = get_boot_purpose(node, osystem, arch, subarch, series, label)
 
2488
 
2468
2489
    if node is not None:
2469
2490
        # We don't care if the kernel opts is from the global setting or a tag,
2470
2491
        # just get the options
2494
2515
    cluster_address = get_mandatory_param(request.GET, "local")
2495
2516
 
2496
2517
    params = KernelParameters(
2497
 
        osystem='ubuntu', arch=arch, subarch=subarch, release=series,
 
2518
        osystem=osystem, arch=arch, subarch=subarch, release=series,
2498
2519
        label=label, purpose=purpose, hostname=hostname, domain=domain,
2499
2520
        preseed_url=preseed_url, log_host=server_address,
2500
2521
        fs_host=cluster_address, extra_opts=extra_kernel_opts)