~barryprice/juju-deployer/resolve-OpenStack-1501-option-errors

« back to all changes in this revision

Viewing changes to deployer/utils.py

  • Committer: Tim Van Steenburgh
  • Date: 2016-07-12 02:29:52 UTC
  • Revision ID: tvansteenburgh@gmail.com-20160712022952-goqcezil57t1d400
juju-2.0beta11 compatibility

Show diffs side-by-side

added added

removed removed

Lines of Context:
427
427
        if x.name == placement:
428
428
            return True
429
429
    return False
 
430
 
 
431
 
 
432
class AlternateKeyDict(dict):
 
433
    def __getitem__(self, key):
 
434
        try:
 
435
            val = super(AlternateKeyDict, self).__getitem__(key)
 
436
            if isinstance(val, dict):
 
437
                return self.__class__(val)
 
438
            return val
 
439
        except KeyError:
 
440
            if key not in self.alternates:
 
441
                raise
 
442
 
 
443
            for alt in self.alternates[key]:
 
444
                if alt in self:
 
445
                    return self[alt]
 
446
            raise
 
447
 
 
448
    def get(self, key, default=None):
 
449
        try:
 
450
            return self.__getitem__(key)
 
451
        except KeyError:
 
452
            return default
 
453
 
 
454
    def values(self):
 
455
        for val in super(AlternateKeyDict, self).values():
 
456
            if isinstance(val, dict):
 
457
                yield self.__class__(val)
 
458
            else:
 
459
                yield val
 
460
 
 
461
    def items(self):
 
462
        for key, val in super(AlternateKeyDict, self).items():
 
463
            if isinstance(val, dict):
 
464
                yield key, self.__class__(val)
 
465
            else:
 
466
                yield key, val