def _list_resources(self, resource, resource_list_attempts=None, raise_exception=False, poll_interval=None, params_kwargs=None, timeout=None, use_over_limit_retry=False): """ @summary: Lists resources and verifies the response is the expected @param resource: type of resource for ex. network, subnet, port, etc. See NeutronResource in the networks constants @type resource: resource instance with singular and plural forms @param resource_list_attempts: number of API retries @type resource_list_attempts: int @param raise_exception: flag to raise an exception if the resource list was not as expected or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @param params_kwargs: key value params to filter by the list results @type params_kwargs: dict @param timeout: resource list timeout for over limit retries @type timeout: int @param use_over_limit_retry: flag to enable/disable the list over limits retries @type use_over_limit_retry: bool @return: NetworkingResponse object with api response and failure list @rtype: common.behaviors.NetworkingResponse """ # Defining the resource type in plural form (for ex. networks) resource_type = resource.plural poll_interval = poll_interval or self.config.api_poll_interval resource_list_attempts = (resource_list_attempts or self.config.api_retries) use_over_limit_retry = (use_over_limit_retry or self.config.use_over_limit_retry) timeout = timeout or self.config.resource_get_timeout result = NetworkingResponse() err_msg = '{0} list failure'.format(resource_type) for attempt in range(resource_list_attempts): self._log.debug( 'Attempt {attempt_n} of {attempts} with {resource_type} ' 'list'.format(attempt_n=attempt + 1, attempts=resource_list_attempts, resource_type=resource_type)) list_fn_name = 'list_{0}'.format(resource_type) resp = getattr(self.client, list_fn_name)(**params_kwargs) if use_over_limit_retry: entity_too_large_status_code = (getattr( self.response_codes, 'REQUEST_ENTITY_TOO_LARGE')) if resp.status_code == entity_too_large_status_code: fn_kwargs = params_kwargs resp = self.__over_limit_retry( resource_type=resource_type, timeout=timeout, poll_interval=poll_interval, status_code=entity_too_large_status_code, resp=resp, fn_name=list_fn_name, fn_kwargs=fn_kwargs) response_code = list_fn_name.upper() status_code = getattr(self.response_codes, response_code) resp_check = self.check_response(resp=resp, status_code=status_code, label='', message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the list was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to LIST {resource_type} after {attempts} attempts: ' '{failures}').format(resource_type=resource_type, attempts=resource_list_attempts, failures=result.failures) self._log.error(err_msg) if raise_exception: raise ResourceListException(err_msg) return result
def list_security_group_rules(self, security_group_rule_id=None, security_group_id=None, direction=None, ethertype=None, protocol=None, port_range_min=None, port_range_max=None, remote_group_id=None, remote_ip_prefix=None, tenant_id=None, limit=None, marker=None, page_reverse=None, resource_list_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Lists security group rules, filtered by params if given @param security_group_rule_id: security group rule ID to filter by @type security_group_rule_id: string @param security_group_id: The security group ID to filter by @type security_group_id: string @param direction: direction to filter by @type direction: string @param ethertype: IPv4 or IPv6 ethertype to filter by @type ethertype: string @param protocol: protocol like tcp, udp, or icmp to filter by @type protocol: string @param port_range_min: The minimum port number to filter by @type port_range_min: int @param port_range_max: The maximum port number to filter by @type port_range_max: int @param remote_group_id: The remote group ID filter by @type remote_group_id: string @param remote_ip_prefix: The remote IP prefix to filter by @type remote_ip_prefix: string @param tenant_id: security group rule tenant ID to filter by @type tenant_id: string @param limit: page size @type limit: int @param marker: Id of the last item of the previous page @type marker: string @param page_reverse: direction of the page @type page_reverse: bool @param resource_list_attempts: number of API retries @type resource_list_attempts: int @param raise_exception: flag to raise an exception if the list Security Groups Rules was not as expected or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @return: NetworkingResponse object with api response and failure list @rtype: common.behaviors.NetworkingResponse """ poll_interval = poll_interval or self.config.api_poll_interval resource_list_attempts = (resource_list_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Rules List failure' for attempt in range(resource_list_attempts): self._log.debug( 'Attempt {0} of {1} with security group rules list'.format( attempt + 1, resource_list_attempts)) resp = self.client.list_security_group_rules( security_group_rule_id=security_group_rule_id, security_group_id=security_group_id, direction=direction, ethertype=ethertype, protocol=protocol, port_range_min=port_range_min, port_range_max=port_range_max, remote_group_id=remote_group_id, remote_ip_prefix=remote_ip_prefix, tenant_id=tenant_id, limit=limit, marker=marker, page_reverse=page_reverse) status_code = SecurityGroupsResponseCodes.LIST_SECURITY_GROUP_RULES resp_check = self.check_response(resp=resp, status_code=status_code, label='', message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the list was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to LIST security group rules after {0} attempts: ' '{1}').format(resource_list_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceListException(err_msg) return result
def list_security_groups(self, security_group_id=None, name=None, description=None, tenant_id=None, limit=None, marker=None, page_reverse=None, resource_list_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Lists security groups, filtered by params if given @param security_group_id: The UUID for the security group to filter by @type security_group_id: string @param name: name for the security group to filter by @type name: string @param description: security group description to filter by @type description: string @param tenant_id: security group tenant ID to filter by @type tenant_id: string @param limit: page size @type limit: int @param marker: Id of the last item of the previous page @type marker: string @param page_reverse: direction of the page @type page_reverse: bool @param resource_list_attempts: number of API retries @type resource_list_attempts: int @param raise_exception: flag to raise an exception if the list Security Groups was not as expected or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @return: NetworkingResponse object with api response and failure list @rtype: common.behaviors.NetworkingResponse """ poll_interval = poll_interval or self.config.api_poll_interval resource_list_attempts = (resource_list_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group List failure' for attempt in range(resource_list_attempts): self._log.debug( 'Attempt {0} of {1} with security groups list'.format( attempt + 1, resource_list_attempts)) resp = self.client.list_security_groups( security_group_id=security_group_id, name=name, description=description, tenant_id=tenant_id, limit=limit, marker=marker, page_reverse=page_reverse) resp_check = self.check_response( resp=resp, status_code=SecurityGroupsResponseCodes.LIST_SECURITY_GROUPS, label='', message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the list was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to LIST security groups after {0} attempts: ' '{1}').format(resource_list_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceListException(err_msg) return result
def list_ports(self, port_id=None, network_id=None, name=None, status=None, admin_state_up=None, device_id=None, tenant_id=None, device_owner=None, mac_address=None, limit=None, marker=None, page_reverse=None, resource_list_attempts=None, raise_exception=False, poll_interval=None, timeout=None, use_over_limit_retry=None): """ @summary: Lists ports and verifies the response is the expected @param port_id: The UUID for the port to filter by @type port_id: string @param network_id: network ID to filter by @type network_id: string @param name: port name to filter by @type name: string @param status: port status to filter by @type status: string @param admin_state_up: Admin state of the port to filter by @type admin_state_up: bool @param device_id: id of device to filter by @type device_id: string @param tenant_id: owner of the port to filter by @type tenant_id: string @param device_owner: device owner to filter by @type device_owner: string @param mac_address: mac address to filter by @type mac_address: string @param limit: page size @type limit: int @param marker: Id of the last item of the previous page @type marker: string @param page_reverse: direction of the page @type page_reverse: bool @param resource_list_attempts: number of API retries @type resource_list_attempts: int @param raise_exception: flag to raise an exception if the list Port was not as expected or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @param timeout: port get timeout for over limit retries @type timeout: int @param use_over_limit_retry: flag to enable/disable the port update over limits retries @type use_over_limit_retry: bool @return: NetworkingResponse object with api response and failure list @rtype: common.behaviors.NetworkingResponse """ poll_interval = poll_interval or self.config.api_poll_interval resource_list_attempts = (resource_list_attempts or self.config.api_retries) use_over_limit_retry = (use_over_limit_retry or self.config.use_over_limit_retry) timeout = timeout or self.config.resource_get_timeout result = NetworkingResponse() err_msg = 'Port List failure' for attempt in range(resource_list_attempts): self._log.debug('Attempt {0} of {1} with port list'.format( attempt + 1, resource_list_attempts)) resp = self.client.list_ports( port_id=port_id, network_id=network_id, name=name, status=status, admin_state_up=admin_state_up, device_id=device_id, tenant_id=tenant_id, device_owner=device_owner, mac_address=mac_address, limit=limit, marker=marker, page_reverse=page_reverse) if use_over_limit_retry: endtime = time.time() + int(timeout) retry_msg = ('OverLimit retry with a {0}s timeout listing ' 'ports').format(timeout, port_id) self._log.info(retry_msg) while (resp.status_code == NeutronResponseCodes.REQUEST_ENTITY_TOO_LARGE and time.time() < endtime): resp = self.client.list_ports( port_id=port_id, network_id=network_id, name=name, status=status, admin_state_up=admin_state_up, device_id=device_id, tenant_id=tenant_id, device_owner=device_owner, mac_address=mac_address, limit=limit, marker=marker, page_reverse=page_reverse) time.sleep(poll_interval) resp_check = self.check_response(resp=resp, status_code=NeutronResponseCodes.LIST_PORTS, label='', message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the list was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to LIST ports after {0} attempts: ' '{1}').format(resource_list_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceListException(err_msg) return result
def list_subnets(self, subnet_id=None, network_id=None, cidr=None, tenant_id=None, gateway_ip=None, ip_version=None, enable_dhcp=None, name=None, limit=None, marker=None, page_reverse=None, resource_list_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Lists subnets and verifies the response is the expected @param subnet_id: subnet ID to filter by @type subnet_id: string @param network_id: network ID to filter by @type network_id: string @param cidr: cider to filter by @type cidr: string @param tenant_id: owner of the network to filter by @type tenant_id: string @param gateway_ip: gateway_ip to filter by @type gateway_ip: string @param ip_version: IP version 4 or 6 to filter by @type ip_version: int @param enable_dhcp: enable_dhcp status to filter by @type enable_dhcp: bool @param name: subnet name to filter by @type name: string @param limit: page size @type limit: int @param marker: Id of the last item of the previous page @type marker: string @param page_reverse: direction of the page @type page_reverse: bool @param resource_list_attempts: number of API retries @type resource_list_attempts: int @param raise_exception: flag to raise an exception if the list Subnet was not as expected or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @return: NetworkingResponse object with api response and failure list @rtype: common.behaviors.NetworkingResponse """ poll_interval = poll_interval or self.config.api_poll_interval resource_list_attempts = (resource_list_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Subnet List failure' for attempt in range(resource_list_attempts): self._log.debug('Attempt {0} of {1} with subnet list'.format( attempt + 1, resource_list_attempts)) resp = self.client.list_subnets(subnet_id=subnet_id, network_id=network_id, cidr=cidr, tenant_id=tenant_id, gateway_ip=gateway_ip, ip_version=ip_version, enable_dhcp=enable_dhcp, name=name, limit=limit, marker=marker, page_reverse=page_reverse) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.LIST_SUBNETS, label='', message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the list was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to LIST subnets after {0} attempts: ' '{1}').format(resource_list_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceListException(err_msg) return result
def list_networks(self, network_id=None, name=None, status=None, admin_state_up=None, shared=None, tenant_id=None, limit=None, marker=None, page_reverse=None, resource_list_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Lists networks and verifies the response is the expected @param network_id: network ID to filter by @type network_id: string @param name: network name to filter by @type name: string @param status: network status to filter by @type status: string @param admin_state_up: Admin state of the network to filter by @type admin_state_up: bool @param shared: If network is shared across tenants status to filter by @type shared: bool @param tenant_id: tenant ID network owner to filter by @type tenant_id: string @param limit: page size @type limit: int @param marker: Id of the last item of the previous page @type marker: string @param page_reverse: direction of the page @type page_reverse: bool @param resource_list_attempts: number of API retries @type resource_list_attempts: int @param raise_exception: flag to raise an exception if the list Network was not as expected or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @return: NetworkingResponse object with api response and failure list @rtype: common.behaviors.NetworkingResponse """ poll_interval = poll_interval or self.config.api_poll_interval resource_list_attempts = (resource_list_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Network List failure' for attempt in range(resource_list_attempts): self._log.debug('Attempt {0} of {1} with network list'.format( attempt + 1, resource_list_attempts)) resp = self.client.list_networks(network_id=network_id, name=name, status=status, admin_state_up=admin_state_up, shared=shared, tenant_id=tenant_id, limit=limit, marker=marker, page_reverse=page_reverse) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.LIST_NETWORKS, label='', message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the list was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to LIST networks after {0} attempts: ' '{1}').format(resource_list_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceListException(err_msg) return result