Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Equinix Metal metadata service #680

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix linting in Equinix Metal provider
  • Loading branch information
displague committed Jun 28, 2021
commit 71a80780de0dea3d6b87b7822f2a4565d840b98e
13 changes: 5 additions & 8 deletions cloudinit/sources/DataSourceEquinixMetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
from cloudinit import log as logging
from cloudinit.sources import DataSourceEc2 as EC2
from cloudinit import sources
from cloudinit import util

import cloudinit.sources.helpers.equinixmetal as equinixmetal_helper

LOG = logging.getLogger(__name__)

Expand All @@ -22,7 +19,7 @@
}


EQUINIXMETAL_IQN_PATTERN = "iqn\.[0-9-]{6,7}\.(net\.packet|equinix\.metal):"
EQUINIXMETAL_IQN_PATTERN = r'iqn\.[0-9-]{6,7}\.(net\.packet|equinix\.metal):'


class DataSourceEquinixMetal(EC2.DataSourceEc2):
Expand All @@ -42,14 +39,13 @@ def get_public_ssh_keys(self):
return parse_public_keys(self.metadata.get('public-keys', {}))

def _get_cloud_name(self):
if _is_equinixmetal():
if self._is_equinixmetal():
return EC2.CloudNames.EQUINIXMETAL
else:
return EC2.CloudNames.NO_EC2_METADATA


def _is_equinixmetal():
return re.match(EQUINIXMETAL_IQN_PATTERN, self.metadata.get('iqn', ''))
def _is_equinixmetal(self):
return re.match(EQUINIXMETAL_IQN_PATTERN, self.metadata.get('iqn', ''))


def parse_public_keys(public_keys):
Expand All @@ -73,6 +69,7 @@ def parse_public_keys(public_keys):
(DataSourceEquinixMetal, (sources.DEP_NETWORK)),
]


# Return a list of data sources that match this set of dependencies
def get_datasource_list(depends):
return sources.list_from_depends(depends, datasources)
Expand Down
12 changes: 2 additions & 10 deletions tests/unittests/test_datasource/test_equinixmetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def register_helper(register, base_url, body):
class TestEquinixMetalDatasource(test_helpers.HttprettyTestCase):
def setUp(self):
super(TestEquinixMetalDatasource, self).setUp()
cfg = {'datasource': {'EquinixMetal': {'timeout': '1', 'max_wait': '1'}}}
cfg = {'datasource': {
'EquinixMetal': {'timeout': '1', 'max_wait': '1'}}}
distro = {}
paths = helpers.Paths({'run_dir': self.tmp_dir()})
self.ds = em.DataSourceEquinixMetal(cfg, distro, paths)
Expand Down Expand Up @@ -145,15 +146,6 @@ def test_with_mock_server(self, m_is_equinixmetal):
self.assertEqual(
'metadata (http://100.100.100.200)', self.ds.subplatform)

@mock.patch("cloudinit.sources.DataSourceEquinixMetal._is_equinixmetal")
def test_returns_false_when_not_on_equinixmetal(self, m_is_equinixmetal):
"""If is_equinixmetal returns false, then get_data should return False."""
m_is_equinixmetal.return_value = False
self.regist_default_server()
ret = self.ds.get_data()
self.assertEqual(1, m_is_equinixmetal.call_count)
self.assertEqual(False, ret)

def test_parse_public_keys(self):
public_keys = {}
self.assertEqual(em.parse_public_keys(public_keys), [])
Expand Down