示例#1
0
 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)
示例#2
0
文件: test_dhcp.py 项目: mattmb/spoke
 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)
示例#3
0
文件: test_dhcp.py 项目: mattmb/spoke
 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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
文件: test_dhcp.py 项目: mattmb/spoke
 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)
示例#7
0
文件: test_dhcp.py 项目: mattmb/spoke
 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)
示例#8
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)
示例#9
0
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
示例#10
0
文件: dhcp.py 项目: mattmb/spoke
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
示例#11
0
文件: dhcp.py 项目: mattmb/spoke
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
示例#12
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
示例#13
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)
示例#14
0
文件: dhcp.py 项目: KrisSaxton/spoke
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
示例#15
0
文件: dhcp.py 项目: KrisSaxton/spoke
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
示例#16
0
    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
示例#17
0
    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
示例#18
0
文件: test_dhcp.py 项目: mattmb/spoke
 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))
示例#19
0
 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))