Seeds the initial node master from an existing znode config.
333620
def find_existing_master
      if data = @zk.get(redis_nodes_path).first
        nodes = symbolize_keys(decode(data))
        master = node_from(nodes[:master])
        logger.info("Master from existing znode config: #{master || 'none'}")
        # Check for case where a node previously thought to be the master was
        # somehow manually reconfigured to be a slave outside of the node manager's
        # control.
        begin
          if master && master.slave?
            raise InvalidNodeRoleError.new(master, :master, :slave)
          end
        rescue RedisFailover::NodeUnavailableError => ex
          logger.warn("Failed to check whether existing master has invalid role: #{ex.inspect}")
        end

        master
      end
    rescue ZK::Exceptions::NoNode
      # blank slate, no last known master
      nil
    end
532058
def ex_create_multiple_nodes(
            self, base_name, size, image, number, location=None,
            ex_network='default', ex_subnetwork=None, ex_tags=None,
            ex_metadata=None, ignore_errors=True, use_existing_disk=True,
            poll_interval=2, external_ip='ephemeral',
            ex_disk_type='pd-standard', ex_disk_auto_delete=True,
            ex_service_accounts=None, timeout=DEFAULT_TASK_COMPLETION_TIMEOUT,
            description=None, ex_can_ip_forward=None, ex_disks_gce_struct=None,
            ex_nic_gce_struct=None, ex_on_host_maintenance=None,
            ex_automatic_restart=None, ex_image_family=None,
            ex_preemptible=None):
        
        # if image and ex_disks_gce_struct:
        #    raise ValueError("Cannot specify both 'image' and "
        #                     "'ex_disks_gce_struct'.")

        driver = self._getDriver()
        if image and ex_image_family:
            raise ValueError("Cannot specify both 'image' and "
                             "'ex_image_family'")

        location = location or driver.zone
        if not hasattr(location, 'name'):
            location = driver.ex_get_zone(location)
        if not hasattr(size, 'name'):
            size = driver.ex_get_size(size, location)
        if not hasattr(ex_network, 'name'):
            ex_network = driver.ex_get_network(ex_network)
        if ex_subnetwork and not hasattr(ex_subnetwork, 'name'):
            ex_subnetwork = \
                driver.ex_get_subnetwork(ex_subnetwork,
                                       region=driver._get_region_from_zone(
                                           location))
        if ex_image_family:
            image = driver.ex_get_image_from_family(ex_image_family)
        if image and not hasattr(image, 'name'):
            image = driver.ex_get_image(image)
        if not hasattr(ex_disk_type, 'name'):
            ex_disk_type = driver.ex_get_disktype(ex_disk_type, zone=location)

        node_attrs = {'size': size,
                      'image': image,
                      'location': location,
                      'network': ex_network,
                      'subnetwork': ex_subnetwork,
                      'tags': ex_tags,
                      'metadata': ex_metadata,
                      'ignore_errors': ignore_errors,
                      'use_existing_disk': use_existing_disk,
                      'external_ip': external_ip,
                      'ex_disk_type': ex_disk_type,
                      'ex_disk_auto_delete': ex_disk_auto_delete,
                      'ex_service_accounts': ex_service_accounts,
                      'description': description,
                      'ex_can_ip_forward': ex_can_ip_forward,
                      'ex_disks_gce_struct': ex_disks_gce_struct,
                      'ex_nic_gce_struct': ex_nic_gce_struct,
                      'ex_on_host_maintenance': ex_on_host_maintenance,
                      'ex_automatic_restart': ex_automatic_restart,
                      'ex_preemptible': ex_preemptible}
        # List for holding the status information for disk/node creation.
        status_list = []

        for i in range(number):
            name = 'wp' if ex_preemptible else 'wn'
            name += str(uuid.uuid4()) #'%s-%03d' % (base_name, i)
            status = {'name': name, 'node_response': None, 'node': None}
            status_list.append(status)

        start_time = time.time()
        complete = False
        while not complete:
            if (time.time() - start_time >= timeout):
                raise Exception("Timeout (%s sec) while waiting for multiple "
                                "instances")
            complete = True
            time.sleep(poll_interval)
            for status in status_list:
                # Create the node or check status if already in progress.
                if not status['node']:
                    if not status['node_response']:
                        driver._multi_create_node(status, node_attrs)
                    else:
                        driver._multi_check_node(status, node_attrs)
                # If any of the nodes have not been created (or failed) we are
                # not done yet.
                if not status['node']:
                    complete = False

        # Return list of nodes
        node_list = []
        for status in status_list:
            node_list.append(status['node'])
        return node_list
