<commit_before>import logging
import smc.actions
import smc.api.web as web_api
import smc.api.common as common_api
from smc.elements.element import SMCElement

logger = logging.getLogger(__name__)

def element(name, objtype=None):
    """ Remove by element
    Args:
        * name: name for object to remove
        * objtype (optional): filter to add to search for element, i.e. host,network,single_fw,etc
    Returns:
        None
    """
  
    removable = smc.actions.search.element_info_as_json(name)
    if removable is not None:
        logger.debug("Element: %s found and is of type: %s. Attempting to remove" % (name, removable['type']))
        element = SMCElement()
        element.name = name
        element.type = removable['type']
        element.href = removable['href']
        
        common_api._remove(element)
        
    else:
        logger.info("No element named: %s, nothing to remove" % name)


if __name__ == '__main__':

    web_api.session.login('http://172.18.1.150:8082', 'EiGpKD4QxlLJ25dbBEp20001')
    
    smc.create.host('test-run', '2.2.2.2')
    smc.create.host('ami2', '3.4.5.6')
    smc.remove.element('test-run')  #single fw
    smc.remove.element('ami2')      #single host
    smc.remove.element('anewgroup')      #group
    
    web_api.session.logout()<commit_msg>get on dict for missing keys<commit_after>import logging
import smc.actions
import smc.api.web as web_api
import smc.api.common as common_api
from smc.elements.element import SMCElement

logger = logging.getLogger(__name__)

def element(name, objtype=None):
    """ Remove by element
    Args:
        * name: name for object to remove
        * objtype (optional): filter to add to search for element, i.e. host,network,single_fw,etc
    Returns:
        None
    """
  
    removable = smc.actions.search.element_info_as_json(name)
    if removable is not None:
        logger.debug("Element: %s found and is of type: %s. Attempting to remove" % (name, removable['type']))
        element = SMCElement()
        element.name = name
        element.type = removable.get('type', None)
        element.href = removable.get('href', None)
        
        common_api._remove(element)
        
    else:
        logger.info("No element named: %s, nothing to remove" % name)


if __name__ == '__main__':

    web_api.session.login('http://172.18.1.150:8082', 'EiGpKD4QxlLJ25dbBEp20001')
    
    smc.create.host('test-run', '2.2.2.2')
    smc.create.host('ami2', '3.4.5.6')
    smc.remove.element('test-run')  #single fw
    smc.remove.element('fe')      #single host
    smc.remove.element('anewgroup')      #group
    
    web_api.session.logout()
{'fraction_non_alphanumeric': 0.12655367231638417, 'fraction_numerical': 0.022975517890772127, 'mean_word_length': 2.8270893371757926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2092279', 'n_tokens_mistral': 925, 'n_tokens_neox': 878, 'n_words': 206}