def get_config(self, **kwargs):

        if not kwargs.has_key('host'):  # if kwargs['host'] is None:
            self.host = cm_config_server().get("cloudmesh.server.ldap.hostname")

        if not kwargs.has_key('ldapcert'):  # if kwargs['ldapcert'] is None:
            self.cert = cm_config_server().get("cloudmesh.server.ldap.cert")
예제 #2
0
    def get_config(self, **kwargs):

        if "host" not in kwargs:
            self.host = cm_config_server().get("cloudmesh.server.ldap.hostname")

        if "ldapcert" not in kwargs:
            self.cert = cm_config_server().get("cloudmesh.server.ldap.cert")
예제 #3
0
    def connect(self, name, type, **kwargs):
        '''
        Register a provider with som parameters specified in the dict params
        
        :param name: the name of the provider
        :param type: the type of the provider, overwrites a possibly given type in params
        :param params: a dictionary describing wht needs to be poassed to the service that provides user information
        '''
        # kwargs host=None, ldapcert=None)
        provider = {'type': type, 'name': name}
        for k, v in kwargs.iteritems():
            provider[k] = v

        if not kwargs.has_key('host'):  # if kwargs['host'] is None:
            self.host = cm_config_server().get(
                "cloudmesh.server.ldap.hostname")

        if not kwargs.has_key('ldapcert'):  # if kwargs['ldapcert'] is None:
            self.cert = cm_config_server().get("cloudmesh.server.ldap.cert")

        ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, self.cert)
        # BUG IN FINAL VERSION MAKE SURE WE CHECK
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

        self.ldapconn = ldap.initialize("ldap://" + self.host)
        self.ldapconn.start_tls_s()
        self.ldapconn.bind_s('', '')
        self.users = {}
예제 #4
0
    def connect(self, name, type, **kwargs):
        """
        Register a provider with som parameters specified in the dict params

        :param name: the name of the provider
        :param type: the type of the provider, overwrites a possibly given type in params
        :param params: a dictionary describing wht needs to be poassed to the service that provides user information
        """
        # kwargs host=None, ldapcert=None)
        provider = {"type": type, "name": name}
        for k, v in kwargs.iteritems():
            provider[k] = v

        if "host" not in kwargs:
            self.host = cm_config_server().get("cloudmesh.server.ldap.hostname")

        if "ldapcert" not in kwargs:
            self.cert = cm_config_server().get("cloudmesh.server.ldap.cert")

        ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, self.cert)
        # BUG IN FINAL VERSION MAKE SURE WE CHECK
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

        self.ldapconn = ldap.initialize("ldap://" + self.host)
        self.ldapconn.start_tls_s()
        self.ldapconn.bind_s("", "")
        self.users = {}
예제 #5
0
 def __init__(self, from_yaml=False):
     self.from_yaml = from_yaml
     self.config_server = cm_config_server()
     self.password_key = self.config_server.get(
         "cloudmesh.server.mongo.collections.password.key")
     self.with_ldap = cm_config_server().get(
         "cloudmesh.server.ldap.with_ldap")
     self.connect_db()
예제 #6
0
 def __init__(self, from_yaml=False):
     self.from_yaml = from_yaml
     self.config_server = cm_config_server()
     self.password_key = self.config_server.get(
         "cloudmesh.server.mongo.collections.password.key")
     self.with_ldap = cm_config_server().get(
         "cloudmesh.server.ldap.with_ldap")
     self.connect_db()
예제 #7
0
    def get_config(self, **kwargs):

        if 'host' not in kwargs:  
            self.host = cm_config_server().get(
                "cloudmesh.server.ldap.hostname")

        if 'ldapcert' not in kwargs:  
            self.cert = cm_config_server().get("cloudmesh.server.ldap.cert")
예제 #8
0
    def get_config(self, **kwargs):

        if not kwargs.has_key('host'):  # if kwargs['host'] is None:
            self.host = cm_config_server().get(
                "cloudmesh.server.ldap.hostname")

        if not kwargs.has_key('ldapcert'):  # if kwargs['ldapcert'] is None:
            self.cert = cm_config_server().get("cloudmesh.server.ldap.cert")
예제 #9
0
def flask():
    config = get_user_config()
    user = config.get("cloudmesh.hpc.username")
    server_config = cm_config_server()
    port = cm_config_server().get("cloudmesh.server.webui.port")
    host = cm_config_server().get("cloudmesh.server.webui.host")

    open(user, host, port)
예제 #10
0
def flask():
    config = get_user_config()
    user = config.get("cloudmesh.hpc.username")
    server_config = cm_config_server()
    port = cm_config_server().get("cloudmesh.server.webui.port")
    host = cm_config_server().get("cloudmesh.server.webui.host")

    open(user, host, port)
예제 #11
0
파일: queue.py 프로젝트: nbohn/cloudmesh
def gui():
    """start the flower celery gui"""
    local("celery flower &")
    time.sleep(1)
    server_config = cm_config_server()
    port = cm_config_server().get("cloudmesh.server.webui.port")
    host = cm_config_server().get("cloudmesh.server.webui.host")

    local("open http://{0}:{1}".format(host, port))
예제 #12
0
def gui():
    """start the flower celery gui"""
    local("celery flower &")
    time.sleep(1)
    server_config = cm_config_server()
    port = cm_config_server().get("cloudmesh.server.webui.port")
    host = cm_config_server().get("cloudmesh.server.webui.host")

    local("open http://{0}:{1}".format(host, port))
