def fetch_node_info(self): orig_attrs = {} info, tags = self._sliceapi.GetNodeInfo(self._node_id) info = info[0] tags = dict( (t['tagname'],t['value']) for t in tags ) orig_attrs['min_num_external_ifaces'] = self.min_num_external_ifaces orig_attrs['max_num_external_ifaces'] = self.max_num_external_ifaces self.min_num_external_ifaces = None self.max_num_external_ifaces = None if not self._timeframe: self._timeframe = 'w' replacements = {'timeframe':self._timeframe} for attr, tag in self.BASEFILTERS.iteritems(): if tag in info: value = info[tag] if hasattr(self, attr): orig_attrs[attr] = getattr(self, attr) setattr(self, attr, value) for attr, (tag,_) in self.TAGFILTERS.iteritems(): tag = tag % replacements if tag in tags: value = tags[tag] if hasattr(self, attr): orig_attrs[attr] = getattr(self, attr) if not value or value.lower() == 'n/a': value = None setattr(self, attr, value) if 'peer_id' in info: orig_attrs['site'] = self.site self.site = self._sliceapi.peer_map[info['peer_id']] if 'interface_ids' in info: self.min_num_external_ifaces = \ self.max_num_external_ifaces = len(info['interface_ids']) if 'ssh_rsa_key' in info: orig_attrs['server_key'] = self.server_key self.server_key = info['ssh_rsa_key'] self.hostip = server.gethostbyname(self.hostname) try: self.__orig_attrs except AttributeError: self.__orig_attrs = orig_attrs
def fetch_node_info(self): orig_attrs = {} info, tags = self._sliceapi.GetNodeInfo(self._node_id) info = info[0] tags = dict((t['tagname'], t['value']) for t in tags) orig_attrs['min_num_external_ifaces'] = self.min_num_external_ifaces orig_attrs['max_num_external_ifaces'] = self.max_num_external_ifaces self.min_num_external_ifaces = None self.max_num_external_ifaces = None if not self._timeframe: self._timeframe = 'w' replacements = {'timeframe': self._timeframe} for attr, tag in self.BASEFILTERS.iteritems(): if tag in info: value = info[tag] if hasattr(self, attr): orig_attrs[attr] = getattr(self, attr) setattr(self, attr, value) for attr, (tag, _) in self.TAGFILTERS.iteritems(): tag = tag % replacements if tag in tags: value = tags[tag] if hasattr(self, attr): orig_attrs[attr] = getattr(self, attr) if not value or value.lower() == 'n/a': value = None setattr(self, attr, value) if 'peer_id' in info: orig_attrs['site'] = self.site self.site = self._sliceapi.peer_map[info['peer_id']] if 'interface_ids' in info: self.min_num_external_ifaces = \ self.max_num_external_ifaces = len(info['interface_ids']) if 'ssh_rsa_key' in info: orig_attrs['server_key'] = self.server_key self.server_key = info['ssh_rsa_key'] self.hostip = server.gethostbyname(self.hostname) try: self.__orig_attrs except AttributeError: self.__orig_attrs = orig_attrs
def getSpanningTree(nodes, root = None, maxbranching = 2, hostgetter = operator.attrgetter('hostname')): if not root: # Pick root (deterministically) root = min(nodes, key=hostgetter) # Obtain all IPs in numeric format # (which means faster distance computations) for node in nodes: node._ip = server.gethostbyname(hostgetter(node)) node._ip_n = struct.unpack('!L', socket.inet_aton(node._ip))[0] # Compute plan # NOTE: the plan is an iterator plan = mst.mst( nodes, lambda a,b : ipaddr2.ipdistn(a._ip_n, b._ip_n), root = root, maxbranching = maxbranching) return plan
def getSpanningTree(nodes, root=None, maxbranching=2, hostgetter=operator.attrgetter('hostname')): if not root: # Pick root (deterministically) root = min(nodes, key=hostgetter) # Obtain all IPs in numeric format # (which means faster distance computations) for node in nodes: node._ip = server.gethostbyname(hostgetter(node)) node._ip_n = struct.unpack('!L', socket.inet_aton(node._ip))[0] # Compute plan # NOTE: the plan is an iterator plan = mst.mst(nodes, lambda a, b: ipaddr2.ipdistn(a._ip_n, b._ip_n), root=root, maxbranching=maxbranching) return plan
def resolvable(node_id): try: addr = server.gethostbyname(hostnames[node_id]) return addr is not None except: return False
def do_spanning_deployment_plan(self): # Create application groups by collecting all applications # based on their hash - the hash should contain everything that # defines them and the platform they're built def dephash(app): return ( frozenset((app.depends or "").split(' ')), frozenset((app.sources or "").split(' ')), app.build, app.install, app.node.architecture, app.node.operatingSystem, app.node.pl_distro, app.__class__, ) depgroups = collections.defaultdict(list) for element in self._elements.itervalues(): if isinstance(element, self._app.Dependency): depgroups[dephash(element)].append(element) elif isinstance(element, self._node.Node): deps = element._yum_dependencies if deps: depgroups[dephash(deps)].append(deps) # Set up spanning deployment for those applications that # have been deployed in several nodes. for dh, group in depgroups.iteritems(): if len(group) > 1: # Pick root (deterministically) root = min(group, key=lambda app:app.node.hostname) # Obtain all IPs in numeric format # (which means faster distance computations) for dep in group: dep._ip = server.gethostbyname(dep.node.hostname) dep._ip_n = struct.unpack('!L', socket.inet_aton(dep._ip))[0] # Compute plan # NOTE: the plan is an iterator plan = mst.mst( group, lambda a,b : ipaddr2.ipdistn(a._ip_n, b._ip_n), root = root, maxbranching = 2) # Re-sign private key try: tempprk, temppuk, tmppass = self._make_temp_private_key() except TempKeyError: continue # Set up slaves plan = list(plan) for slave, master in plan: slave.set_master(master) slave.install_keys(tempprk, temppuk, tmppass) # We don't need the user's passphrase anymore self.sliceSSHKeyPass = None