From ab3239ecd7d50a55fc48df1b8bfd72c384fc6fd7 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 21 Sep 2015 13:04:52 -0400 Subject: [PATCH] added methods for retrieving vapp and vm --- lib/ansible/module_utils/vca.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/ansible/module_utils/vca.py b/lib/ansible/module_utils/vca.py index 2d4cd39d5b..b9ae66dda3 100644 --- a/lib/ansible/module_utils/vca.py +++ b/lib/ansible/module_utils/vca.py @@ -90,6 +90,20 @@ class VcaAnsibleModule(AnsibleModule): self._vdc = _vdc return _vdc + def get_vapp(self, vapp_name): + vapp = self.vca.get_vapp(self.vdc, vapp_name) + if not vapp: + raise VcaError('vca instance has no vapp named %s' % vapp_name) + return vapp + + def get_vm(self, vapp_name, vm_name): + vapp = self.get_vapp(vapp_name) + vms = [vm for vm in children.get_Vm() if vm.name == vm_name] + try: + return vms[0] + except IndexError: + raise VcaError('vapp has no vm named %s' % vm_name) + def create_instance(self): service_type = self.params.get('service_type', DEFAULT_SERVICE_TYPE) host = self.params.get('host', LOGIN_HOST.get('service_type'))