예제 #13
0
 def _load_admin_credential(self):
     if self.admin_credential is None:
         if 'keystone' in cm_config_server().get('cloudmesh.server'):
             self.idp_clouds = cm_config_server().get("cloudmesh.server.keystone").keys()
             self.with_admin_credential = self.label in self.idp_clouds
             if self.with_admin_credential:
                 try:
                     self.admin_credential = cm_config_server().get("cloudmesh.server.keystone.{0}".format(self.label))
                 except:
                     log.error(str(lineno()) + " No admin credential found! Please check your cloudmesh_server.yaml file.")
             else:
                 self.admin_credential = None
                 log.info(str(lineno()) + ": The cloud {0} has no admin credential".format(self.label))
     return self.admin_credential
예제 #14
0
class ProvisionWorkflowForm(Form):
    # print
    # "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",Form
    filename = "abc"

    dir = path_expand(
        cm_config_server().get("cloudmesh.server.workflows.path"))

    # not so nice cludge, ask for location of statcic instead

    web_pwd = Shell.pwd().strip()
    basename = "/static/{0}/{1}".format(dir, filename)

    print "BBBB", basename
    try:
        with open("{2}/{0}.{1}".format(basename, "diag", web_pwd), "r") as f:
            data = f.readlines()[1:-1]
            default = "".join(data)
    except:
        print "Error: diagram not found"
        default = ""
    default = default.split("//graph")
    filename = TextField("Filename", default=filename)
    # properties = TextAreaField("Workflow", default=default[0])
    # workflow = TextAreaField("Workflow", default=default[1])
    properties = TextAreaField("Workflow", default="fake")
    workflow = TextAreaField("Workflow", default="fake")
예제 #15
0
    def do_debug(self, args, arguments):
        """
        ::
        
        Usage:
              debug on
              debug off

              Turns the debug log level on and off.
        """

        self.cm_config_server = cm_config_server()

        if arguments['on']:
            key = "cloudmesh.server.loglevel"
            value = "DEBUG"
            self.cm_config_server._update(key, value)

            key = "cloudmesh.server.debug"
            value = True
            self.cm_config_server._update(key, value)

            self.cm_config_server.write(output="yaml")
            print ("Debug mode is on.")
        elif arguments['off']:
            key = "cloudmesh.server.loglevel"
            value = "ERROR"
            self.cm_config_server._update(key, value)

            key = "cloudmesh.server.debug"
            value = False
            self.cm_config_server._update(key, value)

            self.cm_config_server.write(output="yaml")
            print ("Debug mode is off.")
예제 #16
0
    def get_credential(self, cm_user_id, cloud):
        # DEBUG
        try:
            _args = locals()
            if 'self' in _args:
                del (_args['self'])
            log.debug("[{0}()] called with [{1}]".format(sys._getframe().f_code.co_name,
                                                         str(_args)))
        except:
            pass

        try:
            password = cm_config_server().get(
                "cloudmesh.server.mongo.collections.password.key")
            safe_credential = (self.userdb_passwd.find_one(
                {"cm_user_id": cm_user_id, "cloud": cloud}))["credential"]

            # print "SK", safe_credential

            for cred in safe_credential:
                t = safe_credential[cred]
                n = decrypt(t, password)
                safe_credential[cred] = n

            return safe_credential
        except:
            print(traceback.format_exc())
            return None
예제 #17
0
def display_provision_form():

    clusters = cm_config_server().get("cloudmesh.server.provisioner.clusters")

    # clusters = ['india','bravo','sierra']

    # servers = n_inventory.hostlist(cluster)
    # server = n_inventory.host(name,auth=False)

    form = ProvisionForm(csrf=False)

    if form.validate_on_submit():
        flash("Success")
        print "FORM"
        pprint(form.__dict__)
        print "CLUSTER", form.cluster.data
        print "Service", form.service.data
        hosts = expand_hostlist(form.nodespec.data)
        print "Nodespec", hosts

        for host in hosts:
            print "PROVISION HOST", host
            provision.delay(host, form.service.data)

        return redirect("provision/tasks/{0}/{1}/{2}".format(
            form.cluster.data, form.nodespec.data, form.service.data))
        # return redirect("/provision/summary/")

    else:
        flash("Wrong submission")
    inventory.refresh()
    return render_template("mesh/provision/provision.html",
                           clusters=clusters,
                           form=form)
예제 #18
0
    def get_credential(self, cm_user_id, cloud):
        # DEBUG
        try:
            _args = locals()
            if 'self' in _args:
                del (_args['self'])
            log.debug("[{0}()] called with [{1}]".format(
                sys._getframe().f_code.co_name, str(_args)))
        except:
            pass

        try:
            password = cm_config_server().get(
                "cloudmesh.server.mongo.collections.password.key")
            safe_credential = (self.userdb_passwd.find_one({
                "cm_user_id": cm_user_id,
                "cloud": cloud
            }))["credential"]

            # print "SK", safe_credential

            for cred in safe_credential:
                t = safe_credential[cred]
                n = decrypt(t, password)
                safe_credential[cred] = n

            return safe_credential
        except:
            print(traceback.format_exc())
            return None
