summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiril Vladimiroff <kiril.vladimiroff@cloudsigma.com>2014-05-30 14:19:10 +0300
committerKiril Vladimiroff <kiril.vladimiroff@cloudsigma.com>2014-05-30 14:19:10 +0300
commit71d817c427f06e9e1f5d547d5db191e541963d31 (patch)
tree5ec59777a294f28f866e2000cc7ab1d4ee0f3cf6
parent882f7186143c337e0f30f4ed2c0415f238ed5c83 (diff)
downloadvyos-cloud-init-71d817c427f06e9e1f5d547d5db191e541963d31.tar.gz
vyos-cloud-init-71d817c427f06e9e1f5d547d5db191e541963d31.zip
Use dmidecode to detect if cloud-init runs in CloudSigma's infrastructure
-rw-r--r--cloudinit/sources/DataSourceCloudSigma.py22
-rw-r--r--tests/unittests/test_datasource/test_cloudsigma.py1
2 files changed, 23 insertions, 0 deletions
diff --git a/cloudinit/sources/DataSourceCloudSigma.py b/cloudinit/sources/DataSourceCloudSigma.py
index e1c7e566..fffff91e 100644
--- a/cloudinit/sources/DataSourceCloudSigma.py
+++ b/cloudinit/sources/DataSourceCloudSigma.py
@@ -20,6 +20,7 @@ import re
from cloudinit import log as logging
from cloudinit import sources
+from cloudinit import util
from cloudinit.cs_utils import Cepko
LOG = logging.getLogger(__name__)
@@ -40,12 +41,33 @@ class DataSourceCloudSigma(sources.DataSource):
self.ssh_public_key = ''
sources.DataSource.__init__(self, sys_cfg, distro, paths)
+ def is_running_in_cloudsigma(self):
+ """
+ Uses dmidecode to detect if this instance of cloud-init is running
+ in the CloudSigma's infrastructure.
+ """
+ dmidecode_path = util.which('dmidecode')
+ if not dmidecode_path:
+ return False
+
+ LOG.debug("Determining hypervisor product name via dmidecode")
+ try:
+ system_product_name, _ = util.subp([dmidecode_path, "-s", "system-product-name"])
+ return 'cloudsigma' in system_product_name.lower()
+ except:
+ LOG.exception("Failed to get hypervisor product name")
+
+ return False
+
def get_data(self):
"""
Metadata is the whole server context and /meta/cloud-config is used
as userdata.
"""
dsmode = None
+ if not self.is_running_in_cloudsigma():
+ return False
+
try:
server_context = self.cepko.all().result
server_meta = server_context['meta']
diff --git a/tests/unittests/test_datasource/test_cloudsigma.py b/tests/unittests/test_datasource/test_cloudsigma.py
index adbb4afb..25dc12f3 100644
--- a/tests/unittests/test_datasource/test_cloudsigma.py
+++ b/tests/unittests/test_datasource/test_cloudsigma.py
@@ -35,6 +35,7 @@ class CepkoMock(Cepko):
class DataSourceCloudSigmaTest(TestCase):
def setUp(self):
self.datasource = DataSourceCloudSigma.DataSourceCloudSigma("", "", "")
+ self.datasource.is_running_in_cloudsigma = lambda: True
self.datasource.cepko = CepkoMock(SERVER_CONTEXT)
self.datasource.get_data()