883666
static Configuration setupAvatarNodeStorage(Configuration conf,
      StartupInfo startInfo, NamenodeProtocol primaryNamenode)
      throws IOException {
    
    // shared loations for image and edits
    URI img0 = NNStorageConfiguration.getURIKey(conf, "dfs.name.dir.shared0");
    URI img1 = NNStorageConfiguration.getURIKey(conf, "dfs.name.dir.shared1");
    URI edit0 = NNStorageConfiguration.getURIKey(conf, "dfs.name.edits.dir.shared0");
    URI edit1 = NNStorageConfiguration.getURIKey(conf, "dfs.name.edits.dir.shared1");
    
    // local locations for image and edits
    Collection<URI> namedirs = NNStorageConfiguration.getNamespaceDirs(conf, null);
    Collection<URI> editsdir = NNStorageConfiguration.getNamespaceEditsDirs(conf, null);

    // validate correctness of the configuration
    AvatarStorageSetup.validate(conf, 
        namedirs, editsdir, 
        img0, img1, edit0, edit1);
    
    FileSystem localFs = FileSystem.getLocal(conf).getRaw();
    
    URI ownSharedImage = null;
    URI ownSharedEdits = null;

    //
    // if we are instance one then copy from primary to secondary
    // otherwise copy from secondary to primary.
    //
    if (startInfo.instance == InstanceId.NODEONE) {
      ownSharedImage = img1;
      ownSharedEdits = edit1;
    } else if (startInfo.instance == InstanceId.NODEZERO) {
      ownSharedImage = img0;
      ownSharedEdits = edit0;
    }

    // allocate a new configuration and update fs.name.dir approprately
    // The shared device should be the first in the list.
    Configuration newconf = new Configuration(conf);
    AvatarStorageSetup.updateConf(startInfo, newconf, namedirs, img0, img1,
        "dfs.name.dir");

    // update fs.name.edits.dir approprately in the new configuration
    // The shared device should be the first in the list.
    AvatarStorageSetup.updateConf(startInfo, newconf, editsdir, edit0,
        edit1, "dfs.name.edits.dir");
    
    // copy fsimage directory if needed
    if (startInfo.isStandby) {
      
      // do not open edit log at startup
      newconf.setBoolean("dfs.namenode.openlog", false);
      
      // connect to primary
      String fsName = getRemoteNamenodeHttpName(conf, startInfo.instance);
      
      FSImage tempImage = new FSImage(newconf,
          NNStorageConfiguration.getNamespaceDirs(newconf),
          NNStorageConfiguration.getNamespaceEditsDirs(newconf), null);
      
      // will block until Primary has left the safemode
      CheckpointSignature cs = getCheckpointSignature(primaryNamenode);
      
      long lastCheckpointTxId = cs.mostRecentCheckpointTxId;
      
      if(cs.layoutVersion != FSConstants.LAYOUT_VERSION) {
        throw new IOException("Upgrade for standby is not supported");      
      }
     
      if (isFile(ownSharedImage)) {
        File destFile = new File (ownSharedImage.getPath());
        NNStorageDirectoryRetentionManager.backupFiles(localFs, destFile, conf);
      }
      if (isFile(ownSharedEdits)) {
        File destFile = new File (ownSharedEdits.getPath());
        NNStorageDirectoryRetentionManager.backupFiles(localFs, destFile, newconf);
      }

      // setup storage
      NNStorage tempStorage = tempImage.storage;
      tempStorage.format();
      tempStorage.setStorageInfo(cs);
      tempStorage.writeAll();
      tempImage.editLog.transitionNonFileJournals(tempStorage, false,
          Transition.FORMAT, null);
      tempImage.transitionNonFileImages(tempStorage, false, Transition.FORMAT);
      
      // we need to become the active writer to upload image successfully to
      // non-file images storage
      tempImage.editLog.recoverUnclosedStreams();

      // Download the image to all storage directories
      FLOG.info("Downloading image to all storage directories.");
      MD5Hash digest = downloadImageToStorage(fsName, lastCheckpointTxId, tempImage);
      List<StorageDirectory> badSds = new ArrayList<StorageDirectory>();
      tempStorage.checkpointUploadDone(lastCheckpointTxId, digest);
      FLOG.info("Downloading image to all storage directories. DONE");
      tempImage.saveDigestAndRenameCheckpointImage(lastCheckpointTxId, digest);
      tempStorage.reportErrorsOnDirectories(badSds, tempImage);
      tempStorage.close();
      tempImage.close();
    }
    return newconf;
  }