예제 #19
0
def display_provision_form():

    clusters = cm_config_server().get("cloudmesh.server.provisioner.clusters")

    # clusters = ['india','bravo','sierra']

    # servers = n_inventory.hostlist(cluster)
    # server = n_inventory.host(name,auth=False)


    form = ProvisionForm(csrf=False)

    if form.validate_on_submit():
        flash("Success")
        print "FORM"
        pprint(form.__dict__)
        print "CLUSTER", form.cluster.data
        print "Service", form.service.data
        hosts = expand_hostlist(form.nodespec.data)
        print "Nodespec", hosts

        for host in hosts:
            print "PROVISION HOST", host
            provision.delay(host, form.service.data)

        return redirect("provision/tasks/{0}/{1}/{2}"
                        .format(form.cluster.data,
                                form.nodespec.data,
                                form.service.data))
        # return redirect("/provision/summary/")

    else:
        flash("Wrong submission")
    inventory.refresh()
    return render_template("mesh/provision/provision.html", clusters=clusters, form=form)
예제 #20
0
def boot(auth=True):
    # wipe mongo
    wipe()

    time.sleep(1)
    PROGRESS.next()
    # start mongo without auth
    start(auth=False)

    time.sleep(5)
    PROGRESS.next()
    if isyes(auth):
        # create users
        admin()

        time.sleep(2)
        PROGRESS.next()
        # restart with auth
        kill()

        time.sleep(10)
        PROGRESS.next()
        start(auth=auth)

        time.sleep(1)
        PROGRESS.next()
    config = cm_config_server().get("cloudmesh.server.mongo")
    path = path_expand(config["path"])
    banner(path)
    print Shell.ls(path)
    banner("PROCESS")
    with settings(warn_only=True):
        local("ps -ax | fgrep mongo")
    PROGRESS.next()
예제 #21
0
def start(auth=True):
    '''
    start the mongod service in the location as specified in
    ~/.futuregrid/cloudmesh_server.yaml
    '''
    banner("Starting mongod")
    config = cm_config_server().get("cloudmesh.server.mongo")

    path = path_expand(config["path"])
    port = config["port"]

    if not os.path.exists(path):
        print "Creating mongodb directory in", path
        local("mkdir -p {0}".format(path))

    with settings(warn_only=True):
        with hide('output', 'running', 'warnings'):
            lines = local("ps -ax |grep '[m]ongod.*port {0}'".format(port),
                          capture=True).split("\n")

    if lines != ['']:
        pid = lines[0].split(" ")[0]
        print "NO ACTION: mongo already running in pid {0} for port {1}".format(
            pid, port)
    else:
        print "ACTION: Starting mongod"
        with_auth = ""
        if isyes(auth):
            with_auth = "--auth"

        local(
            "mongod {2} --bind_ip 127.0.0.1 --fork --dbpath {0} --logpath {0}/mongodb.log --port {1}"
            .format(path, port, with_auth))
예제 #22
0
 def get_server_url(self,):
     """
     get the BASE URL of the cobbler service
     """
     server_config = cm_config_server()
     cobbler_config = server_config.get("cloudmesh.server.cobbler")
     return "{0}://{1}:{2}".format(cobbler_config["prot"], cobbler_config["host"], cobbler_config["port"])
예제 #23
0
def start(auth=True):
    '''
    start the mongod service in the location as specified in
    ~/.futuregrid/cloudmesh_server.yaml
    '''
    banner("Starting mongod")
    config = cm_config_server().get("cloudmesh.server.mongo")

    path = path_expand(config["path"])
    port = config["port"]

    if not os.path.exists(path):
        print "Creating mongodb directory in", path
        local("mkdir -p {0}".format(path))

    with settings(warn_only=True):
        with hide('output', 'running', 'warnings'):
            lines = local("ps -ax |grep '[m]ongod.*port {0}'".format(port), capture=True).split("\n")

    if lines != ['']:
        pid = lines[0].split(" ")[0]
        print "NO ACTION: mongo already running in pid {0} for port {1}".format(pid, port)
    else:
        print "ACTION: Starting mongod"
        with_auth = ""
        if isyes(auth):
            with_auth = "--auth"

        local("mongod {2} --bind_ip 127.0.0.1 --fork --dbpath {0} --logpath {0}/mongodb.log --port {1}".format(path, port, with_auth))
예제 #24
0
    def do_debug(self, args, arguments):
        """
        ::
        
        Usage:
              debug on
              debug off

              Turns the debug log level on and off.
        """

        self.cm_config_server = cm_config_server()

        if arguments['on']:
            key = "cloudmesh.server.loglevel"
            value = "DEBUG"
            self.cm_config_server._update(key, value)

            key = "cloudmesh.server.debug"
            value = True
            self.cm_config_server._update(key, value)

            self.cm_config_server.write(output="yaml")
            print("Debug mode is on.")
        elif arguments['off']:
            key = "cloudmesh.server.loglevel"
            value = "ERROR"
            self.cm_config_server._update(key, value)

            key = "cloudmesh.server.debug"
            value = False
            self.cm_config_server._update(key, value)

            self.cm_config_server.write(output="yaml")
            print("Debug mode is off.")
    def __init__(self, collection="profile"):

        self.data = {}
        self.server = cm_config_server()
        self.config = cm_config()

        self.db_clouds = get_mongo_db(collection)
        self._get_usernames_from_config()
