Difference between revisions of "Linode"
From Organic Design wiki
(Created page with "{{stub}} <source lang="bash"> pip3 install linode-cli linode-cli configure --token linode-cli --json --pretty domains list </source>") |
(example in perl) |
||
Line 1: | Line 1: | ||
{{stub}} | {{stub}} | ||
+ | Installing the linode CLI: | ||
<source lang="bash"> | <source lang="bash"> | ||
pip3 install linode-cli | pip3 install linode-cli | ||
linode-cli configure --token | linode-cli configure --token | ||
linode-cli --json --pretty domains list | linode-cli --json --pretty domains list | ||
+ | </source> | ||
+ | |||
+ | |||
+ | Example Perl code using LWP to update an A record: | ||
+ | <source lang="perl"> | ||
+ | # Set up a user agent with our token as default header | ||
+ | $ua = LWP::UserAgent->new(); | ||
+ | $ua->default_header( | ||
+ | 'Content-Type' => "application/json", | ||
+ | 'Authorization' => "Bearer $dnsApiKey" | ||
+ | ); | ||
+ | |||
+ | # Find the ID of the domain | ||
+ | $json = $ua->get( 'https://api.linode.com/v4/domains' )->content; | ||
+ | for ( @{ decode_json( $json )->{data} } ) { | ||
+ | $domain_id = $_->{id} if $_->{domain} eq $domain; | ||
+ | } | ||
+ | die "Domain name not found" unless $domain_id; | ||
+ | |||
+ | # Find the ID of the A record having the host name | ||
+ | $json = $ua->get( "https://api.linode.com/v4/domains/$domain_id/records" )->content; | ||
+ | for ( @{ decode_json( $json )->{data} } ) { | ||
+ | $record_id = $_->{id} if $_->{name} eq $host; | ||
+ | } | ||
+ | die "Host name not found" unless $record_id; | ||
+ | |||
+ | # Update the A record | ||
+ | $ua->put( | ||
+ | "https://api.linode.com/v4/domains/$domain_id/records/$record_id", | ||
+ | 'Content' => encode_json({ 'target' => $new_IP }) | ||
+ | ); | ||
</source> | </source> |
Revision as of 02:08, 28 July 2023
Installing the linode CLI:
pip3 install linode-cli
linode-cli configure --token
linode-cli --json --pretty domains list
Example Perl code using LWP to update an A record:
# Set up a user agent with our token as default header
$ua = LWP::UserAgent->new();
$ua->default_header(
'Content-Type' => "application/json",
'Authorization' => "Bearer $dnsApiKey"
);
# Find the ID of the domain
$json = $ua->get( 'https://api.linode.com/v4/domains' )->content;
for ( @{ decode_json( $json )->{data} } ) {
$domain_id = $_->{id} if $_->{domain} eq $domain;
}
die "Domain name not found" unless $domain_id;
# Find the ID of the A record having the host name
$json = $ua->get( "https://api.linode.com/v4/domains/$domain_id/records" )->content;
for ( @{ decode_json( $json )->{data} } ) {
$record_id = $_->{id} if $_->{name} eq $host;
}
die "Host name not found" unless $record_id;
# Update the A record
$ua->put(
"https://api.linode.com/v4/domains/$domain_id/records/$record_id",
'Content' => encode_json({ 'target' => $new_IP })
);