1318008
def _init_gonodeopts(self, **kws_usr):
        """"""
        options = GoNodeOpts(self.gosubdag, **self.kws['node_go'])
        # Add parent edge count if either is in kws: parentcnt, prt_pcnt
        if not options.kws['set'].isdisjoint(['parentcnt', 'prt_pcnt']):
            options.kws['dict']['c2ps'] = self.edgesobj.get_c2ps()
        # GoeaResults(kws['goea_results'], **self.kws['goea']) if 'goea_results' in kws else None
        if 'goea_results' in kws_usr:
            objgoea = GoeaResults(kws_usr['goea_results'], **self.kws['goea'])
            options.kws['dict']['objgoea'] = objgoea
        return options
305678
def seed(vault_client, opt):
    """"""
    if opt.thaw_from:
        opt.secrets = tempfile.mkdtemp('aomi-thaw')
        auto_thaw(vault_client, opt)

    Context.load(get_secretfile(opt), opt) \
           .fetch(vault_client) \
           .sync(vault_client, opt)

    if opt.thaw_from:
        rmtree(opt.secrets)
149968
def visit_exec(self, node, parent):
        """"""
        newnode = nodes.Exec(node.lineno, node.col_offset, parent)
        newnode.postinit(
            self.visit(node.body, newnode),
            _visit_or_none(node, "globals", self, newnode),
            _visit_or_none(node, "locals", self, newnode),
        )
        return newnode
97006
def _create_PmtInf_node(self):
        
        ED = dict()  # ED is element dict
        ED['PmtInfNode'] = ET.Element("PmtInf")
        ED['PmtInfIdNode'] = ET.Element("PmtInfId")
        ED['PmtMtdNode'] = ET.Element("PmtMtd")
        ED['BtchBookgNode'] = ET.Element("BtchBookg")
        ED['NbOfTxsNode'] = ET.Element("NbOfTxs")
        ED['CtrlSumNode'] = ET.Element("CtrlSum")
        ED['PmtTpInfNode'] = ET.Element("PmtTpInf")
        ED['SvcLvlNode'] = ET.Element("SvcLvl")
        ED['Cd_SvcLvl_Node'] = ET.Element("Cd")
        ED['LclInstrmNode'] = ET.Element("LclInstrm")
        ED['Cd_LclInstrm_Node'] = ET.Element("Cd")
        ED['SeqTpNode'] = ET.Element("SeqTp")
        ED['ReqdColltnDtNode'] = ET.Element("ReqdColltnDt")
        ED['CdtrNode'] = ET.Element("Cdtr")
        ED['Nm_Cdtr_Node'] = ET.Element("Nm")
        ED['CdtrAcctNode'] = ET.Element("CdtrAcct")
        ED['Id_CdtrAcct_Node'] = ET.Element("Id")
        ED['IBAN_CdtrAcct_Node'] = ET.Element("IBAN")
        ED['CdtrAgtNode'] = ET.Element("CdtrAgt")
        ED['FinInstnId_CdtrAgt_Node'] = ET.Element("FinInstnId")
        if 'BIC' in self._config:
            ED['BIC_CdtrAgt_Node'] = ET.Element("BIC")
        ED['ChrgBrNode'] = ET.Element("ChrgBr")
        ED['CdtrSchmeIdNode'] = ET.Element("CdtrSchmeId")
        ED['Nm_CdtrSchmeId_Node'] = ET.Element("Nm")
        ED['Id_CdtrSchmeId_Node'] = ET.Element("Id")
        ED['PrvtIdNode'] = ET.Element("PrvtId")
        ED['OthrNode'] = ET.Element("Othr")
        ED['Id_Othr_Node'] = ET.Element("Id")
        ED['SchmeNmNode'] = ET.Element("SchmeNm")
        ED['PrtryNode'] = ET.Element("Prtry")
        return ED
990581
def dfs(initial)
      nodes, seen = Set.new, Set.new
      stack = Array(initial).reverse

      while node = stack.pop
        if seen.include?(node)
          nodes.add(node)
        else
          seen.add(node)
          stack.push(node)
          stack.concat(Array(yield node).reverse)
        end
      end

      nodes
    end