예제 #26
0
def get_server_url():
    # ONLY for test
    # MUST changed to read info from yml file before commit
    server_config = cm_config_server()
    prot = server_config.get("cloudmesh.server.cobbler.prot")
    host = server_config.get("cloudmesh.server.cobbler.host")
    port = server_config.get("cloudmesh.server.cobbler.port")
    return "{0}://{1}:{2}".format(prot, host, port)
예제 #27
0
    def __init__(self, collection="profile"):

        self.data = {}
        self.server = cm_config_server()
        self.config = cm_config()

        self.db_clouds = get_mongo_db(collection)
        self._get_usernames_from_config()
예제 #28
0
    def __init__(self):
        # read the host file definition from cloudmesh_cluster.yaml
        self.server_config = cm_config_server()

        self.config = ConfigDict(filename=self.CONFIG_FILE)

        collection = "inventory"
        self.db_inventory = get_mongo_db(collection)
예제 #29
0
파일: cobbler.py 프로젝트: nbohn/cloudmesh
def get_server_url():
    # ONLY for test
    # MUST changed to read info from yml file before commit
    server_config = cm_config_server()
    prot = server_config.get("cloudmesh.server.cobbler.prot")
    host = server_config.get("cloudmesh.server.cobbler.host")
    port = server_config.get("cloudmesh.server.cobbler.port")
    return "{0}://{1}:{2}".format(prot, host, port)
예제 #30
0
    def __init__(self):
        # read the host file definition from cloudmesh_cluster.yaml
        self.server_config = cm_config_server()

        self.config = ConfigDict(filename=self.CONFIG_FILE)

        collection = "inventory"
        self.db_inventory = get_mongo_db(collection)
예제 #31
0
파일: mongo.py 프로젝트: mnozary/cloudmesh
def clean():
    port = cm_config_server().get("cloudmesh.server.mongo.port")
    result = local('echo "show dbs" | mongo --quiet --port {0}'.format(port),
                   capture=True).splitlines()
    for line in result:
        name = line.split()[0]
        local('mongo {0} --port {1} --eval "db.dropDatabase();"'.format(
            name, port))
예제 #32
0
파일: mongo.py 프로젝트: lee212/cloudmesh
def clean():
    port = cm_config_server().get("cloudmesh.server.mongo.port")
    result = local(
        'echo "show dbs" | mongo --quiet --port {0}'.format(port), capture=True).splitlines()
    for line in result:
        name = line.split()[0]
        local('mongo {0} --port {1} --eval "db.dropDatabase();"'
              .format(name, port))
예제 #33
0
 def get_server_url(self, ):
     """
     get the BASE URL of the cobbler service
     """
     server_config = cm_config_server()
     cobbler_config = server_config.get("cloudmesh.server.cobbler")
     return "{0}://{1}:{2}".format(cobbler_config["prot"],
                                   cobbler_config["host"],
                                   cobbler_config["port"])
예제 #34
0
def display_provision_workflow_form():

    form = ProvisionWorkflowForm(csrf=False)

    dir = path_expand(
        cm_config_server().get("cloudmesh.server.workflows.path"))

    filename = "abc"

    web_pwd = pwd().strip()
    print "PWD", web_pwd
    basename = "/static/{0}/{1}".format(
        dir,
        filename,
    )
    # if form.validate_on_submit():

    #    print "SKIP"
    try:
        with open("{2}/{0}.{1}".format(basename, "diag", web_pwd), "w") as f:
            # print "########################################################################################"
            # print "aaaaaa"+form.workflow.data+"bbb"
            f.write("blockdiag {\n")
            if form.workflow.data == "":
                form.work.data = f.work.default
            if form.properties.data == "":
                form.properties.data = form.properties.default
            f.write(form.properties.data)
            f.write("//graph\n")
            f.write(form.workflow.data)
            f.write("\n}")

            # print
            # "########################################################################################"
            print form.workflow
    except:
        print "file does not exists"
    print "{0}.{1}".format(basename, diagram_format)

    print "OOOO", basename
    blockdiag("--ignore-pil", "-Tsvg", "-o",
              "{2}/{0}.{1}".format(basename, diagram_format, web_pwd),
              "{2}/{0}.{1}".format(basename, "diag", web_pwd))
    # blockdiag("-Tpng",
    #          "-o", "." + dir + filename + ".png",
    #          "." + dir + filename + ".diag")

    # else:
    #    flash("Wrong submission")
    inventory.refresh()
    return render_template("provision_workflow.html",
                           workflow=form.workflow.data,
                           form=form,
                           pwd=pwd,
                           diagram="{0}.{1}".format(basename, diagram_format),
                           inventory=inventory)
