~sinzui/juju-ci-tools/cloudsigma-lib

« back to all changes in this revision

Viewing changes to jujupy.py

  • Committer: Nate Finch
  • Date: 2015-06-02 03:47:22 UTC
  • mfrom: (968 origin/trunk)
  • mto: This revision was merged to the branch mainline in revision 976.
  • Revision ID: nate.finch@canonical.com-20150602034722-cr3lzq2yb6xdh7gz
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
            return EnvJujuClient24(env, version, full_path, debug=debug)
178
178
        elif re.match('^1\.24[.-]', version):
179
179
            return EnvJujuClient24(env, version, full_path, debug=debug)
 
180
        elif re.match('^1\.25[.-]', version):
 
181
            return EnvJujuClient25(env, version, full_path, debug=debug)
180
182
        else:
181
183
            return EnvJujuClient(env, version, full_path, debug=debug)
182
184
 
191
193
        else:
192
194
            prefix = ('timeout', '%.2fs' % timeout)
193
195
        logging = '--debug' if self.debug else '--show-log'
194
 
        if command == "action":
 
196
                command = command.split()
 
197
        if command[0] == "action":
195
198
            # action requires the -e after the action subcommand, so just
196
199
            # put it at the end.
197
 
            return prefix + ('juju', logging, command,) + args + e_arg
198
 
        return prefix + ('juju', logging, command,) + e_arg + args
 
200
            return prefix + ('juju', logging,) + tuple(command) + args + e_arg
 
201
        return prefix + ('juju', logging,) + tuple(command) + e_arg + args
199
202
 
200
203
    def __init__(self, env, version, full_path, debug=False):
201
204
        if env is None:
341
344
            args.extend(['--repository', repository])
342
345
        return self.juju('deploy', tuple(args))
343
346
 
344
 
    def deployer(self, bundle):
 
347
    def deployer(self, bundle, name=None):
345
348
        """deployer, using sudo if necessary."""
346
349
        args = (
347
350
            '--debug',
348
351
            '--deploy-delay', '10',
349
352
            '--config', bundle,
350
353
        )
 
354
        if name:
 
355
            args += (name,)
351
356
        self.juju('deployer', args, self.env.needs_sudo())
352
357
 
353
358
    def quickstart(self, bundle, upload_tools=False):
555
560
        return env
556
561
 
557
562
 
558
 
class EnvJujuClient24(EnvJujuClient):
 
563
class EnvJujuClient25(EnvJujuClient):
559
564
 
560
565
    def _shell_environ(self, juju_home=None):
561
566
        """Generate a suitable shell environment.
562
567
 
563
568
        Juju's directory must be in the PATH to support plugins.
564
569
        """
565
 
        env = super(EnvJujuClient24, self)._shell_environ(juju_home)
 
570
        env = super(EnvJujuClient25, self)._shell_environ(juju_home)
566
571
        if self.env.config.get('type') == 'cloudsigma':
567
572
            if env.get(JUJU_DEV_FEATURE_FLAGS, '') == '':
568
573
                env[JUJU_DEV_FEATURE_FLAGS] = 'cloudsigma'
571
576
        return env
572
577
 
573
578
 
 
579
class EnvJujuClient24(EnvJujuClient25):
 
580
    """Currently, same feature set as juju 25"""
 
581
 
 
582
 
574
583
def get_local_root(juju_home, env):
575
584
    return os.path.join(juju_home, env.environment)
576
585
 
718
727
        for service in sorted(self.status['services'].values()):
719
728
            for unit_name, unit in service.get('units', {}).items():
720
729
                yield unit_name, unit
 
730
                for sub_name, sub in unit.get('subordinates', {}).items():
 
731
                    yield sub_name, sub
721
732
 
722
733
    def agent_states(self):
723
734
        """Map agent states to the units and machines in those states."""
765
776
                return service['units'][unit_name]
766
777
        raise KeyError(unit_name)
767
778
 
 
779
    def get_subordinate_units(self, service_name):
 
780
        """Return subordinate metadata for a service_name."""
 
781
        subordinates = []
 
782
        services = self.status.get('services', {})
 
783
        if service_name in services.keys():
 
784
            for unit in sorted(services[service_name].get(
 
785
                    'units', {}).values()):
 
786
                subordinates.append(unit.get('subordinates', {}))
 
787
            return subordinates
 
788
        raise KeyError(service_name)
 
789
 
768
790
    def get_open_ports(self, unit_name):
769
791
        """List the open ports for the specified unit.
770
792