YaPI::DHCPD - DHCP server configuration API
This package is the public YaST2 API to configure the ISC DHCP server
use YaPI::DHCPD
$status = StopDhcpService($config)
$status = StartDhcpService($config)
$status = GetDhcpServiceStatus($config)
$ret = AddDeclaration($config,$type,$id,$parent_type,$parent_id)
$ret = DeleteDeclaration($config,$type,$id)
$parent = GetDeclarationParent($config,$type,$id)
$ret = SetDeclarationParent($config,$type,$id,$new_parent_type,$new_parent_id)
$children = GetChildrenOfDeclaration($config,$type,$id)
$options = GetDeclarationOptions($config,$type,$id)
$ret = SetDeclarationOptions($config,$type,$id,$options)
$directives = GetDeclarationDirectives($config,$type,$id)
$ret = SetDeclarationDirectives($config,$type,$id,$directives)
$exists = ExistsDeclaration($config,$type,$id)
The $config
parameter is always a refernece to a hash, that contains various
configuration options. Currently following keys are supported:
"use_ldap"
says if settings should be written/read to LDAP or not. Possible values are
1 (use LDAP if configured properly) or 0 (don't use LDAP).
If not specified, mode is detected automatically.
"ldap_passwd"
holds the LDAP password needed for authentication against the LDAP server.
$status StopDhcpService ($config);
Immediatelly stops the DHCP service. Returns nonzero if operation succeeded, zero if operation failed.
EXAMPLE:
my $status = StopDhcpService ({}); if ($status == 0) { print "Stopping DHCP server failed"; } else { print "Stopping DHCP server succeeded"; }
$status StartDhcpService ($config);
Immediatelly starts the DHCP service. Returns nonzero if operation succeeded, zero if operation failed.
EXAMPLE:
my $status = StartDhcpService ({}); if ($status == 0) { print "Starting DHCP server failed"; } else { print "Starting DHCP server succeeded"; }
$status GetDhcpServiceStatus ($config);
Check if DHCP service is running. Returns nonzero if service is running, zero otherwise.
EXAMPLE:
my $status = GetDhcpServiceStatus ({}); if ($status == 0) { print "DHCP server is not running"; } else { print "DHCP server is running"; }
$ret = AddDeclaration ($config, $type, $id, $parent_type, $parent_id);
Add a new empty DHCP declaration. $type is one of subnet, host, group, pool, shared-network. $id is identification of the declaration (eg. host name for the host, $address netmask $netmask for subnet declaration. $parent_type and $parent_id specify the declaration within that the new declaration shall be created.
Returns nonzero on success, zero on fail.
EXAMPLE:
my $type = "host"; my $id = "client"; my $ret = AddDeclaration ({}, $type, $id, "", ""); This creates a new host on the top level of the configuration file (not within any network or group)
$ret = DeleteDeclaration ($config, $type, $id);
Deletes specified declaration including its whole subtree.
Returns nonzero on success, zero on fail.
EXAMPLE:
my $type = "host"; my $id = "client"; my $ret = DeleteDeclaration ({}, $type, $id);
This deletes the host created in the example of the AddDeclaration function
$parent = GetDeclarationParent ($config, $type, $id);
Returns the parent of specified declaration. It is returned as a hash with keys "type" and "id".
Returns the specification of the parent or undef if the specified declaration was not found.
EXAMPLE:
my $type = "host"; my $id = "client"; my $parent = GetDeclarationParent ({}, $type, $id); if (! defined ($parent)) { print "Specified declaration not found" } else { my $par_type = $parent->{"type"}; my $par_id = $parent->{"id"}; print "Parent type: $par_type"; print "Parent id: $par_id; }
$ret = SetDeclarationParent ($config, $type, $id, $new_parent_type, $new_parent_id);
Sets specified parent to the specified declaration (moves it in the tree). The declaration is moved with its complete subtree.
Returns nonzero on success, zero on fail.
EXAMPLE:
my $type = "host"; my $id = "client"; my $ret = SetDeclarationParent ({}, $type, $id, "", "");
Moves the host declaration from the ssubnet it resides in to the top level.
$children = GetChildrenOfDeclaration ($config, $type, $id);
Get all children of a declaration.
Returns a list of hashes with keys "type" and "id" and appropriate values on success. On fail, returns undef.
EXAMPLE:
my $children = GetChildrenOfDeclaration ({}, "subnet", "192.168.0.0 netmask 255.255.255.0"); if (! defined ($children)) { print "Specified declaration not found"; } else { foreach my $child (@{$children}) { my $type = $child->{"type"}; my $id = $child->{"id"}; print "Have child $type $id"; } }
$options = GetDeclarationOptions ($config, $type, $id);
Get all options of the specified declaration.
Returns all options of specified declaration as a list of hashes with keys "key" and "value" and appropriate values on success. On fail, returns undef.
EXAMPLE:
my $options = GetDeclarationOptions ({}, "subnet", "192.168.0.0 netmask 255.255.255.0"); if (! defined ($options)) { print "Specified declaration not found"; } else { foreach my $option (@{$options}) { my $key = $option->{"key"}; my $value = $option->{"value"}; print "Have option $key with value $value"; } }
Prints all options adjusted to tbe specified declaration.
$ret = SetDeclarationOptions ({}, $config, $type, $id, $options);
Sets all options of specified declaration. The options argument has the same structure as return value of the GetDeclarationOptions function.
Returns nonzero on success, zero on fail.
EXAMPLE:
my $options = [ { "key" => "domain-name-servers", "value" => "ns1.internal.example.org ns2.internal.example.org", }, { "key" => "domain-name", "value" => "\"internal.example.org\"", }, ] $success = SetDeclarationOptions ("host", "client", $options);
Sets specified options to the specified declaration.
$directives = GetDeclarationDirectives ($config, $type, $id);
Get all directives of the specified declaration.
Returns all directives of specified declaration as a list of hashes with keys "key" and "value" and appropriate values on success. On fail, returns undef.
EXAMPLE:
my $directives = GetDeclarationDirectives ({}, "subnet", "192.168.0.0 netmask 255.255.255.0"); if (! defined ($directives)) { print "Specified declaration not found"; } else { foreach my $directive (@{$directives}) { my $key = $option->{"key"}; my $value = $option->{"value"}; print "Have directive $key with value $value"; } }
Prints all directives adjusted to tbe specified declaration.
$ret = SetDeclarationDirectives ($config, $type, $id, $directives);
Sets all directives of specified declaration. The directives argument has the same structure as return value of the GetDeclarationDirectives function.
Returns nonzero on success, zero on fail.
EXAMPLE:
my $directives = [ { "key" => "default-lease-time", "value" => "600", }, { "key" => "max-lease-time", "value" => "7200", }, ] $success = SetDeclarationDirectives ({}, "host", "client", $directives);
Sets specified directives to the specified declaration.
$exists = ExistsDeclaration ($config, $type, $id);
Checks if specified declaration exists.
Returns nonzero if declaration found, zero otherwise.
EXAMPLE:
my $exists = ExistsDeclaration ({}, "host", "client"); if ($exists) { print "Host found"; } else { print "Host not found"; }
Checks if specified host has an entry in the configuration of DHCP server.