예제 #35
0
def display_provision_workflow_form():

    form = ProvisionWorkflowForm(csrf=False)

    dir = path_expand(
        cm_config_server().get("cloudmesh.server.workflows.path"))

    filename = "abc"

    web_pwd = Shell.pwd().strip()
    print "PWD", web_pwd
    basename = "/static/{0}/{1}".format(dir, filename,)
    # if form.validate_on_submit():

    #    print "SKIP"
    try:
        with open("{2}/{0}.{1}".format(basename, "diag", web_pwd), "w") as f:
            # print "########################################################################################"
            # print "aaaaaa"+form.workflow.data+"bbb"
            f.write("blockdiag {\n")
            if form.workflow.data == "":
                form.work.data = f.work.default
            if form.properties.data == "":
                form.properties.data = form.properties.default
            f.write(form.properties.data)
            f.write("//graph\n")
            f.write(form.workflow.data)
            f.write("\n}")

            # print
            # "########################################################################################"
            print form.workflow
    except:
        print "file does not exists"
    print "{0}.{1}".format(basename, diagram_format)

    print "OOOO", basename
    Shell.blockdiag("--ignore-pil", "-Tsvg",
              "-o", "{2}/{0}.{1}".format(basename, diagram_format, web_pwd),
              "{2}/{0}.{1}".format(basename, "diag", web_pwd))
    # Shell.blockdiag("-Tpng",
    #          "-o", "." + dir + filename + ".png",
    #          "." + dir + filename + ".diag")

    # else:
    #    flash("Wrong submission")
    inventory.refresh()
    return render_template("provision_workflow.html",
                           workflow=form.workflow.data,
                           form=form,
                           pwd=pwd,
                           diagram="{0}.{1}".format(basename, diagram_format),
                           inventory=inventory)
예제 #36
0
파일: metric.py 프로젝트: lee212/cloudmesh
 def load_server_info(self):
     # cloudmesh_server.yaml contains the api server info
     config_server = cm_config_server()
     try:
         self.api_server = config_server.get("cloudmesh.server.metric.host")
     except:
         self.api_server = "127.0.0.1"
     try:
         self.port = config_server.get("cloudmesh.server.metric.port")
     except:
         self.port = 5001
     self.doc_url = "metric"
예제 #37
0
def admin():
    """creates a password protected user for mongo"""

    banner("create auth user")
    config = cm_config_server().get("cloudmesh.server.mongo")

    user = config["username"]
    password = config["password"]

    #
    # setting up the list of dbs
    #
    dbs = set()
    # print config["collections"]
    for collection in config["collections"]:
        dbs.add(config['collections'][collection]['db'])

    # setting the admin user
    script = []
    # script.append('db.addUser("{0}", "{1}");'.format(user, password))
    # script.append('db.auth("{0}", "{1}");'.format(user, password))

    mongoversion = version()
    # setting a password for each db
    for db in dbs:
        script.append('db = db.getSiblingDB("{0}");'.format(db))
        # mongod has changes since v 2.6
        # it uses createUser instead of addUser to add new user
        # it does not create empty db if no records added
        if mongoversion and mongoversion >= (2, 6, 0):
            script.append('db.createUser({"user":"******", "pwd":"%s", "roles":["dbOwner"]})' % (user, password))
            script.append('use {0};'.format(db))
            # a trick to ensure the db is created
            script.append('db.cmsysmeta.save({"createdOn":"%s"})' % datetime.now())
        else:
            script.append('db.addUser("{0}", "{1}");'.format(user, password))

    script.append('use admin;')
    if mongoversion and mongoversion >= (2, 6, 0):
        script.append('db.createUser({"user":"******", "pwd":"%s", "roles":["root"]})' % (user, password))
    else:
        script.append('db.addUser("{0}", "{1}");'.format(user, password))

    # script.append('db.auth("{0}", "{1}");'.format(user, password))
    # script.append('db.shutdownServer();')

    mongo_script = '\n'.join(script)

    # print mongo_script
    command = "echo '{0}' | mongo".format(mongo_script)
    # print command
    banner("Executing js")
    os.system(command)
예제 #38
0
def mongo_users():
    time_now = datetime.now().strftime("%Y-%m-%d %H:%M")
    # filter()
    config = cm_config_server()
    adminclouds = config.get("cloudmesh.server.keystone").keys()

    username = g.user.id
    userinfo = getCurrentUserinfo()
    activeclouds = []
    if 'activeclouds' in userinfo['defaults']:
        activeclouds = userinfo['defaults']['activeclouds']
    usersinclouds = []
    for cloud in adminclouds:
        if cloud in activeclouds:
            usersinclouds.append(cloud)

    c = cm_mongo()
    c.activate(cm_user_id=username)

    clouds = {}
    clouds = c.users(usersinclouds)
    # print "TYTYTYT", len(clouds), type(clouds), clouds.keys()
    # print len(clouds['sierra_openstack_grizzly'])


    """
    for cloud in clouds:
        print cloud
        for server in clouds[cloud]:
            print server
            for attribute in clouds[cloud][server]:
                print attribute, clouds[cloud][server][attribute]
    """

    attributes = {"grizzly":
                    [
                        [ "Name", "name"],
                        [ "Firstname", "firstname"],
                        [ "Lastname", "lastname"],
                        [ "Id" , "id"],
                        # [ "TenentId" , "tenantId"],
                        [ "E-mail" , "email"],
                        [ "Enabled" , "enabled"],
                        [ "Refresh", "cm_refresh"]
                    ]
                  }

    return render_template('mesh/mesh_users.html',
                           address_string=address_string,
                           cloud_attributes=attributes,
                           updated=time_now,
                           clouds=clouds,
                           config=config)
