Ejemplo n.º 1
0
 def __init__(self, config):
     self.config = config
     self.storage = AtlasBrokerStorage(self.config.mongo["uri"],
                                       self.config.mongo["timeoutms"],
                                       self.config.mongo["db"],
                                       self.config.mongo["collection"])
     self.atlas = Atlas(self.config.atlas["user"],
                        self.config.atlas["password"],
                        self.config.atlas["group"])
     self.service_instance = AtlasServiceInstance(self)
     self.service_binding = AtlasServiceBinding(self)
Ejemplo n.º 2
0
    def __init__(self, atlas_credentials, mongo_credentials, clusters=None):
        self.atlas = atlas_credentials
        self.mongo = mongo_credentials

        # Broker Service configuration
        self.broker = {
            "id":
            self.UUID_SERVICES_CLUSTER,
            "name":
            "atlas-mongodb-cluster",
            "description":
            "Atlas/MongoDB for applications",
            "bindable":
            True,
            "plans": [
                ServicePlan(
                    id=self.UUID_PLANS_EXISTING_CLUSTER,
                    name="atlas-mongodb-existing-cluster",
                    description="Atlas/MongoDB: Configure an existing cluster",
                    metadata=None,
                    free=False,
                    bindable=True),
            ],
            "tags": ['atlas', 'mongodb'],
            "requires":
            None,
            "metadata":
            ServiceMetadata(
                displayName='Atlas - MongoDB Cloud Provider',
                imageUrl=None,
                longDescription=None,
                providerDisplayName=None,
                documentationUrl=None,
                supportUrl=None,
            ),
            "dashboard_client":
            None,
            "plan_updateable":
            False,
        }

        # Clusters configuration
        if clusters:
            self.clusters = clusters
        else:
            # load from Atlas
            atlas = Atlas(self.atlas["user"], self.atlas["password"],
                          self.atlas["group"])
            self.clusters = {}
            for cluster in atlas.Clusters.get_all_clusters(iterable=True):
                uri = cluster["mongoURIWithOptions"].replace(
                    'mongodb://', 'mongodb://%s:%s@').replace('/?', '/%s?')
                self.clusters[cluster["name"]] = uri
Ejemplo n.º 3
0
    def setUp(self):
        self.USER = getenv('ATLAS_USER', None)
        self.API_KEY = getenv('ATLAS_KEY', None)
        self.GROUP_ID = getenv('ATLAS_GROUP', None)

        self.TEST_CLUSTER_NAME = TEST_CLUSTER_NAME
        self.TEST_CLUSTER2_NAME = TEST_CLUSTER2_NAME

        self.TEST_CLUSTER_NAME_UNIQUE = TEST_CLUSTER2_NAME_UNIQUE
        self.TEST_CLUSTER2_NAME_UNIQUE = TEST_CLUSTER2_NAME_UNIQUE
        self.TEST_CLUSTER3_NAME_UNIQUE = TEST_CLUSTER3_NAME_UNIQUE

        if not self.USER or not self.API_KEY or not self.GROUP_ID:
            raise EnvironmentError('In order to run this smoke test you need ATLAS_USER, AND ATLAS_KEY env variables'
                                   'your env variables are {}'.format(environ.__str__()))
        self.a = Atlas(self.USER, self.API_KEY, self.GROUP_ID)
Ejemplo n.º 4
0
TODO: Create real tests


