Extracting generator objects returned by openstack actions

Change-Id: Ia2956295d4c9773b6203904699a2ae6ecf245348
This commit is contained in:
Renat Akhmerov 2015-10-16 15:12:50 +06:00
parent 6231073ec2
commit d39a59f473
2 changed files with 7 additions and 15 deletions

View File

@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import inspect
from cinderclient.v1 import client as cinderclient from cinderclient.v1 import client as cinderclient
from glanceclient.v2 import client as glanceclient from glanceclient.v2 import client as glanceclient
from heatclient.v1 import client as heatclient from heatclient.v1 import client as heatclient
@ -26,7 +24,6 @@ from oslo_log import log
from mistral.actions.openstack import base from mistral.actions.openstack import base
from mistral import context from mistral import context
from mistral import exceptions as exc
from mistral.utils.openstack import keystone as keystone_utils from mistral.utils.openstack import keystone as keystone_utils
@ -152,17 +149,6 @@ class HeatAction(base.OpenStackAction):
def _get_fake_client(cls): def _get_fake_client(cls):
return cls._client_class("") return cls._client_class("")
def run(self):
try:
method = self._get_client_method(self._get_client())
result = method(**self._kwargs_for_run)
if inspect.isgenerator(result):
return [v for v in result]
return result
except Exception as e:
raise exc.ActionException("%s failed: %s"
% (self.__class__.__name__, e))
class NeutronAction(base.OpenStackAction): class NeutronAction(base.OpenStackAction):
_client_class = neutronclient.Client _client_class = neutronclient.Client

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import abc import abc
import inspect
from mistral.actions import base from mistral.actions import base
from mistral import exceptions as exc from mistral import exceptions as exc
@ -69,7 +70,12 @@ class OpenStackAction(base.Action):
try: try:
method = self._get_client_method(self._get_client()) method = self._get_client_method(self._get_client())
return method(**self._kwargs_for_run) result = method(**self._kwargs_for_run)
if inspect.isgenerator(result):
return [v for v in result]
return result
except Exception as e: except Exception as e:
e_str = '%s: %s' % (type(e), e.message) e_str = '%s: %s' % (type(e), e.message)