def shine_node(self, node, settings, container): """ Finalizes setup of one node :param node: the node to be polished :type node: :class:`libcloud.compute.base.Node` :param settings: the fittings plan for this node :type settings: ``dict`` :param container: the container of this node :type container: :class:`plumbery.PlumberyInfrastructure` """ plogging.info("Configuring node '{}'".format(settings['name'])) if node is None: plogging.info("- not found") return try: cpu_prop = CpuConfiguration() cpu_prop.validate(settings) cpu = cpu_prop.configure(node, settings) ram_prop = MemoryConfiguration() ram_prop.validate(settings) memory = ram_prop.configure(node, settings) if memory is not False and cpu is not False: self.set_node_compute(node, cpu, memory) except ConfigurationError as ce: if self.engine.safeMode: plogging.warn(ce.message) else: raise ce for prop_cls in self.configuration_props: try: configuration_prop = prop_cls(engine=container.facility.plumbery, facility=self.facility) configuration_prop.validate(settings) configuration_prop.configure(node, settings) except ConfigurationError as ce: if self.engine.safeMode: plogging.warn(ce.message) else: raise ce container._add_to_pool(node) if 'glue' in settings: self.attach_node(node, settings['glue'])
def shine_node(self, node, settings, container): """ Finalizes setup of one node :param node: the node to be polished :type node: :class:`libcloud.compute.base.Node` :param settings: the fittings plan for this node :type settings: ``dict`` :param container: the container of this node :type container: :class:`plumbery.PlumberyInfrastructure` """ plogging.info("Configuring node '{}'".format(settings['name'])) if node is None: plogging.info("- not found") return try: cpu_prop = CpuConfiguration() cpu_prop.validate(settings) cpu = cpu_prop.configure(node, settings) ram_prop = MemoryConfiguration() ram_prop.validate(settings) memory = ram_prop.configure(node, settings) if memory is not False and cpu is not False: self.set_node_compute(node, cpu, memory) except ConfigurationError as ce: if self.engine.safeMode: plogging.warn(ce.message) else: raise ce for prop_cls in self.configuration_props: try: configuration_prop = prop_cls( engine=container.facility.plumbery, facility=self.facility) configuration_prop.validate(settings) configuration_prop.configure(node, settings) except ConfigurationError as ce: if self.engine.safeMode: plogging.warn(ce.message) else: raise ce container._add_to_pool(node) if 'glue' in settings: self.attach_node(node, settings['glue'])
def configure(self, node, settings): """ prepares a node :param node: the node to be polished :type node: :class:`libcloud.compute.base.Node` :param settings: the fittings plan for this node :type settings: ``dict`` :param container: the container of this node :type container: :class:`plumbery.PlumberyInfrastructure` """ if self._element_name_ in settings: plogging.info("preparing node '{}'".format(settings['name'])) if node is None: plogging.info("- not found") return timeout = 300 tick = 6 while node.extra['status'].action == 'START_SERVER': time.sleep(tick) node = self.nodes.get_node(node.name) timeout -= tick if timeout < 0: break if node.state != NodeState.RUNNING: plogging.info("- skipped - node is not running") return ipv6 = node.extra['ipv6'] ip = node.private_ips[0] if ipv6 is None: plogging.error('No ipv6 address for node, cannot configure') return # Check to see if WinRM works.. try: self._try_winrm(node) except winrm.exceptions.InvalidCredentialsError: plogging.warn('initial login to %s failed, trying to setup winrm remotely', ip) self._setup_winrm(node) self._try_winrm(node) except requests.exceptions.ConnectionError: plogging.warn('initial connection to %s failed, trying to setup winrm remotely', ip) self._setup_winrm(node) self._try_winrm(node) # OK, we're all ready. Let's look at the node config and start commands cmds = [] hostname = settings[self._element_name_].get('hostname', None) if hostname is not None and isinstance(hostname, str): cmds.append(('powershell.exe', ['Rename-Computer', '-NewName', hostname])) extra_cmds = settings[self._element_name_].get('cmds', []) for command in extra_cmds: command = command.rstrip() command_parts = command.split(' ') cmds.append((command_parts[0], command_parts[1:])) out, err = self._winrm_commands(node, cmds) plogging.info(out) plogging.warning(err) plogging.debug('locking down winrm') self._lockdown_winrm(node) else: return False