Refactor profile set_ methods

There's a lot of duplication in the set_ methods on Profile, so this
change breaks them down and puts the common parts together.

Change-Id: I317677eeb82baa57c809df1df84e0afc6d403364
This commit is contained in:
Brian Curtin 2016-01-26 16:15:17 -06:00
parent 3b727151bc
commit 917c311690

View File

@ -148,6 +148,13 @@ class Profile(object):
(service, self.service_keys)) (service, self.service_keys))
raise exceptions.SDKException(msg) raise exceptions.SDKException(msg)
def _get_services(self, service):
return self.service_keys if service == self.ALL else [service]
def _setter(self, service, attr, value):
for service in self._get_services(service):
setattr(self._get_filter(service), attr, value)
def get_services(self): def get_services(self):
"""Get a list of all the known services.""" """Get a list of all the known services."""
services = [] services = []
@ -161,12 +168,7 @@ class Profile(object):
:param str service: Service type. :param str service: Service type.
:param str name: Desired service name. :param str name: Desired service name.
""" """
if service == self.ALL: self._setter(service, "service_name", name)
services = self.service_keys
else:
services = [service]
for service in services:
self._get_filter(service).service_name = name
def set_region(self, service, region): def set_region(self, service, region):
"""Set the desired region for the specified service. """Set the desired region for the specified service.
@ -174,12 +176,7 @@ class Profile(object):
:param str service: Service type. :param str service: Service type.
:param str region: Desired service region. :param str region: Desired service region.
""" """
if service == self.ALL: self._setter(service, "region", region)
services = self.service_keys
else:
services = [service]
for service in services:
self._get_filter(service).region = region
def set_version(self, service, version): def set_version(self, service, version):
"""Set the desired version for the specified service. """Set the desired version for the specified service.
@ -195,9 +192,4 @@ class Profile(object):
:param str service: Service type. :param str service: Service type.
:param str interface: Desired service interface. :param str interface: Desired service interface.
""" """
if service == self.ALL: self._setter(service, "interface", interface)
services = self.service_keys
else:
services = [service]
for service in services:
self._get_filter(service).interface = interface