~frankban/juju-quickstart/interactive-errors

« back to all changes in this revision

Viewing changes to quickstart/models/envs.py

  • Committer: Francesco Banconi
  • Date: 2014-10-10 13:47:08 UTC
  • mfrom: (100.1.11 maas-detect)
  • Revision ID: francesco.banconi@canonical.com-20141010134708-4zu3585o1p9pmwtl
Support automatic detection of a logged in MAAS.

Automatically detect a logged in MAAS API, so that
it is possible to use the stored credentials to 
create and bootstrap a MAAS environment without
user intervention.

QA:
- ssh to the GUI MAAS;
- destroy the existing environment;
- remove the ~/.juju directory;
- use the MAAS UI (http://maas.jujugui.org/MAAS/nodes/)
  to release the nodes if they are not in a ready state;
- this branch is already checked out in ~/juju-quickstart/sandbox/;
- start quickstart from there:
  cd ~/juju-quickstart/sandbox/ && .venv/bin/python juju-quickstart
- quickstart should show the option to automatically create and
  bootstrap the MAAS environment;
- select the option and wait for the envirnment to be ready:
  this can fail due to juju/maas interaction problems we currently
  have, retrying the process should eventually succeed.

Done, thank you!

R=bac, jay.wren
CC=
https://codereview.appspot.com/157830043

Show diffs side-by-side

added added

removed removed

Lines of Context:
338
338
 
339
339
 
340
340
def create_local_env_data(env_type_db, name, is_default=False):
341
 
    """Create and return an local (LXC) env_data.
 
341
    """Create and return a local (LXC) env_data.
342
342
 
343
343
    Local environments' fields (except for name and type) are assumed to be
344
344
    either optional or suitable for automatic generation of their values. For
367
367
    return env_data
368
368
 
369
369
 
 
370
def create_maas_env_data(env_type_db, name, server, api_key, is_default=False):
 
371
    """Create and return a MAAS (bare metal) env_data.
 
372
 
 
373
    The env_data is created using the given name, MAAS server and MAAS OAuth
 
374
    API key.
 
375
    """
 
376
    env_data = {
 
377
        'type': 'maas',
 
378
        'name': name,
 
379
        'is-default': is_default,
 
380
        'maas-server': server,
 
381
        'maas-oauth': api_key,
 
382
    }
 
383
    env_metadata = get_env_metadata(env_type_db, env_data)
 
384
    # Retrieve a list of missing required fields.
 
385
    missing_fields = [
 
386
        field for field in env_metadata['fields']
 
387
        if field.required and field.name not in env_data]
 
388
    # Assume all missing fields can be automatically generated.
 
389
    env_data.update((field.name, field.generate()) for field in missing_fields)
 
390
    return env_data
 
391
 
 
392
 
370
393
def remove_env(env_db, env_name):
371
394
    """Remove the environment named env_name from the environments database.
372
395