예제 #39
0
def mongo_users():
    time_now = datetime.now().strftime("%Y-%m-%d %H:%M")
    # filter()
    config = cm_config_server()
    adminclouds = config.get("cloudmesh.server.keystone").keys()

    username = g.user.id
    userinfo = getCurrentUserinfo()
    activeclouds = []
    if 'activeclouds' in userinfo['defaults']:
        activeclouds = userinfo['defaults']['activeclouds']
    usersinclouds = []
    for cloud in adminclouds:
        if cloud in activeclouds:
            usersinclouds.append(cloud)

    c = cm_mongo()
    c.activate(cm_user_id=username)

    clouds = {}
    clouds = c.users(usersinclouds)
    # print "TYTYTYT", len(clouds), type(clouds), clouds.keys()
    # print len(clouds['sierra'])
    """
    for cloud in clouds:
        print cloud
        for server in clouds[cloud]:
            print server
            for attribute in clouds[cloud][server]:
                print attribute, clouds[cloud][server][attribute]
    """

    attributes = {
        "grizzly": [
            ["Name", "name"],
            ["Firstname", "firstname"],
            ["Lastname", "lastname"],
            ["Id", "id"],
            # [ "TenentId" , "tenantId"],
            ["E-mail", "email"],
            ["Enabled", "enabled"],
            ["Refresh", "cm_refresh"]
        ]
    }

    return render_template('mesh/mesh_users.html',
                           address_string=address_string,
                           cloud_attributes=attributes,
                           updated=time_now,
                           clouds=clouds,
                           config=config)
예제 #40
0
    def set_password_local_mongodb(self, passwd=None):
        if passwd is None:
            prompt1st = "Please set a password to mongodb.\nMongo Password:"******"\nPassword not strong enough. Minimum " + \
                    "length is 6. Please enter again.\nMongo Password:"******"cloudmesh.server.mongo.password"
        value = passwd
        cm_config_server._update(key, value)
        cm_config_server.write(format="yaml")
예제 #41
0
    def set_password_local_mongodb(self, passwd=None):
        if passwd is None:
            prompt1st = "Please set a password to mongodb.\nMongo Password:"******"\nPassword not strong enough. Minimum " + \
                    "length is 6. Please enter again.\nMongo Password:"******"cloudmesh.server.mongo.password"
        value = passwd
        cm_config_server._update(key, value)
        cm_config_server.write(format="yaml")
예제 #42
0
    def get_credential(self, cm_user_id, cloud):
        try:
            password = cm_config_server().get("cloudmesh.server.mongo.collections.password.key")
            safe_credential = (self.userdb_passwd.find_one({"cm_user_id": cm_user_id, "cloud":cloud}))["credential"]


            # print "SK", safe_credential

            for cred in safe_credential:
                t = safe_credential[cred]
                n = decrypt(t, password)
                safe_credential[cred] = n

            return safe_credential
        except:
            print traceback.format_exc()
            return None
예제 #43
0
    def _info_mongo(self):
        config = cm_config_server().get("cloudmesh.server.mongo")
        path = path_expand(config["path"])
        port = config["port"]
        # print (config)
        # print(port, path)

        # d = {
        # 'pid': None,
        # 'port': None,
        # 'path': None,
        # 'command': None
        # }

        # try:
        # lines = sh.grep(
        # sh.grep(self._ps(), "mongod"), "log").split("\n")[:-1]
        # if lines != ['']:
        # (pid) = lines[0].lstrip().split(" ")[0]
        # d = {'pid': pid,
        # 'port': port,
        # 'path': path,
        # 'command': lines}
        # except:
        # pass
        # return d

        # need to get rid of fabric local later 
        with settings(warn_only=True):
            with hide('output', 'running', 'warnings'):
                lines = local(
                    "ps -ax |grep '[m]ongod.*port {0}'".format(port), capture=True) \
                    .split("\n")

        if lines != ['']:
            pid = lines[0].split(" ")[0]
            d = {'pid': pid,
                 'port': port,
                 'path': path,
                 'command': lines}
        else:
            d = {'pid': "mongodb not active",
                 'port': None,
                 'path': None,
                 'command': None}
        return d
예제 #44
0
    def __init__(self, label, admin_credential=None):
        """
        initializes the keystone client from a file
        located at ~/.futuregrid.org/cloudmesh_server.yaml.
        """
        self.clear()
        self.label = label
        self.admin_credential = admin_credential

        if admin_credential is None:
            try:
                self.admin_credential = cm_config_server().get("cloudmesh.server.keystone.{0}".format(label))
            except:
                log.error("No admin credential found! Please check your cloudmesh_server.yaml file.")
        # connecting within init will lead to long delays
        if self.admin_credential is not None:
            self.connect()
            self.load()
예제 #45
0
def admin():
    """creates a password protected user for mongo"""

    banner("create auth user")
    config = cm_config_server().get("cloudmesh.server.mongo")

    user = config["username"]
    password = config["password"]

    #
    # setting up the list of dbs
    #
    dbs = set()
    # print config["collections"]
    for collection in config["collections"]:
        dbs.add(config['collections'][collection]['db'])

    # setting the admin user
    script = []
    script.append('db.addUser("{0}", "{1}");'.format(user, password))
    script.append('db.auth("{0}", "{1}");'.format(user, password))

    # setting a password for each db

    for db in dbs:
        script.append('db = db.getSiblingDB("{0}");'.format(db))
        script.append('db.addUser("{0}", "{1}");'.format(user, password))
    script.append("use admin;")
    script.append('db.addUser("{0}", "{1}");'.format(user, password))
    script.append('db.auth("{0}", "{1}");'.format(user, password))
    script.append('db.shutdownServer();')

    mongo_script = '\n'.join(script)

    # print mongo_script

    command = "echo -e '{0}' | mongo".format(mongo_script)
    print command
    banner("Executing js")
    os.system(command)

    banner ("Debugging reminder, remove in final version")
    print "USER", user
    print "PASSWORD", password
