~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to jujuci.py

  • Committer: Curtis Hovey
  • Date: 2015-12-04 15:35:31 UTC
  • mto: This revision was merged to the branch mainline in revision 1168.
  • Revision ID: curtis@canonical.com-20151204153531-gyhv0uix87mwcypq
Attempt to delete machines stuck in provisioning. Explain when it must be done in the Joyent UI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from deploy_stack import destroy_environment
19
19
from jujuconfig import NoSuchEnvironment
20
20
from jujupy import (
21
 
    client_from_config,
 
21
    SimpleEnvironment,
 
22
    EnvJujuClient,
22
23
)
23
24
try:
24
25
    from lsb_release import get_distro_information
30
31
    extract_deb,
31
32
    get_deb_arch,
32
33
    get_revision_build,
33
 
    print_now,
34
34
    )
35
35
 
36
36
 
45
45
Artifact = namedtuple('Artifact', ['file_name', 'location'])
46
46
 
47
47
 
 
48
def print_now(string):
 
49
    print(string)
 
50
 
 
51
 
48
52
Credentials = namedtuple('Credentials', ['user', 'password'])
49
53
 
50
54
 
222
226
 
223
227
def clean_environment(env_name, verbose=False):
224
228
    try:
225
 
        client = client_from_config(env_name, None)
 
229
        env = SimpleEnvironment.from_config(env_name)
226
230
    except NoSuchEnvironment as e:
227
231
        # Nothing to do.
228
232
        if verbose:
229
233
            print_now(str(e))
230
234
        return False
 
235
    client = EnvJujuClient.by_version(env)
231
236
    if verbose:
232
237
        print_now("Destroying %s" % env_name)
233
238
    destroy_environment(client, env_name)
453
458
    try:
454
459
        args, credentials = parse_args(argv)
455
460
    except CredentialsMissing as e:
456
 
        print_now(e)
 
461
        print(e)
457
462
        sys.exit(2)
458
463
    try:
459
464
        if args.command == 'list':
470
475
                args.path, env=args.clean_env,
471
476
                dry_run=args.dry_run, verbose=args.verbose)
472
477
        elif args.command == 'get-juju-bin':
473
 
            print_now(get_juju_bin(credentials, args.workspace))
 
478
            print(get_juju_bin(credentials, args.workspace))
474
479
        elif args.command == 'get-certification-bin':
475
480
            path = get_certification_bin(credentials, args.version,
476
481
                                         args.workspace)
477
 
            print_now(path)
 
482
            print(path)
478
483
        elif args.command == 'get-build-vars':
479
484
            text = get_buildvars(
480
485
                credentials, args.build, env=args.env,
482
487
                version=args.version, short_branch=args.short_branch,
483
488
                short_revision=args.short_revision,
484
489
                branch=args.branch, revision=args.revision)
485
 
            print_now(text)
 
490
            print(text)
486
491
        elif args.command == 'get-package-name':
487
 
            print_now(PackageNamer.factory().get_release_package(args.version))
 
492
            print(PackageNamer.factory().get_release_package(args.version))
488
493
 
489
494
    except Exception as e:
490
 
        print_now(e)
 
495
        print(e)
491
496
        if args.verbose:
492
497
            traceback.print_tb(sys.exc_info()[2])
493
498
        return 2
494
499
    if args.verbose:
495
 
        print_now("Done.")
 
500
        print("Done.")
496
501
    return 0
497
502
 
498
503