def _get_cloud_type(): ''' Description: Get the type of the cloud back end this instance is running on. Currently utilizes Puppet's facter via a Python subprocess call. Currently supported cloud back end types are: EC2, RHEV, VSPHERE Input: None Returns: One of the following strings: 'EC2', 'RHEV', 'VSPHERE' or 'UNKNOWN' ''' system_facts = get_system_info(['productname', 'ec2_ami_id']) # Check for productname key as found on RHEVm and VMware/vSphere if 'productname' in system_facts: if 'RHEV' in system_facts['productname'].upper(): return 'RHEV' if 'VMWARE' in system_facts['productname'].upper(): return 'VSPHERE' # Check for ec2_ami_id key as found on EC2 if 'ec2_ami_id' in system_facts: return 'EC2' return 'UNKNOWN'
def generate_cs_str(self): """ Description: Generate the provides parameters list. Input: The provides parameters string obtained from the Config Server. Returns: A string to send back to the Config Server with prifix 'audrey_data='<url encoded return data>' The return portion will be delimited with an | and an & To ensure all the data is transmitted the entire string will be terminated with an "|". This will be a continuous text string (no CR or New Line). Data portion Format: |name1&val1|name2&val...|nameN$valN| e.g.: |ipaddress&<b64/10.118.46.205>|virtual&<b64/xenu>| The return string format: "audrey_data=<url encoded data portion>" """ LOGGER.info("Invoked Provides.generate_cs_str()") system_info = get_system_info(self.keys()) for param in self.keys(): if param in system_info: self[param] = base64.b64encode(system_info[param]) def is_not_none(abc, xyz): """ used to reduce a list of key value paired tuples to only ones that have None as their value """ if xyz[1] is not None: abc.append(xyz) return abc non_none = reduce(is_not_none, self.items(), []) kv_pairs = ["&".join(x) for x in non_none] if not kv_pairs: kv_pairs = ["&"] return urllib.urlencode({"audrey_data": "|%s|" % "|".join(kv_pairs)})
def test_multiple_with_undefined_facts(self): self.assertIn('ipaddress', get_system_info(['not_real', 'ipaddress']))
def test_single_undefined_facts(self): self.assertEqual(get_system_info(['not_real']), {})
def test_mutliple_facs(self): self.assertIn('ipaddress', get_system_info(['ipaddress']))
def test_single_fact(self): self.assertIn('uptime', get_system_info(['uptime']))
def test_multiple_with_undefined_facts(self): self.assertIn('uptime', get_system_info(['not_real', 'uptime'])) self.assertNotIn('not_real', get_system_info(['not_real', 'uptime']))
def test_mutliple_facts(self): self.assertIn('uptime', get_system_info(['timezone', 'uptime'])) self.assertIn('timezone', get_system_info(['timezone', 'uptime']))