def test_create_dhcp_host_twice(self): """Create DHCP host twice; raise AlreadyExists.""" dhcp_host = 'testcreatehosttwice' host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(dhcp_host) self.assertRaises(error.AlreadyExists, host.create, dhcp_host) host.delete(dhcp_host)
def test_create_dhcp_host_twice(self): """Create DHCP host twice; raise AlreadyExists.""" dhcp_host = "testcreatehosttwice" host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(dhcp_host) self.assertRaises(error.AlreadyExists, host.create, dhcp_host) host.delete(dhcp_host)
def test_delete_dhcp_group_before_hosts(self): """Delete DHCP group while hosts present, raise SaveTheBabies.""" dhcp_host = "testdeletebeforehost" host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(dhcp_host) group = SpokeDHCPGroup(self.dhcp_server) self.assertRaises(error.SaveTheBabies, group.delete, self.dhcp_group) host.delete(dhcp_host)
def test_delete_dhcp_group_before_hosts(self): """Delete DHCP group while hosts present, raise SaveTheBabies.""" dhcp_host = 'testdeletebeforehost' host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(dhcp_host) group = SpokeDHCPGroup(self.dhcp_server) self.assertRaises(error.SaveTheBabies, group.delete, self.dhcp_group) host.delete(dhcp_host)
def setUp(self): server = SpokeDHCPServer() server.create(self.dhcp_server) dhcp = SpokeDHCPService() dhcp.create(self.dhcp_server) group = SpokeDHCPGroup(self.dhcp_server) group.create(self.dhcp_group) host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(self.dhcp_host)
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)
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)
def host_create(dhcp_server, dhcp_group, dhcp_host): try: from spoke.lib.dhcp import SpokeDHCPHost host = SpokeDHCPHost(dhcp_server, dhcp_group) result = host.create(dhcp_host) except error.SpokeError as e: result = common.handle_error(e) return result
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
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
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)
def host_create(dhcp_host, 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.create(dhcp_host) except error.SpokeError as e: result = common.handle_error(e) return result
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
except Exception as e: mc.fail(e) if request['action'] != 'search': try: hostname = request['data']['hostname'] except KeyError: mc.fail("Missing input hostname", 2) 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
except Exception as e: mc.fail(e) if request['action'] != 'search': try: hostname = request['data']['hostname'] except KeyError: mc.fail("Missing input hostname", 2) 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
def test_delete_dhcp_host(self): """Delete DHCP host, return True.""" dhcp_host = "testdeletehost" host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(dhcp_host) self.assertTrue(host.delete(dhcp_host))
def test_delete_dhcp_host(self): """Delete DHCP host, return True.""" dhcp_host = 'testdeletehost' host = SpokeDHCPHost(self.dhcp_server, self.dhcp_group) host.create(dhcp_host) self.assertTrue(host.delete(dhcp_host))