예제 #46
0
def admin():
    """creates a password protected user for mongo"""

    banner("create auth user")
    config = cm_config_server().get("cloudmesh.server.mongo")

    user = config["username"]
    password = config["password"]

    #
    # setting up the list of dbs
    #
    dbs = set()
    # print config["collections"]
    for collection in config["collections"]:
        dbs.add(config['collections'][collection]['db'])

    # setting the admin user
    script = []
    script.append('db.addUser("{0}", "{1}");'.format(user, password))
    script.append('db.auth("{0}", "{1}");'.format(user, password))

    # setting a password for each db

    for db in dbs:
        script.append('db = db.getSiblingDB("{0}");'.format(db))
        script.append('db.addUser("{0}", "{1}");'.format(user, password))
    script.append("use admin;")
    script.append('db.addUser("{0}", "{1}");'.format(user, password))
    script.append('db.auth("{0}", "{1}");'.format(user, password))
    script.append('db.shutdownServer();')

    mongo_script = '\n'.join(script)

    # print mongo_script

    command = "echo -e '{0}' | mongo".format(mongo_script)
    print command
    banner("Executing js")
    os.system(command)

    banner("Debugging reminder, remove in final version")
    print "USER", user
    print "PASSWORD", password
예제 #47
0
def start(auth=True):
    """
    start the mongod service in the location as specified in
    cloudmesh_server.yaml
    """
    banner("Starting mongod")
    config = cm_config_server().get("cloudmesh.server.mongo")

    path = path_expand(config["path"])
    port = config["port"]

    if not os.path.exists(path):
        print "Creating mongodb directory in", path
        local("mkdir -p {0}".format(path))

    with settings(warn_only=True):
        with hide('output', 'running', 'warnings'):
            lines = local(
                "ps -ax |grep '[m]ongod.*port {0}'".format(port), capture=True) \
                .split("\n")

    if lines != ['']:
        pid = lines[0].split(" ")[0]
        print "NO ACTION: mongo already running in pid {0} for port {1}" \
            .format(pid, port)
    else:
        print "ACTION: Starting mongod"
        print
        print "NOTE: the preparation of mongo may take a few minutes"
        print "      please do not interrupt this program."
        print
        print "      Please be patient!"
        print

        with_auth = ""
        if isyes(auth):
            with_auth = "--auth"

        local(
            'mongod {2} --bind_ip 127.0.0.1 '
            '--fork --dbpath {0} '
            '--logpath {0}/mongodb.log '
            '--port {1}'.format(path, port, with_auth))
예제 #48
0
파일: mongo.py 프로젝트: lee212/cloudmesh
def wipe():
    """wipes out all traces from mongo"""
    kill()
    config = cm_config_server().get("cloudmesh.server.mongo")

    path = path_expand(config["path"])

    banner("{0}".format(path))
    local("mkdir -p {0}".format(path))
    result = str(Shell.ls(path))
    banner(path, "-")
    print result
    print 70 * "-"
    if result != "":
        if yn_choice("deleting the directory", default="n"):
            local("rm -rf {0}".format(path))
            local("mkdir -p {0}".format(path))
            banner("{0}".format(path))
            local("ls {0}".format(path))
예제 #49
0
파일: mongo.py 프로젝트: mnozary/cloudmesh
def wipe():
    """wipes out all traces from mongo"""
    kill()
    config = cm_config_server().get("cloudmesh.server.mongo")

    path = path_expand(config["path"])

    banner("{0}".format(path))
    local("mkdir -p {0}".format(path))
    result = str(ls(path))
    banner(path, "-")
    print result
    print 70 * "-"
    if result != "":
        if yn_choice("deleting the directory", default="n"):
            local("rm -rf {0}".format(path))
            local("mkdir -p {0}".format(path))
            banner("{0}".format(path))
            local("ls {0}".format(path))
예제 #50
0
class ProvisionForm(Form):

    # clusters = [cluster.name for cluster in inventory.get("cluster")]

    clusters = cm_config_server().get("cloudmesh.server.provisioner.clusters")

    choices = zip(clusters, clusters)
    cluster = SelectField("Cluster", choices=choices)
    nodespec = TextField("Nodes")
    provision_choices = zip(PROVISIONING_CHOICES, PROVISIONING_CHOICES)
    service = SelectField("Service", choices=provision_choices)

    def validate(self):
        cluster = inventory.get("cluster", self.cluster.data)
        posibilities = expand_hostlist(cluster.definition)
        choice = expand_hostlist(self.nodespec.data)
        if choice == []:
            ok = False
        else:
            ok = set(choice).issubset(posibilities)
        print "Validate", ok, choice
        return ok
