예제 #1
0
def deploy_sensor_app():
    """ Uploads the sensor app for registered deployments. """

    deployment_id = helper.get_deployment_id()
    #If deployment is not registered, then do nothing.
    if not deployment_id:
        return

    uaserver = SOAPpy.SOAPProxy('https://{0}:{1}'.format(
        appscale_info.get_db_master_ip(), hermes_constants.UA_SERVER_PORT))

    # If the appscalesensor app is already running, then do nothing.
    is_app_enabled = uaserver.is_app_enabled(hermes_constants.APPSCALE_SENSOR,
                                             appscale_info.get_secret())
    if is_app_enabled == "true":
        return

    pwd = appscale_utils.encrypt_password(
        hermes_constants.USER_EMAIL,
        appscale_utils.random_password_generator())
    if create_appscale_user(pwd, uaserver) and create_xmpp_user(pwd, uaserver):
        logging.debug("Created new user and now tarring app to be deployed.")
        file_path = os.path.join(os.path.dirname(__file__), '../Apps/sensor')
        app_dir_location = os.path.join(hermes_constants.APP_DIR_LOCATION,
                                        hermes_constants.APPSCALE_SENSOR)
        archive = tarfile.open(app_dir_location, "w|gz")
        archive.add(file_path, arcname=hermes_constants.APPSCALE_SENSOR)
        archive.close()

        try:
            logging.info(
                "Deploying the sensor app for registered deployments.")
            acc = appscale_info.get_appcontroller_client()
            acc.upload_app(app_dir_location, hermes_constants.FILE_SUFFIX,
                           hermes_constants.USER_EMAIL)
        except AppControllerException:
            logging.exception("AppControllerException while trying to deploy "
                              "appscalesensor app.")
    else:
        logging.error("Error while creating or accessing the user to deploy "
                      "appscalesensor app.")
예제 #2
0
def create_xmpp_user(password, uaserver):
  """ Creates the XMPP account. If the user's email is [email protected], then that
  means their XMPP account name is a@login_ip. """
  username_regex = re.compile('\A(.*)@')
  username = username_regex.match(hermes_constants.USER_EMAIL).groups()[0]
  xmpp_user = "******".format(username, appscale_info.get_login_ip())
  xmpp_pass = appscale_utils.encrypt_password(xmpp_user, password)
  does_user_exist = uaserver.does_user_exist(xmpp_user,
    appscale_info.get_secret())
  if does_user_exist == "true":
    logging.debug("XMPP User {0} already exists, so not creating it again.".
      format(xmpp_user))
    return True
  else:
    if uaserver.commit_new_user(xmpp_user, xmpp_pass,
        hermes_constants.ACCOUNT_TYPE, appscale_info.get_secret()) == "true":
      logging.info("XMPP username is {0}".format(xmpp_user))
      return True
    else:
      logging.error("Error while creating an XMPP user.")
      return False
예제 #3
0
파일: hermes.py 프로젝트: eabyshev/appscale
def create_xmpp_user(password, uaserver):
  """ Creates the XMPP account. If the user's email is [email protected], then that
  means their XMPP account name is a@login_ip. """
  username_regex = re.compile('\A(.*)@')
  username = username_regex.match(hermes_constants.USER_EMAIL).groups()[0]
  xmpp_user = "******".format(username, appscale_info.get_login_ip())
  xmpp_pass = appscale_utils.encrypt_password(xmpp_user, password)
  does_user_exist = uaserver.does_user_exist(xmpp_user,
    appscale_info.get_secret())
  if does_user_exist == "true":
    logging.debug("XMPP User {0} already exists, so not creating it again.".
      format(xmpp_user))
    return True
  else:
    if uaserver.commit_new_user(xmpp_user, xmpp_pass,
        hermes_constants.ACCOUNT_TYPE, appscale_info.get_secret()) == "true":
      logging.info("XMPP username is {0}".format(xmpp_user))
      return True
    else:
      logging.error("Error while creating an XMPP user.")
      return False
예제 #4
0
파일: hermes.py 프로젝트: eabyshev/appscale
def deploy_sensor_app():
  """ Uploads the sensor app for registered deployments. """

  deployment_id = helper.get_deployment_id()
  #If deployment is not registered, then do nothing.
  if not deployment_id:
    return

  uaserver = SOAPpy.SOAPProxy('https://{0}:{1}'.format(
    appscale_info.get_db_master_ip(), hermes_constants.UA_SERVER_PORT))

  # If the appscalesensor app is already running, then do nothing.
  is_app_enabled = uaserver.is_app_enabled(hermes_constants.APPSCALE_SENSOR,
    appscale_info.get_secret())
  if is_app_enabled == "true":
    return

  pwd = appscale_utils.encrypt_password(hermes_constants.USER_EMAIL,
    appscale_utils.random_password_generator())
  if create_appscale_user(pwd, uaserver) and create_xmpp_user(pwd, uaserver):
    logging.debug("Created new user and now tarring app to be deployed.")
    file_path = os.path.join(os.path.dirname(__file__), '../Apps/sensor')
    app_dir_location = os.path.join(hermes_constants.APP_DIR_LOCATION,
      hermes_constants.APPSCALE_SENSOR)
    archive = tarfile.open(app_dir_location, "w|gz")
    archive.add(file_path, arcname= hermes_constants.APPSCALE_SENSOR)
    archive.close()

    try:
      logging.info("Deploying the sensor app for registered deployments.")
      acc = appscale_info.get_appcontroller_client()
      acc.upload_app(app_dir_location, hermes_constants.FILE_SUFFIX,
        hermes_constants.USER_EMAIL)
    except AppControllerException:
      logging.exception("AppControllerException while trying to deploy "
        "appscalesensor app.")
  else:
    logging.error("Error while creating or accessing the user to deploy "
      "appscalesensor app.")