def delete_security_group_rule(self, security_group_rule_id, resource_delete_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Deletes a specified security group rule @param security_group_rule_id: The UUID for the security group rule @type security_group_rule_id: string @param resource_delete_attempts: number of API retries @type resource_delete_attempts: int @param raise_exception: flag to raise an exception if the delete Security Group Rule 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_delete_attempts = (resource_delete_attempts or self.config.api_retries) result = NetworkingResponse() for attempt in range(resource_delete_attempts): self._log.debug( 'Attempt {0} of {1} deleting security group rule {2}'.format( attempt + 1, resource_delete_attempts, security_group_rule_id)) resp = self.client.delete_security_group_rule( security_group_rule_id=security_group_rule_id) result.response = resp # Delete response is without entity so resp_check can not be used if (resp.ok and resp.status_code == SecurityGroupsResponseCodes.DELETE_SECURITY_GROUP_RULE): return result del_status_code = \ SecurityGroupsResponseCodes.DELETE_SECURITY_GROUP_RULE err_msg = ( '{security_group_rule} Security Group Rule Delete failure, ' 'expected status code: {expected_status}. Response: {status} ' '{reason} {content}').format( security_group_rule=security_group_rule_id, expected_status=del_status_code, status=resp.status_code, reason=resp.reason, content=resp.content) self._log.error(err_msg) result.failures.append(err_msg) time.sleep(poll_interval) else: err_msg = ( 'Unable to DELETE {0} Security Group Rule after {1} attempts: ' '{2}').format(security_group_rule_id, resource_delete_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceDeleteException(err_msg) return result
def get_security_group_rule(self, security_group_rule_id, resource_get_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Shows information for a specified security group rule @param security_group_rule_id: The UUID for the security group rule @type security_group_rule_id: string @param resource_get_attempts: number of API retries @type resource_get_attempts: int @param raise_exception: flag to raise an exception if the get Security Group Rule 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_get_attempts = (resource_get_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Rule Get failure' for attempt in range(resource_get_attempts): self._log.debug( 'Attempt {0} of {1} getting security group rule {2}'.format( attempt + 1, resource_get_attempts, security_group_rule_id)) resp = self.client.get_security_group_rule( security_group_rule_id=security_group_rule_id) resp_check = self.check_response( resp=resp, status_code=SecurityGroupsResponseCodes. GET_SECURITY_GROUP_RULE, label=security_group_rule_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the get was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to GET {0} security group rule after {1} attempts: ' '{2}').format(security_group_rule_id, resource_get_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceGetException(err_msg) return result
def get_security_group(self, security_group_id, resource_get_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Shows information for a specified security group @param security_group_id: The UUID for the security group @type security_group_id: string @param resource_get_attempts: number of API retries @type resource_get_attempts: int @param raise_exception: flag to raise an exception if the get Security Group 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_get_attempts = (resource_get_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Get failure' for attempt in range(resource_get_attempts): self._log.debug( 'Attempt {0} of {1} getting security group {2}'.format( attempt + 1, resource_get_attempts, security_group_id)) resp = self.client.get_security_group( security_group_id=security_group_id) resp_check = self.check_response( resp=resp, status_code=SecurityGroupsResponseCodes.GET_SECURITY_GROUP, label=security_group_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the get was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to GET {0} security group after {1} attempts: ' '{2}').format(security_group_id, resource_get_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceGetException(err_msg) return result
def delete_subnet(self, subnet_id, resource_delete_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Deletes and verifies a specified subnet is deleted @param subnet_id: The UUID for the subnet @type subnet_id: string @param resource_delete_attempts: number of API retries @type resource_delete_attempts: int @param raise_exception: flag to raise an exception if the deleted 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_delete_attempts = (resource_delete_attempts or self.config.api_retries) result = NetworkingResponse() for attempt in range(resource_delete_attempts): self._log.debug('Attempt {0} of {1} deleting subnet {2}'.format( attempt + 1, resource_delete_attempts, subnet_id)) resp = self.client.delete_subnet(subnet_id=subnet_id) result.response = resp # Delete response is without entity so resp_check can not be used if (resp.ok and resp.status_code == NeutronResponseCodes.DELETE_SUBNET): return result err_msg = ('{subnet} Subnet Delete failure, expected status ' 'code: {expected_status}. Response: {status} {reason} ' '{content}').format( subnet=subnet_id, expected_status=NeutronResponseCodes.DELETE_SUBNET, status=resp.status_code, reason=resp.reason, content=resp.content) self._log.error(err_msg) result.failures.append(err_msg) time.sleep(poll_interval) else: err_msg = ('Unable to DELETE {0} subnet after {1} attempts: ' '{2}').format(subnet_id, resource_delete_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceDeleteException(err_msg) return result
def get_network(self, network_id, resource_get_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Shows and verifies a specified network @param network_id: The UUID for the network @type network_id: string @param resource_get_attempts: number of API retries @type resource_get_attempts: int @param raise_exception: flag to raise an exception if the get 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_get_attempts = (resource_get_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Network Get failure' for attempt in range(resource_get_attempts): self._log.debug('Attempt {0} of {1} getting network {2}'.format( attempt + 1, resource_get_attempts, network_id)) resp = self.client.get_network(network_id=network_id) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.GET_NETWORK, label=network_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the get was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to GET {0} network after {1} attempts: ' '{2}').format(network_id, resource_get_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceGetException(err_msg) return result
def get_limits(self, page_reverse=None, resource_get_attempts=None, raise_exception=False, poll_interval=None): """ @summary: get rate limits @param page_reverse: direction of the page @type page_reverse: bool @param resource_get_attempts: number of API retries @type resource_get_attempts: int @param raise_exception: flag to raise an exception if the get limits call 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_get_attempts = (resource_get_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Limits GET failure' for attempt in range(resource_get_attempts): self._log.debug( 'Attempt {0} of {1} with limits GET'.format( attempt + 1, resource_get_attempts)) resp = self.client.get_limits(page_reverse=page_reverse) resp_check = self.check_response( resp=resp, status_code=LimitsResponseCodes.GET_LIMITS, label='', message=err_msg) result.response = resp # resp_check will have the response failure or None if no failure if resp_check is None: 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 GET limits after {0} attempts: ' '{1}').format(resource_get_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceGetException(err_msg) return result
def delete_network(self, network_id, resource_delete_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Deletes and verifies a specified network is deleted @param network_id: The UUID for the network @type network_id: string @param resource_delete_attempts: number of API retries @type resource_delete_attempts: int @param raise_exception: flag to raise an exception if the deleted 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_delete_attempts = (resource_delete_attempts or self.config.api_retries) result = NetworkingResponse() for attempt in range(resource_delete_attempts): self._log.debug('Attempt {0} of {1} deleting network {2}'.format( attempt + 1, resource_delete_attempts, network_id)) resp = self.client.delete_network(network_id=network_id) result.response = resp # Delete response is without entity so resp_check can not be used if (resp.ok and resp.status_code == NeutronResponseCodes.DELETE_NETWORK): return result err_msg = ('{network} Network Delete failure, expected status ' 'code: {expected_status}. Response: {status} {reason} ' '{content}').format( network=network_id, expected_status=NeutronResponseCodes.DELETE_NETWORK, status=resp.status_code, reason=resp.reason, content=resp.content) self._log.error(err_msg) result.failures.append(err_msg) time.sleep(poll_interval) else: err_msg = ( 'Unable to DELETE {0} network after {1} attempts: ' '{2}').format(network_id, resource_delete_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceDeleteException(err_msg) return result
def get_limits(self, page_reverse=None, resource_get_attempts=None, raise_exception=False, poll_interval=None): """ @summary: get rate limits @param page_reverse: direction of the page @type page_reverse: bool @param resource_get_attempts: number of API retries @type resource_get_attempts: int @param raise_exception: flag to raise an exception if the get limits call 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_get_attempts = resource_get_attempts or self.config.api_retries result = NetworkingResponse() err_msg = "Limits GET failure" for attempt in range(resource_get_attempts): self._log.debug("Attempt {0} of {1} with limits GET".format(attempt + 1, resource_get_attempts)) resp = self.client.get_limits(page_reverse=page_reverse) resp_check = self.check_response( resp=resp, status_code=LimitsResponseCodes.GET_LIMITS, label="", message=err_msg ) result.response = resp # resp_check will have the response failure or None if no failure if resp_check is None: 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 GET limits after {0} attempts: " "{1}").format(resource_get_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceGetException(err_msg) return result
def update_network(self, network_id, name=None, admin_state_up=None, shared=None, tenant_id=None, resource_update_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Updates and verifies a specified Network @param network_id: The UUID for the network @type network_id: string @param name: human readable name for the network, may not be unique. (CRUD: CRU) @type name: string @param admin_state_up: true or false, the admin state of the network. If down, the network does not forward packets. Usually set to True (CRUD: CRU) @type admin_state_up: bool @param shared: specifies if the network can be accessed by any tenant. Usually set to False (CRUD: CRU) @type shared: bool @param tenant_id: owner of the network. (CRUD: CR) @type tenant_id: string @param resource_update_attempts: number of API retries @type resource_update_attempts: int @param raise_exception: flag to raise an exception if the Network was not updated 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_update_attempts = (resource_update_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Network Update failure' for attempt in range(resource_update_attempts): self._log.debug('Attempt {0} of {1} updating network {2}'.format( attempt + 1, resource_update_attempts, network_id)) resp = self.client.update_network( network_id=network_id, name=name, admin_state_up=admin_state_up, shared=shared, tenant_id=tenant_id) resp_check = self.check_response(resp=resp, status_code=NeutronResponseCodes.UPDATE_NETWORK, label=network_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the update was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to update {0} network after {1} attempts: ' '{2}').format(network_id, resource_update_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceUpdateException(err_msg) return result
def create_port(self, network_id, name=None, admin_state_up=None, mac_address=None, fixed_ips=None, device_id=None, device_owner=None, tenant_id=None, security_groups=None, resource_build_attempts=None, raise_exception=True, use_exact_name=False, poll_interval=None, timeout=None, use_over_limit_retry=None): """ @summary: Creates and verifies a Port is created as expected @param network_id: network port is associated with (CRUD: CR) @type network_id: string @param name: human readable name for the port, may not be unique. (CRUD: CRU) @type name: string @param admin_state_up: true or false (default true), the admin state of the port. If down, the port does not forward packets (CRUD: CRU) @type admin_state_up: bool @param mac_address: mac address to use on the port (CRUD: CR) @type mac_address: string @param fixed_ips: ip addresses for the port associating the port with the subnets where the IPs come from (CRUD: CRU) @type fixed_ips: list(dict) @param device_id: id of device using this port (CRUD: CRUD) @type device_id: string @param device_owner: entity using this port (ex. dhcp agent,CRUD: CRUD) @type device_owner: string @param tenant_id: owner of the port (CRUD: CR) @type tenant_id: string @param security_groups: ids of any security groups associated with the port (CRUD: CRUD) @type security_groups: list(dict) @param resource_build_attempts: number of API retries @type resource_build_attempts: int @param raise_exception: flag to raise an exception if the Port was not created or to return None @type raise_exception: bool @param use_exact_name: flag if the exact name given should be used @type use_exact_name: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @param timeout: port update 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 """ if not network_id: raise NetworkIDMissingException if name is None: name = rand_name(self.config.starts_with_name) elif not use_exact_name: name = rand_name(name) poll_interval = poll_interval or self.config.api_poll_interval resource_build_attempts = (resource_build_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_create_timeout result = NetworkingResponse() err_msg = 'Port Create failure' for attempt in range(resource_build_attempts): self._log.debug('Attempt {0} of {1} building port {2}'.format( attempt + 1, resource_build_attempts, name)) resp = self.client.create_port( network_id=network_id, name=name, admin_state_up=admin_state_up, mac_address=mac_address, fixed_ips=fixed_ips, device_id=device_id, device_owner=device_owner, tenant_id=tenant_id, security_groups=security_groups) if use_over_limit_retry: endtime = time.time() + int(timeout) retry_msg = ('OverLimit retry with a {0}s timeout creating a ' 'port on network {1}').format(timeout, network_id) self._log.info(retry_msg) while (resp.status_code == NeutronResponseCodes.REQUEST_ENTITY_TOO_LARGE and time.time() < endtime): resp = self.client.create_port( network_id=network_id, name=name, admin_state_up=admin_state_up, mac_address=mac_address, fixed_ips=fixed_ips, device_id=device_id, device_owner=device_owner, tenant_id=tenant_id, security_groups=security_groups) time.sleep(poll_interval) resp_check = self.check_response(resp=resp, status_code=NeutronResponseCodes.CREATE_PORT, label=name, message=err_msg, network_id=network_id) result.response = resp if not resp_check: return result # Failures will be an empty list if the create was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to create {0} port after {1} attempts: ' '{2}').format(name, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(err_msg) return result
def delete_port(self, port_id, resource_delete_attempts=None, raise_exception=False, poll_interval=None, timeout=None, use_over_limit_retry=None): """ @summary: Deletes and verifies a specified port is deleted @param string port_id: The UUID for the port @type port_id: string @param resource_delete_attempts: number of API retries @type resource_delete_attempts: int @param raise_exception: flag to raise an exception if the deleted 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 delete timeout for over limit retries @type timeout: int @param use_over_limit_retry: flag to enable/disable the port delete 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_delete_attempts = (resource_delete_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_delete_timeout result = NetworkingResponse() for attempt in range(resource_delete_attempts): self._log.debug('Attempt {0} of {1} deleting port {2}'.format( attempt + 1, resource_delete_attempts, port_id)) resp = self.client.delete_port(port_id=port_id) if use_over_limit_retry: endtime = time.time() + int(timeout) retry_msg = ('OverLimit retry with a {0}s timeout deleting ' 'port {1}').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.delete_port(port_id=port_id) time.sleep(poll_interval) result.response = resp # Delete response is without entity so resp_check can not be used if (resp.ok and resp.status_code == NeutronResponseCodes.DELETE_PORT): return result err_msg = ('{port} Port Delete failure, expected status ' 'code: {expected_status}. Response: {status} {reason} ' '{content}').format( port=port_id, expected_status=NeutronResponseCodes.DELETE_PORT, status=resp.status_code, reason=resp.reason, content=resp.content) self._log.error(err_msg) result.failures.append(err_msg) time.sleep(poll_interval) else: err_msg = ( 'Unable to DELETE {0} port after {1} attempts: ' '{2}').format(port_id, resource_delete_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceDeleteException(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 get_port(self, port_id, resource_get_attempts=None, raise_exception=False, poll_interval=None, timeout=None, use_over_limit_retry=None): """ @summary: Shows and verifies a specified port @param port_id: The UUID for the port @type port_id: string @param resource_get_attempts: number of API retries @type resource_get_attempts: int @param raise_exception: flag to raise an exception if the get 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_get_attempts = (resource_get_attempts or self.config.api_retries) poll_interval = poll_interval or self.config.api_poll_interval 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 Get failure' for attempt in range(resource_get_attempts): self._log.debug('Attempt {0} of {1} getting network {2}'.format( attempt + 1, resource_get_attempts, port_id)) resp = self.client.get_port(port_id=port_id) if use_over_limit_retry: endtime = time.time() + int(timeout) retry_msg = ('OverLimit retry with a {0}s timeout getting ' 'port {1}').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.get_port(port_id=port_id) time.sleep(poll_interval) resp_check = self.check_response(resp=resp, status_code=NeutronResponseCodes.GET_PORT, label=port_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the get was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to GET {0} port after {1} attempts: ' '{2}').format(port_id, resource_get_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceGetException(err_msg) return result
def update_port(self, port_id, name=None, admin_state_up=None, fixed_ips=None, device_id=None, device_owner=None, security_groups=None, resource_update_attempts=None, raise_exception=False, poll_interval=None, timeout=None, use_over_limit_retry=None): """ @summary: Updates and verifies a specified Port @param port_id: The UUID for the port @type port_id: string @param name: human readable name for the port, may not be unique (CRUD: CRU) @type name: string @param admin_state_up: true or false (default true), the admin state of the port. If down, the port does not forward packets (CRUD: CRU) @type admin_state_up: bool @param fixed_ips: ip addresses for the port associating the port with the subnets where the IPs come from (CRUD: CRU) @type fixed_ips: list(dict) @param device_id: id of device using this port (CRUD: CRUD) @type device_id: string @param string device_owner: entity using this port (ex. dhcp agent, CRUD: CRUD) @type device_owner: string @param security_groups: ids of any security groups associated with the port (CRUD: CRUD) @type security_groups: list(dict) @param resource_update_attempts: number of API retries @type resource_update_attempts: int @param raise_exception: flag to raise an exception if the Port was not updated or to return None @type raise_exception: bool @param poll_interval: sleep time interval between API retries @type poll_interval: int @param timeout: port update 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_update_attempts = (resource_update_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_update_timeout result = NetworkingResponse() err_msg = 'Port Update failure' for attempt in range(resource_update_attempts): self._log.debug('Attempt {0} of {1} updating port {2}'.format( attempt + 1, resource_update_attempts, port_id)) resp = self.client.update_port( port_id=port_id, name=name, admin_state_up=admin_state_up, fixed_ips=fixed_ips, device_id=device_id, device_owner=device_owner, security_groups=security_groups) if use_over_limit_retry: endtime = time.time() + int(timeout) retry_msg = ('OverLimit retry with a {0}s timeout updating ' 'port {1}').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.update_port( port_id=port_id, name=name, admin_state_up=admin_state_up, fixed_ips=fixed_ips, device_id=device_id, device_owner=device_owner, security_groups=security_groups) time.sleep(poll_interval) resp_check = self.check_response(resp=resp, status_code=NeutronResponseCodes.UPDATE_PORT, label=port_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the update was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to update {0} port after {1} attempts: ' '{2}').format(port_id, resource_update_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceUpdateException(err_msg) return result
def update_subnet(self, subnet_id, name=None, gateway_ip=None, dns_nameservers=None, host_routes=None, enable_dhcp=None, allocation_pools=None, resource_update_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Updates and verifies a specified Subnet @param subnet_id: The UUID for the subnet @type subnet_id: string @param name: human readable name for the subnet, may not be unique (CRUD: CRU) @type name: string @param gateway_ip: default gateway used by devices in the subnet (CRUD: CRUD) @type gateway_ip: string @param dns_nameservers: DNS name servers used by subnet hosts (CRUD: CRU) @type dns_nameservers: list(str) @param host_routes: routes that should be used by devices with IPs from this subnet (does not includes the local route (CRUD: CRU) @type host_routes: list(dict) @param enable_dhcp: whether DHCP is enabled (CRUD:CRU) @type enable_dhcp: bool @param allocation_pools: sub range of cidr available for dynamic allocation to ports (CRUD: CRU) @type allocation_pools: list(dict) @param resource_update_attempts: number of API retries @type resource_update_attempts: int @param raise_exception: flag to raise an exception if the Subnet was not updated 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_update_attempts = (resource_update_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Subnet Update failure' for attempt in range(resource_update_attempts): self._log.debug('Attempt {0} of {1} updating subnet {2}'.format( attempt + 1, resource_update_attempts, subnet_id)) resp = self.client.update_subnet(subnet_id=subnet_id, name=name, gateway_ip=gateway_ip, dns_nameservers=dns_nameservers, host_routes=host_routes, enable_dhcp=enable_dhcp, allocation_pools=allocation_pools) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.UPDATE_SUBNET, label=subnet_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the update was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to update {0} subnet after {1} attempts: ' '{2}').format(subnet_id, resource_update_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceUpdateException(err_msg) return result
def update_network(self, network_id, name=None, admin_state_up=None, shared=None, tenant_id=None, resource_update_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Updates and verifies a specified Network @param network_id: The UUID for the network @type network_id: string @param name: human readable name for the network, may not be unique. (CRUD: CRU) @type name: string @param admin_state_up: true or false, the admin state of the network. If down, the network does not forward packets. Usually set to True (CRUD: CRU) @type admin_state_up: bool @param shared: specifies if the network can be accessed by any tenant. Usually set to False (CRUD: CRU) @type shared: bool @param tenant_id: owner of the network. (CRUD: CR) @type tenant_id: string @param resource_update_attempts: number of API retries @type resource_update_attempts: int @param raise_exception: flag to raise an exception if the Network was not updated 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_update_attempts = (resource_update_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Network Update failure' for attempt in range(resource_update_attempts): self._log.debug('Attempt {0} of {1} updating network {2}'.format( attempt + 1, resource_update_attempts, network_id)) resp = self.client.update_network(network_id=network_id, name=name, admin_state_up=admin_state_up, shared=shared, tenant_id=tenant_id) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.UPDATE_NETWORK, label=network_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the update was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to update {0} network after {1} attempts: ' '{2}').format(network_id, resource_update_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceUpdateException(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 create_network(self, name=None, admin_state_up=None, shared=None, tenant_id=None, resource_build_attempts=None, raise_exception=True, use_exact_name=False, poll_interval=None): """ @summary: Creates and verifies a Network is created as expected @param name: human readable name for the network, may not be unique @type name: string @param admin_state_up: true or false, the admin state of the network @type admin_state_up: bool @param shared: specifies if the network can be accessed by any tenant @type shared: bool @param tenant_id: owner of the network @type tenant_id: string @param resource_build_attempts: number of API retries @type resource_build_attempts: int @param raise_exception: flag to raise an exception if the Network was not created or to return None @type raise_exception: bool @param use_exact_name: flag if the exact name given should be used @type use_exact_name: 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 """ if name is None: name = rand_name(self.config.starts_with_name) elif not use_exact_name: name = rand_name(name) poll_interval = poll_interval or self.config.api_poll_interval resource_build_attempts = (resource_build_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Network Create failure' for attempt in range(resource_build_attempts): self._log.debug('Attempt {0} of {1} building network {2}'.format( attempt + 1, resource_build_attempts, name)) resp = self.client.create_network( name=name, admin_state_up=admin_state_up, shared=shared, tenant_id=tenant_id) resp_check = self.check_response(resp=resp, status_code=NeutronResponseCodes.CREATE_NETWORK, label=name, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the create was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to create {0} network after {1} attempts: ' '{2}').format(name, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(err_msg) return result
def create_network(self, name=None, admin_state_up=None, shared=None, tenant_id=None, resource_build_attempts=None, raise_exception=True, use_exact_name=False, poll_interval=None): """ @summary: Creates and verifies a Network is created as expected @param name: human readable name for the network, may not be unique @type name: string @param admin_state_up: true or false, the admin state of the network @type admin_state_up: bool @param shared: specifies if the network can be accessed by any tenant @type shared: bool @param tenant_id: owner of the network @type tenant_id: string @param resource_build_attempts: number of API retries @type resource_build_attempts: int @param raise_exception: flag to raise an exception if the Network was not created or to return None @type raise_exception: bool @param use_exact_name: flag if the exact name given should be used @type use_exact_name: 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 """ if name is None: name = rand_name(self.config.starts_with_name) elif not use_exact_name: name = rand_name(name) poll_interval = poll_interval or self.config.api_poll_interval resource_build_attempts = (resource_build_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Network Create failure' for attempt in range(resource_build_attempts): self._log.debug('Attempt {0} of {1} building network {2}'.format( attempt + 1, resource_build_attempts, name)) resp = self.client.create_network(name=name, admin_state_up=admin_state_up, shared=shared, tenant_id=tenant_id) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.CREATE_NETWORK, label=name, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the create was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to create {0} network after {1} attempts: ' '{2}').format(name, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(err_msg) return result
def create_subnet(self, network_id, ip_version=None, cidr=None, name=None, tenant_id=None, gateway_ip=None, dns_nameservers=None, allocation_pools=None, host_routes=None, enable_dhcp=None, resource_build_attempts=None, raise_exception=True, use_exact_name=False, poll_interval=None): """ @summary: Creates and verifies a Subnet is created as expected @param name: human readable name for the subnet, may not be unique. (CRUD: CRU) @type name: string @param tenant_id: owner of the network. (CRUD: CR) @type tenant_id: string @param network_id: network subnet is associated with (CRUD: CR) @type network_id: string @param ip_version: IP version 4 or 6 (CRUD: CR), if the CIDR is given this is optional and the CIDR one will be taken @type ip_version: int @param cidr: represents IP range for the subnet and should be in the form <network_address>/<prefix> (CRUD: CR) @type cidr: string @param gateway_ip: default gateway used by devices in the subnet (CRUD: CRUD) @type gateway_ip: string @param dns_nameservers: DNS name servers used by subnet hosts (CRUD: CRU) @type dns_nameservers: list(str) @param allocation_pools: sub range of cidr available for dynamic allocation to ports (CRUD: CR) @type allocation_pools: list(dict) @param host_routes: routes that should be used by devices with IPs from this subnet (does not includes the local route, CRUD: CRU) @type host_routes: list(dict) @param enable_dhcp: whether DHCP is enabled (CRUD:CRU) @type enable_dhcp: bool @param resource_build_attempts: number of API retries @type resource_build_attempts:int @param raise_exception: flag to raise an exception if the Subnet was not created or to return None @type raise_exception: bool @param use_exact_name: flag if the exact name given should be used @type use_exact_name: 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 """ if not network_id: raise NetworkIDMissingException if cidr: if self.verify_ip(cidr): ip_version = IPy.IP(cidr).version() else: raise InvalidIPException else: if ip_version == 6: cidr = self.create_ipv6_cidr() else: # Setting the default create version to 4 if not given ip_version = 4 cidr = self.create_ipv4_cidr() if name is None: name = rand_name(self.config.starts_with_name) elif not use_exact_name: name = rand_name(name) poll_interval = poll_interval or self.config.api_poll_interval resource_build_attempts = (resource_build_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Subnet Create failure' for attempt in range(resource_build_attempts): self._log.debug('Attempt {0} of {1} building subnet {2}'.format( attempt + 1, resource_build_attempts, name)) resp = self.client.create_subnet(network_id=network_id, ip_version=ip_version, cidr=cidr, name=name, tenant_id=tenant_id, gateway_ip=gateway_ip, dns_nameservers=dns_nameservers, allocation_pools=allocation_pools, host_routes=host_routes, enable_dhcp=enable_dhcp) resp_check = self.check_response( resp=resp, status_code=NeutronResponseCodes.CREATE_SUBNET, label=name, message=err_msg, network_id=network_id) result.response = resp if not resp_check: return result # Failures will be an empty list if the update was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to create {0} subnet after {1} attempts: ' '{2}').format(name, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(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
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
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_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 update_security_group(self, security_group_id, name=None, description=None, tenant_id=None, resource_update_attempts=None, raise_exception=False, poll_interval=None): """ @summary: Updates a security group @param security_group_id: The UUID for the security group @type security_group_id: string @param name: A symbolic name for the security group. Not required to be unique. @type name: string @param description: (optional) Description of a security group. @type description: string @param tenant_id: (admin use only) Owner of the security group. @type tenant_id: string @param resource_update_attempts: number of API retries @type resource_update_attempts: int @param raise_exception: flag to raise an exception if the Security Group was not updated 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_update_attempts = (resource_update_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Update failure' for attempt in range(resource_update_attempts): self._log.debug('Attempt {0} of {1} updating security group ' '{2}'.format(attempt + 1, resource_update_attempts, security_group_id)) resp = self.client.update_security_group( security_group_id=security_group_id, name=name, description=description, tenant_id=tenant_id) resp_check = self.check_response( resp=resp, status_code=SecurityGroupsResponseCodes.UPDATE_SECURITY_GROUP, label=security_group_id, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the update was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to update {0} security group after {1} attempts: ' '{2}').format(security_group_id, resource_update_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceUpdateException(err_msg) return result
def create_security_group(self, name=None, description=None, tenant_id=None, resource_build_attempts=None, raise_exception=True, use_exact_name=False, poll_interval=None): """ @summary: Creates a security group @param name: A symbolic name for the security group. Not required to be unique. @type name: string @param description: (optional) Description of a security group. @type description: string @param tenant_id: (admin use only) Owner of the security group. @type tenant_id: string @param resource_build_attempts: number of API retries @type resource_build_attempts: int @param raise_exception: flag to raise an exception if the Security Group was not created or to return None @type raise_exception: bool @param use_exact_name: flag if the exact name in config should be used @type use_exact_name: 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 """ if name is None and not use_exact_name: name = rand_name(self.config.starts_with_name) elif not use_exact_name: name = rand_name(name) poll_interval = poll_interval or self.config.api_poll_interval resource_build_attempts = (resource_build_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Create failure' for attempt in range(resource_build_attempts): self._log.debug( 'Attempt {0} of {1} building security group {2}'.format( attempt + 1, resource_build_attempts, name)) resp = self.client.create_security_group( name=name, description=description, tenant_id=tenant_id) resp_check = self.check_response( resp=resp, status_code=SecurityGroupsResponseCodes.CREATE_SECURITY_GROUP, label=name, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the create was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to create {0} security group after {1} attempts: ' '{2}').format(name, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(err_msg) return result
def create_security_group_rule(self, security_group_id, direction='ingress', ethertype='IPv4', protocol=None, port_range_min=None, port_range_max=None, remote_group_id=None, remote_ip_prefix=None, resource_build_attempts=None, raise_exception=True, poll_interval=None): """ @summary: Creates a security group rule @param security_group_id: The security group ID to associate with @type security_group_id: string @param direction: ingress or egress security group rule direction @type direction: string @param ethertype: Must be IPv4 or IPv6 @type ethertype: string @param protocol: protocol matched by the security group rule. Valid values are null, tcp, udp, and icmp. @type protocol: string @param port_range_min: The minimum port number in the range that is matched by the security group rule. Value must be less than or equal to the port_range_max for tcp or udp. If the protocol is ICMP, this value must be an ICMP type. @type port_range_min: int @param port_range_max: The maximum port number in the range @type port_range_max: int @param remote_group_id: The remote group ID to be associated with @type remote_group_id: string @param remote_ip_prefix: The remote IP prefix to be associated with, remote_group_id or remote_ip_prefix can be specified @type remote_ip_prefix: string @param resource_build_attempts: number of API retries @type resource_build_attempts: int @param raise_exception: flag to raise an exception if the Security Group Rule was not created 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_build_attempts = (resource_build_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Rule Create failure' for attempt in range(resource_build_attempts): self._log.debug( ('Attempt {0} of {1} building security group rule ' 'at security group {2}').format(attempt + 1, resource_build_attempts, security_group_id)) resp = self.client.create_security_group_rule( 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) label = 'At Security Group {0}'.format(security_group_id) exp_code = SecurityGroupsResponseCodes.CREATE_SECURITY_GROUP_RULE resp_check = self.check_response(resp=resp, status_code=exp_code, label=label, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the create was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ('Unable to create at security group {0} security group ' 'rule after {1} attempts: {2}').format( security_group_id, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(err_msg) return result
def create_security_group_rule(self, security_group_id, direction='ingress', ethertype='IPv4', protocol=None, port_range_min=None, port_range_max=None, remote_group_id=None, remote_ip_prefix=None, resource_build_attempts=None, raise_exception=True, poll_interval=None): """ @summary: Creates a security group rule @param security_group_id: The security group ID to associate with @type security_group_id: string @param direction: ingress or egress security group rule direction @type direction: string @param ethertype: Must be IPv4 or IPv6 @type ethertype: string @param protocol: protocol matched by the security group rule. Valid values are null, tcp, udp, and icmp. @type protocol: string @param port_range_min: The minimum port number in the range that is matched by the security group rule. Value must be less than or equal to the port_range_max for tcp or udp. If the protocol is ICMP, this value must be an ICMP type. @type port_range_min: int @param port_range_max: The maximum port number in the range @type port_range_max: int @param remote_group_id: The remote group ID to be associated with @type remote_group_id: string @param remote_ip_prefix: The remote IP prefix to be associated with, remote_group_id or remote_ip_prefix can be specified @type remote_ip_prefix: string @param resource_build_attempts: number of API retries @type resource_build_attempts: int @param raise_exception: flag to raise an exception if the Security Group Rule was not created 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_build_attempts = (resource_build_attempts or self.config.api_retries) result = NetworkingResponse() err_msg = 'Security Group Rule Create failure' for attempt in range(resource_build_attempts): self._log.debug(( 'Attempt {0} of {1} building security group rule ' 'at security group {2}') .format(attempt + 1, resource_build_attempts, security_group_id)) resp = self.client.create_security_group_rule( 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) label = 'At Security Group {0}'.format(security_group_id) exp_code = SecurityGroupsResponseCodes.CREATE_SECURITY_GROUP_RULE resp_check = self.check_response( resp=resp, status_code=exp_code, label=label, message=err_msg) result.response = resp if not resp_check: return result # Failures will be an empty list if the create was successful the # first time result.failures.append(resp_check) time.sleep(poll_interval) else: err_msg = ( 'Unable to create at security group {0} security group ' 'rule after {1} attempts: {2}' ).format(security_group_id, resource_build_attempts, result.failures) self._log.error(err_msg) if raise_exception: raise ResourceBuildException(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) resp_check = self.check_response( resp=resp, status_code=SecurityGroupsResponseCodes.LIST_SECURITY_GROUP_RULES, 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