Sub-command init. Branches out to sharded, replicaset or single node methods.
(self)
| 629 | |
| 630 | # -- below are the main commands: init, start, stop, list, kill |
| 631 | def init(self): |
| 632 | """ |
| 633 | Sub-command init. |
| 634 | |
| 635 | Branches out to sharded, replicaset or single node methods. |
| 636 | """ |
| 637 | # check for existing environment. Only allow subsequent |
| 638 | # 'mlaunch init' if they are identical. |
| 639 | if self._load_parameters(): |
| 640 | if self.loaded_args != self.args: |
| 641 | raise SystemExit('A different environment already exists ' |
| 642 | 'at %s.' % self.dir) |
| 643 | first_init = False |
| 644 | else: |
| 645 | first_init = True |
| 646 | |
| 647 | self.ssl_pymongo_options = self._get_ssl_pymongo_options(self.args) |
| 648 | self.tls_pymongo_options = self._get_tls_pymongo_options(self.args) |
| 649 | |
| 650 | if (self._get_ssl_server_args() and not |
| 651 | self.args['sslAllowConnectionsWithoutCertificates'] and not |
| 652 | self.args['sslClientCertificate'] and not |
| 653 | self.args['sslClientPEMKeyFile']): |
| 654 | sys.stderr.write('warning: server requires certificates but no' |
| 655 | ' --sslClientCertificate provided\n') |
| 656 | |
| 657 | if (self._get_tls_server_args() and not |
| 658 | self.args['tlsAllowConnectionsWithoutCertificates'] and not |
| 659 | self.args['tlsClientCertificateKeyFile']): |
| 660 | sys.stderr.write('warning: server requires certificates but no' |
| 661 | ' --tlsClientCertificateKeyFile provided\n') |
| 662 | # number of default config servers |
| 663 | if self.args['config'] == -1: |
| 664 | self.args['config'] = 1 |
| 665 | |
| 666 | # add the 'csrs' parameter as default for MongoDB >= 3.3.0 |
| 667 | if (version.parse(self.current_version) >= version.parse("3.3.0") or |
| 668 | version.parse(self.current_version) == version.parse("0.0.0")): |
| 669 | self.args['csrs'] = True |
| 670 | |
| 671 | # construct startup strings |
| 672 | self._construct_cmdlines() |
| 673 | |
| 674 | # write out parameters |
| 675 | if self.args['verbose']: |
| 676 | print("writing .mlaunch_startup file.") |
| 677 | self._store_parameters() |
| 678 | |
| 679 | # exit if running in testing mode |
| 680 | if self.test: |
| 681 | return |
| 682 | |
| 683 | # check if authentication is enabled, make key file |
| 684 | if self.args['auth'] and first_init: |
| 685 | if not os.path.exists(self.dir): |
| 686 | os.makedirs(self.dir) |
| 687 | |
| 688 | if '--keyFile' in self.unknown_args: |
no test coverage detected