def get_stack_servers(heat_cli, nova, neutron, keystone, stack, project_name): """ Returns a list of VMInst domain objects associated with a Stack :param heat_cli: the OpenStack heat client object :param nova: the OpenStack nova client object :param neutron: the OpenStack neutron client object :param keystone: the OpenStack keystone client object :param stack: the SNAPS-OO Stack domain object :param project_name: the associated project ID :return: a list of VMInst domain objects """ out = list() srvr_res = get_resources(heat_cli, stack.id, 'OS::Nova::Server') workers = [] for resource in srvr_res: worker = worker_pool().apply_async( nova_utils.get_server_object_by_id, (nova, neutron, keystone, resource.id, project_name)) workers.append((resource.id, worker)) for worker in workers: resource_id = worker[0] try: server = worker[1].get() if server: out.append(server) except NotFound: logger.warn('VmInst cannot be located with ID %s', resource_id) res_grps = get_resources(heat_cli, stack.id, 'OS::Heat::ResourceGroup') for res_grp in res_grps: res_ress = get_resources(heat_cli, res_grp.id) workers = [] for res_res in res_ress: res_res_srvrs = get_resources(heat_cli, res_res.id, 'OS::Nova::Server') for res_srvr in res_res_srvrs: worker = worker_pool().apply_async( nova_utils.get_server_object_by_id, (nova, neutron, keystone, res_srvr.id, project_name)) workers.append(worker) for worker in workers: server = worker.get() if server: out.append(server) return out
def get_stack_flavors(heat_cli, nova, stack): """ Returns an instance of Flavor SNAPS domain object for each flavor created by this stack :param heat_cli: the OpenStack heat client object :param nova: the OpenStack cinder client object :param stack: the SNAPS-OO Stack domain object :return: a list of Volume domain objects """ out = list() resources = get_resources(heat_cli, stack.id, 'OS::Nova::Flavor') workers = [] for resource in resources: worker = worker_pool().apply_async(nova_utils.get_flavor_by_id, (nova, resource.id)) workers.append((resource.id, worker)) for worker in workers: resource_id = worker[0] try: flavor = worker[1].get() if flavor: out.append(flavor) except NotFound: logger.warn('Flavor cannot be located with ID %s', resource_id) return out
def get_stack_volume_types(heat_cli, cinder, stack): """ Returns an instance of VolumeType domain objects created by this stack :param heat_cli: the OpenStack heat client object :param cinder: the OpenStack cinder client object :param stack: the SNAPS-OO Stack domain object :return: a list of VolumeType domain objects """ out = list() resources = get_resources(heat_cli, stack.id, 'OS::Cinder::VolumeType') workers = [] for resource in resources: worker = worker_pool().apply_async(cinder_utils.get_volume_type_by_id, (cinder, resource.id)) workers.append((resource.id, worker)) for worker in workers: resource_id = worker[0] try: vol_type = worker[1].get() if vol_type: out.append(vol_type) except NotFound: logger.warn('VolumeType cannot be located with ID %s', resource_id) return out
def get_stack_keypairs(heat_cli, nova, stack): """ Returns a list of Keypair domain objects associated with a Stack :param heat_cli: the OpenStack heat client object :param nova: the OpenStack nova client object :param stack: the SNAPS-OO Stack domain object :return: a list of VMInst domain objects """ out = list() resources = get_resources(heat_cli, stack.id, 'OS::Nova::KeyPair') workers = [] for resource in resources: worker = worker_pool().apply_async(nova_utils.get_keypair_by_id, (nova, resource.id)) workers.append((resource.id, worker)) for worker in workers: resource_id = worker[0] try: keypair = worker[1].get() if keypair: out.append(keypair) except NotFound: logger.warn('Keypair cannot be located with ID %s', resource_id) return out
def get_vm_inst_creators(self, heat_keypair_option=None): """ Returns a list of VM Instance creator objects as configured by the heat template :return: list() of OpenStackVmInstance objects """ out = list() stack_servers = heat_utils.get_stack_servers( self.__heat_cli, self.__nova, self.__neutron, self._keystone, self.__stack, self._os_creds.project_name) workers = [] for stack_server in stack_servers: worker = worker_pool().apply_async( self.__create_vm_inst, (heat_keypair_option, stack_server)) workers.append(worker) for worker in workers: out.append(worker.get()) return out
def get_stack_security_groups(heat_cli, neutron, stack): """ Returns a list of SecurityGroup domain objects deployed by this stack :param heat_cli: the OpenStack heat client object :param neutron: the OpenStack neutron client object :param stack: the SNAPS-OO Stack domain object :return: a list of SecurityGroup objects """ out = list() resources = get_resources(heat_cli, stack.id, 'OS::Neutron::SecurityGroup') workers = [] for resource in resources: worker = worker_pool().apply_async( neutron_utils.get_security_group_by_id, (neutron, resource.id)) workers.append(worker) for worker in workers: security_group = worker.get() if security_group: out.append(security_group) return out
def get_stack_routers(heat_cli, neutron, stack): """ Returns a list of Network domain objects deployed by this stack :param heat_cli: the OpenStack heat client object :param neutron: the OpenStack neutron client object :param stack: the SNAPS-OO Stack domain object :return: a list of Network objects """ out = list() resources = get_resources(heat_cli, stack.id, 'OS::Neutron::Router') workers = [] for resource in resources: worker = worker_pool().apply_async(neutron_utils.get_router_by_id, (neutron, resource.id)) workers.append(worker) for worker in workers: router = worker.get() if router: out.append(router) return out