예제 #1
0
 def __init__(self, cls, database, user=None, username=None, email=None, commit_at_exit=True):
     # Check if context is not already locked
     if get_context() != None:
         raise ValueError('Cannot acquire context. Already locked.')
     # Acquire lock on database
     DBSEM.acquire()
     from server import get_server
     self.context = cls()
     self.context.database = database
     self.context.server = get_server()
     self.commit_at_exit = commit_at_exit
     # Set context
     set_context(self.context)
     # Get user by user
     if email:
         query = AndQuery(
             PhraseQuery('format', 'user'),
             PhraseQuery('email', email),
         )
         search = database.search(query)
         if search:
             user = search.get_resources(size=1).next()
     # Get user by username
     if username:
         user = self.context.root.get_user(username)
     # Log user
     if user:
         self.context.login(user)
예제 #2
0
파일: main.py 프로젝트: Br0bby/bgs4a
    def build(self):
        root = FloatLayout(size_hint=(1, 1))

        self.server = get_server(8000)
        Clock.schedule_interval(self.run_server, 0.032)

        self.browser = KivyBrowser("http://localhost:8000/index.html")
        root.add_widget(self.browser)
        return root
예제 #3
0
def plot():
    """

    NOTES:
    1. have to use unix-style paths in the webbrowser.get() call
       http://stackoverflow.com/questions/24873302/python-generic-webbrowser-get-open-for-chrome-exe-does-not-work
    """
    global _server
    if _server is None:
        _server = server.get_server("localhost", 7777)
    chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"  # see NOTE 1
    webbrowser.get("google-Chrome").open_new_tab("http://localhost:7777/chart?id=123")
예제 #4
0
 def reload_http_server(self):
  """Reload the http server."""
  if self.http_server:
   self.http_server.shutdown()
   logger.info('Shutdown the HTTP server.')
  if config.config.get('http', 'enabled') and not self.http_server:
   self.http_server = server.get_server()
   self.server_thread = Thread(target = self.http_server.serve_forever)
   self.server_thread.start()
   logger.info('Started HTTP server.')
  else:
   self.http_server = None
   self.server_thread = None
   logger.info('Not starting HTTP server.')
예제 #5
0
def live_migrate(vm_id, destination_host):
    """ live migrate instance
    :param vm_id: id of vm
    :param destination_host: migrate to destination host
    """
    server = yield get_server(vm_id=vm_id)
    if VM_STATUS_ACTIVE != server['state']:
        raise LiveMigrateVmStatusError()
    hosts = yield get_migrate_available_host(server)
    if destination_host not in [host['name'] for host in hosts]:
        raise MigrateBeyondDomain()
    try:
        yield live_migrate_request(vm_id, destination_host)
    except Exception, e:
        LOG.error("live migrate instance error: %s" % e)
        raise MigrateFailed
예제 #6
0
def resize(vm_id, cores, memory):
    if isinstance(vm_id, basestring):
        instance = yield get_server(vm_id=vm_id)
    else:
        instance = vm_id
    tenant = instance['tenant']['id']
    if VM_STATUS_STOP != instance['state']:
        raise ResizeVmStatusError()
    sys_volume_size = instance['sys_volume']['size']
    quota = yield check_tenant_quota(tenant, cores - instance['cores'],
                                     memory - instance['memory_mb'])
    flavor = yield find_or_create_flavor(cores, memory, sys_volume_size)
    yield __update_instance_flavor(instance['id'], **flavor)
    yield server_action(instance['id'],
                        Control.REBOOT,
                        info={"type": __REBOOT_HARD})
    yield update_tenant_vm_quotas(tenant, quota['used_cores'],
                                  quota['used_memorys'])
예제 #7
0
def cold_migrate(vm_id, destination_host):
    """ cold migrate instance
    :param vm_id: id of vm
    :param destination_host: migrate to destination host
    """
    try:
        server = yield get_server(vm_id=vm_id)
        if VM_STATUS_STOP != server['state']:
            raise ColdMigrateVmStatusError()
        hosts = yield get_migrate_available_host(server)
        if destination_host not in [host['name'] for host in hosts]:
            raise MigrateBeyondDomain()
        server_id = server['id']
        yield __update_server_host(server_id, destination_host)
        migrate_data = {NEED_REBOOT: 1}
        yield add_server_meta(server_id, **migrate_data)
    except Exception, e:
        LOG.error("cold migrate instance error: %s" % e)
        raise e
