Beispiel #1
0
    def launch_vpn_instance(self, project_id):
        logging.debug("Launching VPN for %s" % (project_id))
        project = self.manager.get_project(project_id)
        # Make a payload.zip
        tmpfolder = tempfile.mkdtemp()
        filename = "payload.zip"
        zippath = os.path.join(tmpfolder, filename)
        z = ZipFile(zippath, "w", ZIP_DEFLATED)

        z.write(FLAGS.boot_script_template, 'autorun.sh')
        z.close()

        key_name = self.setup_keypair(project.project_manager_id, project_id)
        zippy = open(zippath, "r")
        context = api.APIRequestContext(handler=None,
                                        user=project.project_manager,
                                        project=project)

        reservation = self.controller.run_instances(
            context,
            # run instances expects encoded userdata, it is decoded in the get_metadata_call
            # autorun.sh also decodes the zip file, hence the double encoding
            user_data=zippy.read().encode("base64").encode("base64"),
            max_count=1,
            min_count=1,
            instance_type='m1.tiny',
            image_id=FLAGS.vpn_image_id,
            key_name=key_name,
            security_groups=["vpn-secgroup"])
        zippy.close()
Beispiel #2
0
    def setUp(self):
        super(CloudTestCase, self).setUp()
        self.flags(fake_libvirt=True,
                   fake_storage=True,
                   fake_users=True)

        self.conn = rpc.Connection.instance()
        logging.getLogger().setLevel(logging.DEBUG)

        # set up our cloud
        self.cloud = cloud.CloudController()
        self.cloud_consumer = rpc.AdapterConsumer(connection=self.conn,
                                                      topic=FLAGS.cloud_topic,
                                                      proxy=self.cloud)
        self.injected.append(self.cloud_consumer.attach_to_tornado(self.ioloop))

        # set up a node
        self.node = node.Node()
        self.node_consumer = rpc.AdapterConsumer(connection=self.conn,
                                                     topic=FLAGS.compute_topic,
                                                     proxy=self.node)
        self.injected.append(self.node_consumer.attach_to_tornado(self.ioloop))

        try:
            users.UserManager.instance().create_user('admin', 'admin', 'admin')
        except: pass
        admin = users.UserManager.instance().get_user('admin')
        project = users.UserManager.instance().create_project('proj', 'admin', 'proj')
        self.context = api.APIRequestContext(handler=None,project=project,user=admin)
Beispiel #3
0
    def setUp(self):
        super(CloudTestCase, self).setUp()

        self.conn = rpc.Connection.instance()
        logging.getLogger().setLevel(logging.DEBUG)

        # set up our cloud
        self.cloud = cloud.CloudController()
        self.cloud_consumer = rpc.AdapterConsumer(connection=self.conn,
                                                  topic=FLAGS.cloud_topic,
                                                  proxy=self.cloud)
        self.injected.append(self.cloud_consumer.attach_to_tornado(
            self.ioloop))

        # set up a node
        self.node = node.Node()
        self.node_consumer = rpc.AdapterConsumer(connection=self.conn,
                                                 topic=FLAGS.compute_topic,
                                                 proxy=self.node)
        self.injected.append(self.node_consumer.attach_to_tornado(self.ioloop))

        user_mocker = mox.Mox()
        self.admin = user_mocker.CreateMock(users.User)
        self.admin.is_authorized(mox.IgnoreArg()).AndReturn(True)
        self.context = api.APIRequestContext(handler=None, user=self.admin)
Beispiel #4
0
 def context(self):
     if not hasattr(self, '_context'):
         try:
             # Authorization Header format: 'AWS <access>:<secret>'
             access, sep, secret = self.request.headers['Authorization'].split(' ')[1].rpartition(':')
             (user, project) = self.application.user_manager.authenticate(access, secret, {}, self.request.method, self.request.host, self.request.path, False)
             # FIXME: check signature here!
             self._context = api.APIRequestContext(self, user, project)
         except exception.Error, ex:
             logging.debug("Authentication Failure: %s" % ex)
             raise web.HTTPError(403)