Skip to content

Commit 33493ab

Browse files
authored
Merge pull request #16 from Crunch-io/update-dynamic-hostname
Update dynamic_hostname.py
2 parents 95fb718 + a7df1de commit 33493ab

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

swarmy/dynamic_hostname.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
--domain-tag=<domain_tag>
3131
Instance tag name to use to retrieve name. Overrides --domain
3232
--hosted-zone=<hosted_zone>
33-
By default, we try to add the hostname to the zone name found using --domain or --domain-tag, but if this is different for you, specify this parameter. Ignored if --no-dns is specified
33+
By default, we try to add the hostname to the zone name found using --domain or --domain-tag, but if this isdifferent for you, specify this parameter. Ignored if --no-dns is specified
3434
--prefix=<prefix>
3535
The hostname prefix to use. Will be used verbatim (no '-' will be appended). E.g., 'ip' will become 'ip10-2-3-4' and 'ip-' will become 'ip-10-2-3-4' [default: ip-]
3636
--prefix-tag=<prefix_tag>
@@ -44,7 +44,7 @@
4444

4545
from typing import Optional, Dict, Any, Union
4646
from dataclasses import dataclass
47-
import lib
47+
from swarmy import lib, _version
4848
from docopt import docopt
4949
import sys
5050

@@ -60,7 +60,7 @@ class HostnameConfig:
6060
sep: str = ''
6161

6262
@lib.metadata_required
63-
def get_ip(public: bool = False) -> str:
63+
def get_ip(public: bool = False) -> Optional[str]:
6464
"""
6565
Get the current ip address (private by default)
6666
@@ -71,8 +71,8 @@ def get_ip(public: bool = False) -> str:
7171
str: IP address
7272
"""
7373
if public:
74-
return lib._metadata.get('public-ipv4', '169.254.0.1')
75-
return lib._metadata.get('local-ipv4')
74+
return lib._metadata_cache['public-ipv4', '169.254.0.1']
75+
return lib._metadata_cache['privateIp']
7676

7777
@lib.instance_tags_required
7878
def get_domain_from_tags(tagName: str) -> Optional[str]:
@@ -85,7 +85,7 @@ def get_domain_from_tags(tagName: str) -> Optional[str]:
8585
Returns:
8686
Optional[str]: Domain name if found, None otherwise
8787
"""
88-
return lib._tags.get(tagName)
88+
return lib._tags_cache(tagName)
8989

9090
@lib.instance_tags_required
9191
def get_prefix_from_tags(tagName: str) -> Optional[str]:
@@ -98,14 +98,14 @@ def get_prefix_from_tags(tagName: str) -> Optional[str]:
9898
Returns:
9999
Optional[str]: Prefix if found, None otherwise
100100
"""
101-
return lib._tags.get(tagName)
101+
return lib._tags_cache(tagName)
102102

103103
def gen_fqdn(config: HostnameConfig) -> str:
104104
"""
105-
Generate FQDN from configuration
105+
Generate FQDN from configuration with proper IP part handling
106106
107107
Args:
108-
config: HostnameConfig instance containing all necessary parameters
108+
config: HostnameConfig with ip, domain, numparts, prefix, and sep
109109
110110
Returns:
111111
str: Generated FQDN
@@ -115,11 +115,11 @@ def gen_fqdn(config: HostnameConfig) -> str:
115115
else:
116116
host_ip_part = ""
117117

118-
return f"{config.prefix}{config.sep}{host_ip_part}.{config.domain}"
118+
return f"{config.prefix}{host_ip_part}.{config.domain}"
119119

120120
def parse_arguments() -> Dict[str, Any]:
121121
"""Parse and validate command line arguments"""
122-
return docopt(helpstr, version=f"dynamic_hostname {lib.version}")
122+
return docopt(helpstr, version=f"dynamic_hostname {_version.version}")
123123

124124
def get_numparts(arguments: Dict[str, Any]) -> int:
125125
"""Determine number of IP parts to use"""

0 commit comments

Comments
 (0)