def on_init(self, *args, **kwargs): bus.on("before_hello", self.on_before_hello) bus.on("before_host_init", self.on_before_host_init) bus.on("before_restart", self.on_before_restart) bus.on("before_reboot_finish", self.on_before_reboot_finish) try: system(('ntpdate', '-u', '0.amazon.pool.ntp.org')) except: pass msg_service = bus.messaging_service producer = msg_service.get_producer() producer.on("before_send", self.on_before_message_send) if not os_dist.windows_family and not __node__.get('hostname'): # Set the hostname to this instance's public hostname try: hostname_as_pubdns = int(__ec2__['hostname_as_pubdns']) except: hostname_as_pubdns = True if hostname_as_pubdns: pub_hostname = self._platform.get_public_hostname() self._logger.debug('Setting hostname to %s' % pub_hostname) system2("hostname " + pub_hostname, shell=True) if disttool.is_ubuntu(): # Ubuntu cloud-init scripts may disable root ssh login for path in ('/etc/ec2-init/ec2-config.cfg', '/etc/cloud/cloud.cfg'): if os.path.exists(path): c = None with open(path, 'r') as fp: c = fp.read() c = re.sub(re.compile(r'^disable_root[^:=]*([:=]).*', re.M), r'disable_root\1 0', c) with open(path, 'w') as fp: fp.write(c) if not linux.os.windows_family: # Add server ssh public key to authorized_keys ssh_key = self._platform.get_ssh_pub_key() if ssh_key: add_authorized_key(ssh_key) # Mount ephemeral devices # Seen on eucalyptus: # - fstab contains invalid fstype and `mount -a` fails if self._platform.name == 'eucalyptus': mtab = mount.mounts() fstab = mount.fstab() for device in self._platform.instance_store_devices: if os.path.exists(device) and device in fstab and device not in mtab: entry = fstab[device] try: mount.mount(device, entry.mpoint, '-o', entry.options) except: self._logger.warn(sys.exc_info()[1]) else: if not os_dist.windows_family: system2('mount -a', shell=True, raise_exc=False)
def _assign_hostname(self): if not __node__.get('hostname'): return __node__['hostname'] = __node__['hostname'].replace(' ', '') try: self._system_api.set_hostname(__node__['hostname']) except NotImplementedError, e: self._logger.debug(e)
def get_node_name(self): return __node__.get("hostname") or "{0}-{1}-{2}".format( self._platform.name, self._platform.get_public_ip(), time.time() )
def on_init(self, *args, **kwargs): bus.on("before_hello", self.on_before_hello) bus.on("before_host_init", self.on_before_host_init) bus.on("before_restart", self.on_before_restart) bus.on("before_reboot_finish", self.on_before_reboot_finish) try: system(('ntpdate', '-u', '0.amazon.pool.ntp.org')) except: pass msg_service = bus.messaging_service producer = msg_service.get_producer() producer.on("before_send", self.on_before_message_send) if not os_dist.windows_family and not __node__.get('hostname'): # Set the hostname to this instance's public hostname try: hostname_as_pubdns = int(__ec2__['hostname_as_pubdns']) except: hostname_as_pubdns = True if hostname_as_pubdns: pub_hostname = self._platform.get_public_hostname() self._logger.debug('Setting hostname to %s' % pub_hostname) system2("hostname " + pub_hostname, shell=True) if disttool.is_ubuntu(): # Ubuntu cloud-init scripts may disable root ssh login for path in ('/etc/ec2-init/ec2-config.cfg', '/etc/cloud/cloud.cfg'): if os.path.exists(path): c = None with open(path, 'r') as fp: c = fp.read() c = re.sub( re.compile(r'^disable_root[^:=]*([:=]).*', re.M), r'disable_root\1 0', c) with open(path, 'w') as fp: fp.write(c) if not linux.os.windows_family: # Add server ssh public key to authorized_keys ssh_key = self._platform.get_ssh_pub_key() if ssh_key: add_authorized_key(ssh_key) # Mount ephemeral devices # Seen on eucalyptus: # - fstab contains invalid fstype and `mount -a` fails if self._platform.name == 'eucalyptus': mtab = mount.mounts() fstab = mount.fstab() for device in self._platform.instance_store_devices: if os.path.exists( device) and device in fstab and device not in mtab: entry = fstab[device] try: mount.mount(device, entry.mpoint, '-o', entry.options) except: self._logger.warn(sys.exc_info()[1]) else: if not os_dist.windows_family: system2('mount -a', shell=True, raise_exc=False)
def get_node_name(self): return __node__.get('hostname') or \ '{0}-{1}-{2}'.format( self._platform.name, self._platform.get_public_ip(), time.time())
def _shutdown_bollard(self): if __node__.get('bollard'): __node__['bollard'].stop(workers=False)