예제 #8
0
 def __init__(self, server = None, project = None, options = None):
     '''
         :param Server server: The server where the script to run. Default None, to run on local machine.
         :param Project project: The chuff project that the chuff command will run in. Default get current directory as project directory.
         :param dict options: additional options that will pass to all the functions chuff will call
     '''
     self.server = get_server()
     self.project = project
     if self.project is None:
         self.project = Project.open()
     # options comes first from the server config, then project config, then options parameters.
     self.options = self.server.get_options()
     if self.project:
         self.options.update(self.project.get_options())
     if options is not None:
         self.options.update(options)
     self.script_dir = []
     if 'CHUFF_COMMAND_DIR' in globals():
         self.script_dir.append(globals()['CHUFF_COMMAND_DIR'])
예제 #9
0
파일: extend.py 프로젝트: sskafandri/autovm
from server import get_arg, get_server, get_center, response

serve = get_center()

if not serve:
    serve = get_server()

if not serve:
    response(False)

address = get_arg('ip[ip]')

try:
    machine = serve.get_vm_by_name(address)
except:
    response(False)

if not machine:
    response(False)

# Operating system username
username = get_arg('username')

# And its password
password = get_arg('password')

try:
    machine.login_in_guest(username, password)
except:
    response(False)
예제 #10
0
    this_receiver = RabbitReceiver()
    # Read the messages.
    rabbit_logger.info('Starting the listener for RabbitMQ messages on the queue "match_data"')
    this_receiver.receiver_start(rabbit_callback)


def rabbit_callback(ch, method, properties, body):
    # This callback function will be called each time a new RabbitMQ message is received.
    logger_name_rabbit = logger_name + '.rabbit'
    rabbit_logger = logging.getLogger(logger_name_rabbit)
    rabbit_logger.info('Received new RabbitMQ message')
    try:
        # First the byte string JSON has to be parsed as a dict.
        msg_json = body.decode('utf-8')
        msg_dict = json.loads(msg_json)
        # Save the received data to the database.
        elastic_server.post_json(msg_dict)

    except Exception as e:
        rabbit_logger.error(e)


if __name__ == '__main__':
    logger.info('------- START MAIN ---------')
    # Start the listener for messages in RabbitMQ as a thread.
    rabbit_listener_thread = threading.Thread(target=rabbit_listener)
    rabbit_listener_thread.start()
    # Start the flask server that provides the API at "localhost:5000/get_matches".
    app = get_server()
    app.run(debug=False)
