예제 #1
0
    def _get_deployment_type(self):
        # getCmdLineOpts is the runtime configuration of the mongo instance. Helpful to know whether the node is
        # a mongos or mongod, if the mongod is in a shard, if it's in a replica set, etc.
        try:
            options = self['admin'].command("getCmdLineOpts")['parsed']
        except Exception as e:
            self._log.debug(
                "Unable to run `getCmdLineOpts`, got: %s. Assuming this is an Alibaba ApsaraDB instance.",
                str(e))
            # `getCmdLineOpts` is forbidden on Alibaba ApsaraDB
            return self._get_alibaba_deployment_type()
        cluster_role = None
        if 'sharding' in options:
            if 'configDB' in options['sharding']:
                return MongosDeployment()
            elif 'clusterRole' in options['sharding']:
                cluster_role = options['sharding']['clusterRole']

        replication_options = options.get('replication', {})
        if 'replSetName' in replication_options or 'replSet' in replication_options:
            repl_set_payload = self['admin'].command("replSetGetStatus")
            return self._get_rs_deployment_from_status_payload(
                repl_set_payload, cluster_role)

        return StandaloneDeployment()
예제 #2
0
 def update_deployment(self, admindb):
     props = admindb.command("isMaster")
     if props.get("ismaster") == "isdbgrid":
         self.deployment = MongosDeployment()
     elif props.get("hosts"):
         repl_set_payload = admindb.command("replSetGetStatus")
         replset_name = repl_set_payload["set"]
         replset_state = repl_set_payload["myState"]
         self.deployment = ReplicaSetDeployment(replset_name, replset_state)
     else:
         self.deployment = StandaloneDeployment()
예제 #3
0
    def _get_alibaba_deployment_type(self):
        is_master_payload = self['admin'].command('isMaster')
        if is_master_payload.get('msg') == 'isdbgrid':
            return MongosDeployment()

        # On alibaba cloud, a mongo node is either a mongos or part of a replica set.
        repl_set_payload = self['admin'].command("replSetGetStatus")
        if repl_set_payload.get('configsvr') is True:
            cluster_role = 'configsvr'
        elif self['admin'].command('shardingState').get('enabled') is True:
            # Use `shardingState` command to know whether or not the replicaset
            # is a shard or not.
            cluster_role = 'shardsvr'
        else:
            cluster_role = None

        return self._get_rs_deployment_from_status_payload(
            repl_set_payload, cluster_role)
예제 #4
0
    def get_deployment(admindb):
        # getCmdLineOpts is the runtime configuration of the mongo instance. Helpful to know whether the node is
        # a mongos or mongod, if the mongod is in a shard, if it's in a replica set, etc.
        options = admindb.command("getCmdLineOpts")['parsed']
        cluster_role = None
        if 'sharding' in options:
            if 'configDB' in options['sharding']:
                return MongosDeployment()
            elif 'clusterRole' in options['sharding']:
                cluster_role = options['sharding']['clusterRole']

        if 'replSetName' in options.get('replication', {}):
            repl_set_payload = admindb.command("replSetGetStatus")
            replset_name = repl_set_payload["set"]
            replset_state = repl_set_payload["myState"]
            return ReplicaSetDeployment(replset_name, replset_state, cluster_role=cluster_role)

        return StandaloneDeployment()