def _get_firewall_policy(kwargs):
    '''
    Construct FirewallPolicy and FirewallPolicy instances from passed arguments
    '''
    fp_name = kwargs.get('name', None)
    fp_description = kwargs.get('description', None)
    firewallPolicy = FirewallPolicy(
        name=fp_name,
        description=fp_description
    )

    fpr_json = kwargs.get('rules', None)
    jdata = json.loads(fpr_json)
    rules = []
    for fwpr in jdata:
        firewallPolicyRule = FirewallPolicyRule()
        if 'protocol' in fwpr:
            firewallPolicyRule.rule_set['protocol'] = fwpr['protocol']
        if 'port_from' in fwpr:
            firewallPolicyRule.rule_set['port_from'] = fwpr['port_from']
        if 'port_to' in fwpr:
            firewallPolicyRule.rule_set['port_to'] = fwpr['port_to']
        if 'source' in fwpr:
            firewallPolicyRule.rule_set['source'] = fwpr['source']
        if 'action' in fwpr:
            firewallPolicyRule.rule_set['action'] = fwpr['action']
        if 'description' in fwpr:
            firewallPolicyRule.rule_set['description'] = fwpr['description']
        if 'port' in fwpr:
            firewallPolicyRule.rule_set['port'] = fwpr['port']
        rules.append(firewallPolicyRule)

    return {'firewall_policy': firewallPolicy, 'firewall_policy_rules': rules}
def _get_firewall_policy ( kwargs ) : fp_name = kwargs . get ( 'name' , None ) fp_description = kwargs . get ( 'description' , None ) firewallPolicy = FirewallPolicy ( name = fp_name , description = fp_description ) fpr_json = kwargs . get ( 'rules' , None ) jdata = json . loads ( fpr_json ) rules = [ ] for fwpr in jdata : firewallPolicyRule = FirewallPolicyRule ( ) if 'protocol' in fwpr : firewallPolicyRule . rule_set [ 'protocol' ] = fwpr [ 'protocol' ] if 'port_from' in fwpr : firewallPolicyRule . rule_set [ 'port_from' ] = fwpr [ 'port_from' ] if 'port_to' in fwpr : firewallPolicyRule . rule_set [ 'port_to' ] = fwpr [ 'port_to' ] if 'source' in fwpr : firewallPolicyRule . rule_set [ 'source' ] = fwpr [ 'source' ] if 'action' in fwpr : firewallPolicyRule . rule_set [ 'action' ] = fwpr [ 'action' ] if 'description' in fwpr : firewallPolicyRule . rule_set [ 'description' ] = fwpr [ 'description' ] if 'port' in fwpr : firewallPolicyRule . rule_set [ 'port' ] = fwpr [ 'port' ] rules . append ( firewallPolicyRule ) return { 'firewall_policy' : firewallPolicy , 'firewall_policy_rules' : rules }
Construct FirewallPolicy and FirewallPolicy instances from passed arguments