331599
def add_node(self, node):
        """"""
        nodes = [n for n in self.nodes() if not isinstance(n, Source)]
        num_agents = len(nodes)
        curr_generation = int((num_agents - 1) / float(self.generation_size))
        node.generation = curr_generation

        if curr_generation == 0:
            if self.initial_source:
                source = min(
                    self.nodes(type=Source),
                    key=attrgetter('creation_time'))
                source.connect(whom=node)
                source.transmit(to_whom=node)
        else:
            prev_agents = Node.query\
                .filter_by(failed=False,
                           network_id=self.id,
                           generation=(curr_generation - 1))\
                .all()
            prev_fits = [p.fitness for p in prev_agents]
            prev_probs = [(f / (1.0 * sum(prev_fits))) for f in prev_fits]

            rnd = random.random()
            temp = 0.0
            for i, probability in enumerate(prev_probs):
                temp += probability
                if temp > rnd:
                    parent = prev_agents[i]
                    break

            parent.connect(whom=node)
            parent.transmit(to_whom=node)
308240
public static HighTideNode createHighTideNode(String argv[],
                                        Configuration conf) throws IOException {
    if (conf == null) {
      conf = new Configuration();
    }
    StartupOption startOpt = parseArguments(argv);
    if (startOpt == null) {
      printUsage();
      return null;
    }
    setStartupOption(conf, startOpt);
    HighTideNode node = new HighTideNode(conf);
    return node;
  }
