Beispiel #1
0
 def test_get_missing_dhcp_host(self):
     """Fetch missing DHCP host; return empty list."""
     dhcp_host = 'testgetmissinghost'
     host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group)
     result = host.get(dhcp_host)['data']
     expected_result = []
     self.assertEqual(result, expected_result)
Beispiel #2
0
 def test_get_missing_dhcp_host(self):
     """Fetch missing DHCP host; return empty list."""
     dhcp_host = "testgetmissinghost"
     host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group)
     result = host.get(dhcp_host)["data"]
     expected_result = []
     self.assertEqual(result, expected_result)
Beispiel #3
0
def reservation_search(dhcp_server, dhcp_group, host_name):
    try:
        from spoke.lib.dhcp import SpokeDHCPHost
        host = SpokeDHCPHost(dhcp_server, dhcp_group)
        result = host.get(host_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #4
0
def reservation_search(dhcp_server, dhcp_group, host_name):
    try:
        from spoke.lib.dhcp import SpokeDHCPHost
        host = SpokeDHCPHost(dhcp_server, dhcp_group)
        result = host.get(host_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #5
0
 def test_get_dhcp_host(self):
     """Fetch DHCP host; return True."""
     dhcp_host = "testgethost"
     host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group)
     host.create(dhcp_host)
     result = host.get(dhcp_host)["data"]
     service_name = self.dhcp_server + self.dhcp_conf_suffix
     group_base_dn = "cn=%s,cn=%s,%s" % (self.dhcp_group, service_name, self.base_dn)
     dn = "cn=%s,%s" % (dhcp_host, group_base_dn)
     dn_info = {"objectClass": ["top", self.dhcp_host_class, self.dhcp_options_class], "cn": [dhcp_host]}
     expected_result = [(dn, dn_info)]
     self.assertEqual(result, expected_result)
     host.delete(dhcp_host)
Beispiel #6
0
def reservation_search(host_name, dhcp_server=None, dhcp_group=None):
    try:
        conf = _spoke_config(_salt_config('config'))
        if not dhcp_server:
            dhcp_server = conf.get('DHCP', 'dhcp_def_server')
        if not dhcp_group:
            dhcp_group = conf.get('DHCP', 'dhcp_def_group')
        from spoke.lib.dhcp import SpokeDHCPHost
        host = SpokeDHCPHost(dhcp_server, dhcp_group)
        result = host.get(host_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #7
0
 def test_get_dhcp_host(self):
     """Fetch DHCP host; return True."""
     dhcp_host = 'testgethost'
     host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group)
     host.create(dhcp_host)
     result = host.get(dhcp_host)['data']
     service_name = self.dhcp_server + self.dhcp_conf_suffix
     group_base_dn = 'cn=%s,cn=%s,%s' % (self.dhcp_group, service_name,
                                         self.base_dn)
     dn = 'cn=%s,%s' % (dhcp_host, group_base_dn)
     dn_info = {'objectClass': ['top', self.dhcp_host_class,
                                self.dhcp_options_class],
                'cn': [dhcp_host]}
     expected_result = [(dn, dn_info)]
     self.assertEqual(result, expected_result)
     host.delete(dhcp_host)
Beispiel #8
0
def reservation_create(dhcp_server, dhcp_group, host_name, mac, ip):
    try:
        from spoke.lib.dhcp import SpokeDHCPHost
        from spoke.lib.dhcp import SpokeDHCPAttr
        host = SpokeDHCPHost(dhcp_server, dhcp_group)
        try:
            host.create(host_name)
        except error.AlreadyExists:
            pass
        attr = SpokeDHCPAttr(dhcp_server, dhcp_group, host_name)
        attr.create("dhcpHWAddress", "ethernet %s" % mac)
        attr.create("dhcpStatements", "fixed-address %s" % ip)
        attr.create("dhcpOption", "host-name \"%s\"" % host_name)
        result = host.get(host_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #9
0
def reservation_create(dhcp_server, dhcp_group, host_name, mac,  ip):
    try:
        from spoke.lib.dhcp import SpokeDHCPHost
        from spoke.lib.dhcp import SpokeDHCPAttr
        host = SpokeDHCPHost(dhcp_server, dhcp_group)
        try:
            host.create(host_name)
        except error.AlreadyExists:
            pass
        attr = SpokeDHCPAttr(dhcp_server, dhcp_group, host_name)
        attr.create("dhcpHWAddress", "ethernet %s" % mac )
        attr.create("dhcpStatements", "fixed-address %s" %ip )
        attr.create("dhcpOption", "host-name \"%s\"" %host_name )
        result = host.get(host_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #10
0
 def test_get_dhcp_host(self):
     """Fetch DHCP host; return True."""
     dhcp_host = 'testgethost'
     host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group)
     host.create(dhcp_host)
     result = host.get(dhcp_host)['data']
     service_name = self.dhcp_server + self.dhcp_conf_suffix
     group_base_dn = 'cn=%s,cn=%s,%s' % (self.dhcp_group, service_name,
                                         self.base_dn)
     dn = 'cn=%s,%s' % (dhcp_host, group_base_dn)
     dn_info = {
         'objectClass':
         ['top', self.dhcp_host_class, self.dhcp_options_class],
         'cn': [dhcp_host]
     }
     expected_result = [(dn, dn_info)]
     self.assertEqual(result, expected_result)
     host.delete(dhcp_host)
Beispiel #11
0
def reservation_create(host_name, mac, ip, dhcp_server=None, dhcp_group=None):
    try:
        conf = _spoke_config(_salt_config('config'))
        if not dhcp_server:
            dhcp_server = conf.get('DHCP', 'dhcp_def_server')
        if not dhcp_group:
            dhcp_group = conf.get('DHCP', 'dhcp_def_group')
        from spoke.lib.dhcp import SpokeDHCPHost
        from spoke.lib.dhcp import SpokeDHCPAttr
        host = SpokeDHCPHost(dhcp_server, dhcp_group)
        try:
            host.create(host_name)
        except error.AlreadyExists:
            pass
        attr = SpokeDHCPAttr(dhcp_server, dhcp_group, host_name)
        attr.create("dhcpHWAddress", "ethernet %s" % mac)
        attr.create("dhcpStatements", "fixed-address %s" % ip)
        attr.create("dhcpOption", "host-name \"%s\"" % host_name)
        result = host.get(host_name)
    except error.SpokeError as e:
        result = common.handle_error(e)
    return result
Beispiel #12
0
    if request['action'] == 'create':
        try:
            mac = request['data']['mac']
            ip = request['data']['ip']
            try:
                mc.info('Creating host %s' % hostname)
                host.create(hostname)
            except error.AlreadyExists:
                mc.info('Host %s already exists' % hostname)
            mc.info('Adding DHCP attributes for host %s' % hostname)
            attr = SpokeDHCPAttr(server, group, hostname)
            attr.create("dhcpHWAddress", "ethernet %s" % mac)
            attr.create("dhcpStatements", "fixed-address %s" % ip)
            attr.create("dhcpOption", "host-name \"%s\"" % hostname)
            mc.data = host.get(hostname)
        except error.SpokeError, e:
            mc.fail(e.msg, e.exit_code)
    elif request['action'] == 'search':
        try:
            hostname = request['data']['hostname']
        except KeyError:
            hostname = None
        try:
            mc.data = host.get(hostname)
            attrs = mc.data['data'][0][1]
            mc.mac = attrs['dhcpHWAddress'][0].split()[1]
            mc.ip = attrs['dhcpStatements'][0].split()[1]
        except error.SpokeError, e:
            mc.fail(e.msg, e.exit_code)
    elif request['action'] == 'delete':
Beispiel #13
0
         
 if request['action'] == 'create':
     try:
         mac = request['data']['mac']
         ip = request['data']['ip']
         try:
             mc.info('Creating host %s' % hostname)
             host.create(hostname)
         except error.AlreadyExists:
             mc.info('Host %s already exists' % hostname)
         mc.info('Adding DHCP attributes for host %s' % hostname)
         attr = SpokeDHCPAttr(server, group, hostname)
         attr.create("dhcpHWAddress", "ethernet %s" % mac )
         attr.create("dhcpStatements", "fixed-address %s" %ip )
         attr.create("dhcpOption", "host-name \"%s\"" %hostname )
         mc.data = host.get(hostname)
     except error.SpokeError, e:
         mc.fail(e.msg, e.exit_code)
 elif request['action'] == 'search':
     try:
         hostname = request['data']['hostname']
     except KeyError:
         hostname = None
     try:
         mc.data = host.get(hostname)
         attrs = mc.data['data'][0][1]
         mc.mac = attrs['dhcpHWAddress'][0].split()[1]
         mc.ip = attrs['dhcpStatements'][0].split()[1]
     except error.SpokeError, e:
         mc.fail(e.msg, e.exit_code)
 elif request['action'] == 'delete':