"""

from atlasapi.atlas import Atlas
from pprint import pprint
from os import environ, getenv

from atlasapi.specs import ListOfHosts, Host
USER = getenv('ATLAS_USER', 'JKKIDWUA')
API_KEY = getenv('ATLAS_KEY', '4e09ab9f-bf2c-41da-90bf-7d7974c330d2')
GROUP_ID = getenv('ATLAS_GROUP', '5b1e92c13b34b93b0230e6e1')
from atlasapi.lib import AtlasPeriods, AtlasUnits, AtlasGranularities
from atlasapi.measurements import AtlasMeasurementTypes

if not USER or not API_KEY or not GROUP_ID:
    raise EnvironmentError('In order to run this smoke test you need ATLAS_USER, AND ATLAS_KEY env variables'
                           'your env variables are {}'.format(environ.__str__()))

a = Atlas(USER,API_KEY,GROUP_ID)


pprint('----------MeasureMents')
output = a.Hosts._get_measurement_for_host(a.Hosts.host_list[0]
                                           ,measurement=AtlasMeasurementTypes.Memory.resident,iterable=True
                                           ,period=AtlasPeriods.WEEKS_4,granularity=AtlasGranularities.MINUTE)

for each in a.Hosts.host_list:
    pprint(each.__dict__)
Ejemplo n.º 5
0
## Manual Test for issue 29

from atlasapi.atlas import Atlas
from atlasapi.clusters import AdvancedOptions, InstanceSizeName

a = Atlas(user="", password="", group="")

out = a.Clusters.modify_cluster_instance_size(
    cluster='oplogTest', new_cluster_size=InstanceSizeName.M10)

print(out)
Ejemplo n.º 6
0
def main(args):
    """

    :param args: Expect sys.argv
    :return: None
    """
    parser = argparse.ArgumentParser(prog="atlascli",
                                     description="A command line interface to the MongoDB Atlas"
                                                 "database as a service."
                                                 "https://www.mongodb.com/cloud/atlas for more info"
                                                 "See also https://docs.atlas.mongodb.com/configure-api-access"
                                                 "/#programmatic-api-keys "
                                                 "For how to obtain a programmatic API key required to access the API"
                                     )

    parser.add_argument("--publickey", help="MongoDB Atlas public API key")
    parser.add_argument("--privatekey", help="MongoDB Atlas private API key")
    parser.add_argument("--atlasgroup", help="Default group (aka project)")

    parser.add_argument("--format", type=ListFormat,
                        choices=list(ListFormat),
                        default=ListFormat.short,
                        help="Format for output of list command [default: %(default)s]")

    parser.add_argument("--resource",
                        type=AtlasResource, default=AtlasResource.CLUSTER,
                        choices=list(AtlasResource),
                        help="Which resource type are we operating on:"
                             "organization, project or cluster? [default: %(default)s]")

    parser.add_argument('--id', type=str, help='Specify a resource id')

    parser.add_argument("--debug", default=False, action="store_true",
                        help="Turn on logging at debug level [default: %(default)s]")

    parser.add_argument("--list", default=False, action="store_true",
                        help="List a set of resources [default: %(default)s]")

    args = parser.parse_args(args)

    if args.debug:
        logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                            level=logging.DEBUG)
    else:
        logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                            level=logging.INFO)

    logging.debug("logging is on at DEBUG level")

    if args.publickey:
        public_key = args.publickey
    else:
        public_key = os.getenv("ATLAS_PUBLIC_KEY")
        if public_key is None:
            print("you must specify an ATLAS public key via --publickey arg "
                  "or the environment variable ATLAS_PUBLIC_KEY")
            sys.exit(1)

    if args.privatekey:
        private_key = args.privatekey
    else:
        private_key = os.getenv("ATLAS_PRIVATE_KEY")
        if private_key is None:
            print("you must specify an an ATLAS private key via --privatekey"
                  "arg or the environment variable ATLAS_PRIVATE_KEY")
            sys.exit(1)

    atlas = Atlas(public_key, private_key, args.atlasgroup)

    if args.list:
        if args.resource == AtlasResource.CLUSTER:
            list_cmd = ListCommand(args.format)
            if args.id:
                print("Cluster:")
                cluster = atlas.Clusters.get_single_cluster(cluster=args.id)
                list_cmd.list_one(cluster)
            else:
                print("Cluster list:")
                clusters = atlas.Clusters.get_all_clusters(iterable=True)
                total = list_cmd.list_all(clusters)
                print(f"{total} cluster(s)")