Пример #1
0
def create(module, name, operatingsystems, url):

    # Create list of operatingsystem ids
    set_operatingsystems = theforeman_gen_os_ids(module, url, operatingsystems)

    # Query Foreman API for current Domains
    myurl = url + "/api/architectures"
    data = {
        "architecture": {
            "name": name,
            "operatingsystems": set_operatingsystems
        }
    }
    method = 'GET'
    search_parameter = 'name'
    search_value = name

    # Obtain Foreman resource ID
    resource_id = theforeman_obtain_resource_id(module, myurl, data, method,
                                                search_parameter, search_value)

    # Create architecture if it does not exist
    if resource_id == 'None' or resource_id == '':
        if not module.check_mode:
            myurl = url + "/api/architectures"
            method = 'POST'
            (query_out, info) = theforeman_query(module, myurl, data, method)
            return False, query_out, True
        else:
            return False, "Architecture %s will be created" % (name), True
    else:
        # Obtain current Foreman resource values
        myurl = url + "/api/architectures/%s" % (resource_id)
        (query_out, info) = theforeman_query(module, myurl, data, method)

        # Update architecture if set/return values differ
        (diff_val,
         diff_data) = theforeman_compare_values(module, url, data, query_out,
                                                '', '', '',
                                                set_operatingsystems)
        if diff_val != 0:
            myurl = url + "/api/architectures/%s" % (query_out['id'])
            method = 'PUT'
            (query_out, info) = theforeman_query(module, myurl, diff_data,
                                                 method)
            return False, query_out, True

        return False, query_out, False
Пример #2
0
def create(module, name, fullname, locations, url):

    # Create list of locations dictionaries
    set_locations = theforeman_generate_locations_dict(module, url, locations)

    # Query Foreman API for current Domains
    myurl = url + "/api/domains"
    data = {
        "domain": {
            "name": name,
            "fullname": fullname,
            "locations": set_locations
        }
    }
    method = 'GET'
    search_parameter = 'name'
    search_value = name

    # Obtain Foreman resource ID
    resource_id = theforeman_obtain_resource_id(module, myurl, data, method,
                                                search_parameter, search_value)

    # Create domain if it does not exist
    if resource_id == 'None' or resource_id == '':
        if not module.check_mode:
            myurl = url + "/api/domains"
            method = 'POST'
            (query_out, info) = theforeman_query(module, myurl, data, method)
            return False, query_out, True
        else:
            return False, "Domain %s will be created" % (name), True
    else:
        # Obtain current Foreman resource values
        myurl = url + "/api/domains/%s" % (resource_id)
        (query_out, info) = theforeman_query(module, myurl, data, method)

        # Update domain if set/return values differ
        (diff_val,
         diff_data) = theforeman_compare_values(module, url, data, query_out,
                                                "", set_locations, "", "")
        if diff_val != 0:
            myurl = url + "/api/domains/%s" % (query_out['id'])
            method = 'PUT'
            (query_out, info) = theforeman_query(module, myurl, diff_data,
                                                 method)
            return False, query_out, True

        return False, query_out, False
Пример #3
0
def remove(module, name, operatingsystems, url):
    # Query Foreman API for current Domains
    myurl = url + "/api/architectures/%s" % (name)
    data = {
        "name": name,
    }
    method = 'GET'
    (query_out, info) = theforeman_query(module, myurl, data, method)
    if query_out == 'None' or query_out == '':
        return False, query_out, False
    else:
        if not module.check_mode:
            method = 'DELETE'
            (query_out, info) = theforeman_query(module, myurl, data, method)
            return False, query_out, True
        else:
            return False, "Architecture %s will be removed" % (name), True
def remove(module, name, description, url):
    # Query Foreman API for current Domains
    myurl = url + "/api/locations/%s" % (name)
    data = {
        "name": name,
    }
    method = 'GET'
    (query_out, info) = theforeman_query(module, myurl, data, method)
    if query_out == 'None' or query_out == '':
        return False, query_out, False
    else:
        if not module.check_mode:
            method = 'DELETE'
            (query_out, info) = theforeman_query(module, myurl, data, method)
            return False, query_out, True
        else:
            return False, "Domain %s will be removed" % (name), True
Пример #5
0
def create(module, name, description, network_type, network, mask, gateway,
           dns_primary, dns_secondary, ipam, ip_from, ip_to, vlanid, boot_mode,
           dhcp_proxy, dns_proxy, tftp_proxy, domains, locations,
           organizations, url):

    # Create list of domain dictionaries
    set_domains = theforeman_generate_domains_dict(module, url, domains)

    # Create list of locations dictionaries
    set_locations = theforeman_generate_locations_dict(module, url, locations)

    # Create list of organizations dictionaries
    set_organizations = theforeman_generate_organizations_dict(
        module, url, organizations)

    # Get resource ID for Foreman DHCP,DNS,TFTP proxies
    if dhcp_proxy or dns_proxy or tftp_proxy:
        myurl = url + "/api/smart_proxies"
        data = {}
        method = 'GET'
        search_parameter = 'name'
    if dhcp_proxy:
        search_value = dhcp_proxy
        dhcp_proxy_id = theforeman_obtain_resource_id(module, myurl, data,
                                                      method, search_parameter,
                                                      search_value)
    else:
        dhcp_proxy_id = None

    if dns_proxy:
        search_value = dns_proxy
        dns_proxy_id = theforeman_obtain_resource_id(module, myurl, data,
                                                     method, search_parameter,
                                                     search_value)
    else:
        dns_proxy_id = None

    if tftp_proxy:
        search_value = tftp_proxy
        tftp_proxy_id = theforeman_obtain_resource_id(module, myurl, data,
                                                      method, search_parameter,
                                                      search_value)
    else:
        tftp_proxy_id = None

    # Query Foreman API for current Domains
    myurl = url + "/api/subnets"
    data = {
        'subnet': {
            "name": name,
            "description": description,
            "network_type": network_type,
            "network": network,
            "mask": mask,
            "gateway": gateway,
            "dns_primary": dns_primary,
            "dns_secondary": dns_secondary,
            "ipam": ipam,
            "from": ip_from,
            "to": ip_to,
            "vlanid": vlanid,
            "boot_mode": boot_mode,
            "dhcp_id": dhcp_proxy_id,
            "dns_id": dns_proxy_id,
            "tftp_id": tftp_proxy_id,
            "domains": set_domains,
            "locations": set_locations,
        }
    }
    method = 'GET'
    search_parameter = 'name'
    search_value = name

    # Obtain Foreman resource ID
    resource_id = theforeman_obtain_resource_id(module, myurl, data, method,
                                                search_parameter, search_value)

    # Create subnet if it does not exist
    if resource_id == 'None' or resource_id == '':
        if not module.check_mode:
            myurl = url + "/api/subnets"
            method = 'POST'
            (query_out, info) = theforeman_query(module, myurl, data, method)
            return False, query_out, True
        else:
            return False, "Subnet %s will be created" % (name), True
    else:
        # Obtain current Foreman resouce values
        myurl = url + "/api/subnets/%s" % (resource_id)
        (query_out, info) = theforeman_query(module, myurl, data, method)

        # Update domain if set/return values differ
        (diff_val,
         diff_data) = theforeman_compare_values(module, url, data, query_out,
                                                set_domains, set_locations,
                                                set_organizations)
        if diff_val != 0:
            method = 'PUT'
            (query_out, info) = theforeman_query(module, myurl, diff_data,
                                                 method)
            return False, query_out, True

        return False, query_out, False