460471
public void init() throws IOException {
    try {
      if (zooKeeper.exists(zooKeeperParentPath, false) == null) {
        zooKeeper.create(zooKeeperParentPath, new byte[] { '0' },
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        LOG.info("Created ZNode " + zooKeeperParentPath);
      }
      if (zooKeeper.exists(ledgerParentPath, false) == null) {
        zooKeeper.create(ledgerParentPath, new byte[] { '0' },
            ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        LOG.info("Created ZNode" + ledgerParentPath);
      }
    } catch (InterruptedException e) {
      interruptedException("Interrupted ensuring that ZNodes " +
          zooKeeperParentPath + " and " + ledgerParentPath + " exist!", e);
    } catch (KeeperException e) {
      keeperException(
          "Unrecoverable ZooKeeper error ensuring that ZNodes "
              + zooKeeperParentPath + " and " + ledgerParentPath + " exist!",
          e);
    }
  }
1123604
def setupnode(overwrite=False):
    
    if not port_is_open():
        if not skip_disable_root():
            disable_root()
        port_changed = change_ssh_port()
    #avoid trying to take shortcuts if setupnode did not finish 
    #on previous execution
    if server_state('setupnode-incomplete'):
        env.overwrite=True
    else: set_server_state('setupnode-incomplete')
    upload_ssh_key()
    restrict_ssh()
    add_repositories()
    upgrade_packages()
    setup_ufw()
    uninstall_packages()
    install_packages()

    upload_etc()
    post_install_package()
    setup_ufw_rules()
    set_timezone()
    set_server_state('setupnode-incomplete',delete=True)
    #stop and start webservers - and reload nginx
    for s in webserver_list():
        stop_webserver(s)
        start_webserver(s)
198547
protected function seedRoot(? Foundation\AbstractActor $founder = null): void
   {  
       $graph_id = $this->database()->get("configs:graph_id");

       if(isset($graph_id)) {
         $this->logger()->info(
           "Existing network with id: %s", 
           $graph_id
         );
         $this["graph"] = $this->share(function($c) use($graph_id) {
            return $c["gs"]->node($graph_id);
          });
           $this["founder"] = $this->share(function($c) { 
           $founder = $c["graph"]->getFounder();
           return $founder;
         });
       }
       else {
          $this->logger()->info("Creating a new graph from scratch");
          if(!is_null($founder)) {
            $founder->persist();
          }
          else {
            throw new Exceptions\FounderMustBeSetException();
          }
          $this["founder"] = $this->share(function($c) use ($founder) {
              return $founder;
          });
          $this["graph"] = $this->share(function($c) {
            $graph_class = $c["config"]->default_objects->graph;
            $graph = new $graph_class($c, $c["founder"], $c["space"], $c["founder"]);
            $c["logger"]->info("Changing founder context as graph");
            $c["founder"]->changeContext($graph);
            //$c["founder"]->hydrate($c, $c["graph"]); // // to make sure that is set up, since the services are now available.
            return $graph;
          });
         $this->database()->set("configs:graph_id", $this->graph()->id());
         $this->logger()->info(
           "New graph with id: %s and founder: %s", $this->graph()->id(), $this->founder()->id()
         );
       }

       $this->logger()->info("Root seed complete. Time to integrate space & graph");
       $this["gs"]->warmUpCache();

       try {
        //  $this["space"]->add($this["graph"]);
          
       }
       catch(NodeAlreadyMemberException $e) {
          // do nothing
       }

       
   }
1363739
def duplicate_node(self, source_node_id, destination_node_id):
        

        source_node = self.get_node(source_node_id)
        destination_node = self.get_node(destination_node_id)

        # Not a Dynamips router
        if not hasattr(source_node, "startup_config_path"):
            return (yield from super().duplicate_node(source_node_id, destination_node_id))

        try:
            with open(source_node.startup_config_path) as f:
                startup_config = f.read()
        except OSError:
            startup_config = None
        try:
            with open(source_node.private_config_path) as f:
                private_config = f.read()
        except OSError:
            private_config = None
        yield from self.set_vm_configs(destination_node, {
            "startup_config_content": startup_config,
            "private_config_content": private_config
        })

        # Force refresh of the name in configuration files
        new_name = destination_node.name
        yield from destination_node.set_name(source_node.name)
        yield from destination_node.set_name(new_name)
        return destination_node
694464
@When("^I create the zNode '(.+?)'( with content '(.+?)')? which (IS|IS NOT) ephemeral$")
    public void createZNode(String path, String foo, String content, boolean ephemeral) throws Exception {
        if (content != null) {
            commonspec.getZookeeperSecClient().zCreate(path, content, ephemeral);
        } else {
            commonspec.getZookeeperSecClient().zCreate(path, ephemeral);
        }
    }
487985
def init(self, **settings):
        """"""
        if self.get_status() != 'not-initialized':
            raise ClusterError(
                'cluster in {!r} has already been initialized'.format(
                    self._data_dir))

        process = subprocess.run(
            [self._pg_basebackup, '-h', self._master['host'],
             '-p', self._master['port'], '-D', self._data_dir,
             '-U', self._repl_user],
            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

        output = process.stdout

        if process.returncode != 0:
            raise ClusterError(
                'pg_basebackup init exited with status {:d}:\n{}'.format(
                    process.returncode, output.decode()))

        with open(os.path.join(self._data_dir, 'recovery.conf'), 'w') as f:
            f.write(textwrap.dedent("""\
                standby_mode = 'on'
                primary_conninfo = 'host={host} port={port} user={user}'
            """.format(
                host=self._master['host'],
                port=self._master['port'],
                user=self._repl_user)))

        return output.decode()
1065918
def setupNodding(self):
        
        g = get_root(self).globals

        if not self.nod():
            # re-enable clear mode box if not drift
            if not self.isDrift():
                self.clear.enable()

            # clear existing nod pattern
            self.nodPattern = {}
            self.check()
            return

        # Do nothing if we're not at the GTC
        if g.cpars['telins_name'] != 'GTC':
            messagebox.showerror('Error', 'Cannot dither WHT')
            self.nod.set(False)
            self.nodPattern = {}
            return

        # check for drift mode and bomb out
        if self.isDrift():
            messagebox.showerror('Error', 'Cannot dither telescope in drift mode')
            self.nod.set(False)
            self.nodPattern = {}
            return

        # check for clear not enabled and warn
        if not self.clear():
            if not messagebox.askokcancel('Warning',
                                          'Dithering telescope will enable clear mode. Continue?'):
                self.nod.set(False)
                self.nodPattern = {}
                return

        # Ask for nod pattern
        try:
            home = expanduser('~')
            fname = filedialog.askopenfilename(
                title='Open offsets text file',
                defaultextension='.txt',
                filetypes=[('text files', '.txt')],
                initialdir=home)

            if not fname:
                g.clog.warn('Aborted load from disk')
                raise ValueError

            ra, dec = np.loadtxt(fname).T
            if len(ra) != len(dec):
                g.clog.warn('Mismatched lengths of RA and Dec offsets')
                raise ValueError

            data = dict(
                ra=ra.tolist(),
                dec=dec.tolist()
            )
        except:
            g.clog.warn('Setting dither pattern failed. Disabling dithering')
            self.nod.set(False)
            self.nodPattern = {}
            return

        # store nodding on ipars object
        self.nodPattern = data
        # enable clear mode
        self.clear.set(True)
        # update
        self.check()