예제 #51
0
def display_rack_map():

    ####
    #
    #  Flag of debug, True means generate fake data with random generator
    #                 False means fetch the real data from server
    ####
    flag_debug = False

    # class name means the specific class to generate map for different service type
    # method name means the specific method to fetch real data of different service type,
    #     the methods are defined in class FetchClusterInfo
    service_options = {
        "temperature": {
            "class": HeatClusterMap,
            "method": "fetch_temperature_ipmi",
        },
        "service": {
            "class": ServiceClusterMap,
            "method": "fetch_service_type",
        },
    }

    # rack denote the rack user selected
    # service denote the service user selected on the specific rack
    rack = request.form['select_rack']
    service = request.form['select_service']

    # double check to make sure rack can provide the specific service
    rack_form = RackForm()
    if rack not in rack_form.all_services_dict[service]["clusters"]:
        log.error(
            "Someone try to hack the service [service: '{0}' on rack: '{1}'] provided by Rack Diagram. Just ignore it."
            .format(service, rack))
        return redirect("/inventory/rack")

    # get location of configuration file, input diag, output image
    dir_base = config_file("")
    server_config = cm_config_server()
    relative_dir_diag = server_config.get("cloudmesh.server.rack.input")
    relative_dir_image = server_config.get(
        "cloudmesh.server.rack.diagrams.{0}".format(service))
    # log.debug("relative dir image, {0}".format(relative_dir_image))
    flask_dir = "static"
    # guess absolute path of webui
    rack_py_dir = pwd().strip().split("/")
    webui_dir = rack_py_dir  # [:-1]
    # log.debug("webui dir, {0}".format(webui_dir))
    list_image_dir = [flask_dir] + relative_dir_image.strip().split("/")
    abs_dir_image = "/".join(webui_dir + list_image_dir)
    abs_dir_diag = dir_base + "/" + relative_dir_diag
    # dynamic generate image
    map_class = service_options[service]["class"](rack, dir_base, abs_dir_diag,
                                                  abs_dir_image)
    # get cluster server data
    dict_data = None
    if flag_debug:
        dict_data = map_class.genRandomValues()
    else:
        # fetch the real data ....
        # TODO cloudmesh.hpc.proxyserver
        # should we add a field in cloudmesh.yaml for the proxy server to run pbsnodes ???
        config = cm_config()
        user = config.get("cloudmesh.hpc.username")
        myfetch = FetchClusterInfo(user, "india.futuregrid.org")
        flag_filter = None if rack == "all" else rack
        # If user want to customize the action, user can set optional param here
        # by calling map_class.set_optional_param(value)
        # optional param
        aparam = map_class.get_optional_param()
        dict_data = getattr(myfetch,
                            service_options[service]["method"])(flag_filter,
                                                                aparam)

    # update data
    map_class.update(dict_data)
    # plot map
    map_class.plot()

    # get image names
    filename_image = map_class.getImageFilename()
    filename_legend = map_class.getLegendFilename()
    image_size = map_class.getImageSize()
    legend_size = map_class.getImageLegendSize()
    # log.debug("legend size is: {0}".format(legend_size))
    abs_web_path_image = "/".join([""] + list_image_dir + [filename_image])
    abs_web_path_legend = "/".join([""] + list_image_dir + [filename_legend])
    img_flag = "?" + str(time.time())
    return render_template("mesh/rack/rack.html",
                           flag_home=False,
                           rack=rack,
                           imageWidth=image_size["width"],
                           imageHeight=image_size["height"],
                           legendWidth=legend_size["width"],
                           legendHeight=legend_size["height"],
                           service=service,
                           imageFilename=abs_web_path_image + img_flag,
                           legendFilename=abs_web_path_legend + img_flag)
예제 #52
0
    def _start_mongo(self):
        """
        start the mongodb service in the location as specified in
        cloudmesh_server.yaml
        """
        banner("Starting mongod")
        config = cm_config_server().get("cloudmesh.server.mongo")
        path = path_expand(config["path"])
        port = config["port"]

        # pprint(config)
        # print(path)
        # print(port)

        banner("creating dir")
        if not os.path.exists(path):
            print("Creating mongodb directory in {0}".format(path))
            sh.mkdir("-p", path)

        banner("check")

        # lines = str(sh.grep(sh.ps("-ax"), "mongod", "*port {0}".format(port)))
        # need to get rid of fabric local later
        with settings(warn_only=True):
            with hide('output', 'running', 'warnings'):
                lines = local(
                    "ps -ax |grep '[m]ongod.*port {0}'".format(port), capture=True) \
                    .split("\n")
        print("search result:")
        # print(type(lines))
        print(lines)
        if lines != ['']:
            pid = lines[0].split(" ")[0]
            print("NO ACTION: mongo already running in pid "
                  "{0} for port {1}".format(pid, port))
            return

        print("ACTION: Starting mongod")
        print()
        print("NOTE: the preparation of mongo may take a few minutes")
        print("      please do not interrupt this program.")
        print()
        print("      Please be patient!")
        print()
        '''
        Shell.mongod("--auth",
                  "--bind_ip", "127.0.0.1"
                  "--fork",
                  "--dbpath", path,
                  "--logpath", "{0}/mongodb.log".format(path),
                  "--port",  port,
                  _bg=True)
        '''

        # need to get rid of fabric local later     

        local(
            'mongod --auth --bind_ip 127.0.0.1 '
            '--fork --dbpath {0} '
            '--logpath {0}/mongodb.log '
            '--port {1}'.format(path, port))
예제 #53
0
 def __init__(self):
     self.config_server = cm_config_server().get(
         "cloudmesh.server.clusters")
     self.inventory = Inventory()