예제 #11
0
    def init_from_environ(self, environ, user=None):
        from server import get_server
        # Set environ
        self.environ = environ
        path = environ.get('PATH_INFO')
        self.path = path
        self.header_response = []
        self.content_type = None
        self.status = None
        # Get database
        server = get_server()
        self.server = server
        self.database = server.database
        # Root
        self.root = self.database.get_resource('/')
        # The request method
        self.method = environ.get('REQUEST_METHOD')
        # Get body
        self.body = self.get_body_from_environ()
        # The query
        query = environ.get('QUERY_STRING')
        self.query = decode_query(query)
        # Accept language
        accept_language = self.environ.get('HTTP_ACCEPT_LANGUAGE', '')
        if accept_language is None:
            accept_language = ''
        try:
            self.accept_language = AcceptLanguageType.decode(accept_language)
        except:
            # Cannot decode accept language
            pass
        # The URI as it was typed by the client
        xfp = environ.get('HTTP_X_FORWARDED_PROTO')
        src_scheme = xfp or 'http'
        xff = environ.get('HTTP_X-Forwarded-Host')
        if xff:
            xff = xff.split(',', 1)[0].strip()
        src_host = xff or environ.get('HTTP_HOST')
        if query:
            uri = '%s://%s%s?%s' % (src_scheme, src_host, path, query)
        else:
            uri = '%s://%s%s' % (src_scheme, src_host, path)
        self.uri = get_reference(uri)

        # Split the path into path and method ("a/b/c/;view")
        path = path if type(path) is Path else Path(path)
        name = path.get_name()
        if name and name[0] == ';':
            self.path = path[:-1]
            self.view_name = name[1:]
        else:
            self.path = path
            self.view_name = None

        # Cookies
        self.cookies = {}

        # Media files (CSS, javascript)
        # Set the list of needed resources. The method we are going to
        # call may need external resources to be rendered properly, for
        # example it could need an style sheet or a javascript file to
        # be included in the html head (which it can not control). This
        # attribute lets the interface to add those resources.
        self.styles = []
        self.scripts = []
        # Log user if user is given
        if user:
            self.login(user)
        # The authenticated user
        self.authenticate()
        # Search
        self._context_user_search = self._user_search(self.user)
        # The Site Root
        self.find_site_root()
        self.site_root.before_traverse(self)  # Hook
        # Not a cron
        self.is_cron = False
        # Set header
        self.set_header('Server', 'ikaaro.web')
예제 #12
0
파일: context.py 프로젝트: hforge/ikaaro
    def init_from_environ(self, environ, user=None):
        from server import get_server
        # Set environ
        self.environ = environ
        path = environ.get('PATH_INFO')
        self.path = path
        self.header_response = []
        self.content_type = None
        self.status = None
        # Get database
        server = get_server()
        self.server = server
        self.database = server.get_database()
        # Root
        self.root = self.database.get_resource('/')
        # The request method
        self.method = environ.get('REQUEST_METHOD')
        # Get body
        self.body = self.get_body_from_environ()
        # The query
        query = environ.get('QUERY_STRING')
        self.query = decode_query(query)
        # Accept language
        accept_language = self.environ.get('HTTP_ACCEPT_LANGUAGE', '')
        if accept_language is None:
            accept_language = ''
        try:
            self.accept_language = AcceptLanguageType.decode(accept_language)
        except:
            # Cannot decode accept language
            pass
        # The URI as it was typed by the client
        xfp = environ.get('HTTP_X_FORWARDED_PROTO')
        src_scheme = xfp or 'http'
        xff = environ.get('HTTP_X-Forwarded-Host')
        if xff:
            xff = xff.split(',', 1)[0].strip()
        src_host = xff or environ.get('HTTP_HOST')
        if query:
            uri = '%s://%s%s?%s' % (src_scheme, src_host, path, query)
        else:
            uri = '%s://%s%s' % (src_scheme, src_host, path)
        self.uri = get_reference(uri)

        # Split the path into path and method ("a/b/c/;view")
        path = path if type(path) is Path else Path(path)
        name = path.get_name()
        if name and name[0] == ';':
            self.path = path[:-1]
            self.view_name = name[1:]
        else:
            self.path = path
            self.view_name = None

        # Cookies
        self.cookies = {}

        # Media files (CSS, javascript)
        # Set the list of needed resources. The method we are going to
        # call may need external resources to be rendered properly, for
        # example it could need an style sheet or a javascript file to
        # be included in the html head (which it can not control). This
        # attribute lets the interface to add those resources.
        self.styles = []
        self.scripts = []
        # Log user if user is given
        if user:
            self.login(user)
        # The authenticated user
        self.authenticate()
        # Search
        self._context_user_search = self._user_search(self.user)
        # The Site Root
        self.find_site_root()
        self.site_root.before_traverse(self)  # Hook
        # Not a cron
        self.is_cron = False
        # Set header
        self.set_header('Server', 'ikaaro.web')
예제 #13
0
from server import get_server

if __name__ == "__main__":
    server = get_server(play_guessing=False,
                        env_name='double',
                        random_behaviour=True)
    server.port = 8521  # The default
    server.launch()
예제 #14
0
from server import get_server

if __name__ == "__main__":
    _, run_server = get_server(True)

    run_server()