import requests
import json


def create_snmp_community(baseurl, cookie_header, name, community):
    """
    This function creates a new SNMP Community with the 'name' parameter

    :param baseurl: The resource URL for the device, in String format.
    :param cookie_header: The login cookie for the session.
    :param name: The SNMP Community Name to be created, 1-32 digits, in String format
    :param community: JSON passed from the get_snmp_community call
    :return: return status code of the API call
    """
    url = baseurl + 'snmp-server/communities'
    headers = {'cookie': cookie_header}
    data = {
        "access_type": community['access_type'],
        "community_name": name,
        "restricted": community['restricted']
    }
    print(data)
    response = requests.post(url, verify=False, data=json.dumps(data), headers=headers)
    if response.status_code == 201:
        print("SNMP Community Created successfully for {}".format(data['community_name']))
        return response.status_code
    else:
        print("SNMP Community Creation Failed - " + str(response))