~axwalk/juju-ci-tools/cli-model-owner

« back to all changes in this revision

Viewing changes to utility.py

  • Committer: Andrew Wilkins
  • Date: 2016-07-28 05:42:18 UTC
  • mfrom: (1477.3.1 juju-ci-tools)
  • Revision ID: andrew.wilkins@canonical.com-20160728054218-wjvxcwa2e8q3c4iv
Qualify model names with owner

When cloning an environment, make the
model name owner-qualified. This will
enable users to refer to others' models.

Show diffs side-by-side

added added

removed removed

Lines of Context:
486
486
        status = client.get_status()
487
487
        if charm not in status.get_applications():
488
488
            break
 
489
 
 
490
 
 
491
def unqualified_model_name(model_name):
 
492
    """Return the model name without the owner qualifier."""
 
493
    return model_name.split('/', 1)[-1]
 
494
 
 
495
 
 
496
def qualified_model_name(model_name, owner_name):
 
497
    """Return the model name qualified with the given owner name."""
 
498
    assert model_name != ''
 
499
    assert owner_name != ''
 
500
    parts = model_name.split('/', 1)
 
501
    if len(parts) == 2 and parts[0] != owner_name:
 
502
        raise ValueError(
 
503
            'qualified model name {} with owner not matching {}'.format(
 
504
                model_name, owner_name))
 
505
    return '{}/{}'.format(owner_name, parts[-1])