예제 #1
0
 def delete(self, req, id):
     """
     Delete a keypair with a given name
     """
     context = req.environ['nova.context']
     db.key_pair_destroy(context, context.user_id, id)
     return exc.HTTPAccepted()
예제 #2
0
 def delete(self, req, id):
     """
     Delete a keypair with a given name
     """
     context = req.environ['nova.context']
     db.key_pair_destroy(context, context.user_id, id)
     return webob.Response(status_int=202)
예제 #3
0
파일: keypairs.py 프로젝트: emonty/nova
 def delete(self, req, id):
     """
     Delete a keypair with a given name
     """
     context = req.environ['nova.context']
     db.key_pair_destroy(context, context.user_id, id)
     return webob.Response(status_int=202)
예제 #4
0
 def delete_key_pair(self, context, key_name, **kwargs):
     LOG.audit(_("Delete key pair %s"), key_name, context=context)
     try:
         db.key_pair_destroy(context, context.user_id, key_name)
     except exception.NotFound:
         # aws returns true even if the key doesn't exist
         pass
     return True
예제 #5
0
파일: cloud.py 프로젝트: yosh/nova
 def delete_key_pair(self, context, key_name, **kwargs):
     LOG.audit(_("Delete key pair %s"), key_name, context=context)
     try:
         db.key_pair_destroy(context, context.user_id, key_name)
     except exception.NotFound:
         # aws returns true even if the key doesn't exist
         pass
     return True
예제 #6
0
 def test_destroy(self):
     self.mox.StubOutWithMock(db, 'key_pair_destroy')
     db.key_pair_destroy(self.context, 'fake-user', 'foo-keypair')
     self.mox.ReplayAll()
     keypair_obj = keypair.KeyPair(context=self.context)
     keypair_obj.id = 123
     keypair_obj.user_id = 'fake-user'
     keypair_obj.name = 'foo-keypair'
     keypair_obj.destroy()
예제 #7
0
 def test_destroy(self):
     self.mox.StubOutWithMock(db, 'key_pair_destroy')
     db.key_pair_destroy(self.context, 'fake-user', 'foo-keypair')
     self.mox.ReplayAll()
     keypair_obj = keypair.KeyPair()
     keypair_obj.id = 123
     keypair_obj.user_id = 'fake-user'
     keypair_obj.name = 'foo-keypair'
     keypair_obj.destroy(self.context)
예제 #8
0
파일: admin.py 프로젝트: mgius/openstackx
 def delete(self, req, id):
     context = req.environ['nova.context']
     key_name = id
     LOG.audit(_("Delete key pair %s"), key_name, context=context)
     try:
         db.key_pair_destroy(context, context.user_id, key_name)
     except exception.NotFound:
         # aws returns true even if the key doesn't exist
         pass
     return exc.HTTPAccepted()
예제 #9
0
 def delete(self, req, id):
     context = req.environ['nova.context']
     key_name = id
     LOG.audit(_("Delete key pair %s"), key_name, context=context)
     try:
         db.key_pair_destroy(context, context.user_id, key_name)
     except exception.NotFound:
         # aws returns true even if the key doesn't exist
         pass
     return exc.HTTPAccepted()
예제 #10
0
 def delete(self, req, id):
     """
     Delete a keypair with a given name
     """
     context = req.environ["nova.context"]
     authorize(context)
     try:
         db.key_pair_destroy(context, context.user_id, id)
     except exception.KeypairNotFound:
         raise webob.exc.HTTPNotFound()
     return webob.Response(status_int=202)
예제 #11
0
 def delete(self, req, id):
     """
     Delete a keypair with a given name
     """
     context = req.environ['nova.context']
     authorize(context)
     try:
         db.key_pair_destroy(context, context.user_id, id)
     except exception.KeypairNotFound:
         raise webob.exc.HTTPNotFound()
     return webob.Response(status_int=202)
예제 #12
0
    def create(self, req, resp_obj, body):
        """
        When create action, not import, upload private key to NOS
        and update private_key_url in DB.
        """
        # NOTE(hzyangtk): Catch the create response from keypairs API.
        #                 If is create(not import), upload the generate
        #                 private key to NOS. And store private key url
        #                 of NOS into nova.keypairs table.
        context = req.environ['nova.context']
        authorize(context)

        self._init_nos_api(context)

        keypair = resp_obj.obj['keypair']
        params = body['keypair']

        # NOTE(hzyangtk): when do creating keypairs, fingerprint will
        #                 be add an extra string '.create' to end. This
        #                 action is target to idetify create and import
        is_create = False
        if 'public_key' not in params:
            is_create = True
            create_fingerprint = keypair['fingerprint'] + '.create'
            db.key_pair_update_fingerprint(context, context.user_id,
                                           keypair['name'],
                                           create_fingerprint)

        if is_create and FLAGS.keypairs_connect_nos:
            # NOTE(hzyangtk): This means this is create but not import.
            #                 Then, determine use nos to store
            #                 keypairs or not by FLAGS.keypairs_connect_nos.
            #                 if use nos to store keypairs, it will
            #                 upload private key to nos when create
            #                 return a private key url of nos to NOVA
            #                 and store it into db with private_key_url
            try:
                tmp_data = db.key_pair_get(context, context.user_id,
                                           keypair['name'])
                created_at_local_tz = self._tz_utc_to_local(
                                            tmp_data['created_at'])
                create_timestamp = self._datetime_to_timestamp(
                                        created_at_local_tz)
                expires = long(create_timestamp + self.expires_time)
                if context.user_name is not None:
                    private_key_name = context.user_name + '_' \
                                            + keypair['name'] \
                                            + '.private'
                else:
                    private_key_name = keypair['fingerprint'].replace(':', '')
                private_key_content = keypair['private_key']
                check_bucket = self.call_nos.check_bucket_exist(
                                    self.bucket_name)
                if not check_bucket:
                    self.call_nos.create_bucket(self.bucket_name)
                else:
                    check_object = self.call_nos.check_object_exist(
                                        self.bucket_name,
                                        private_key_name)
                    if check_object:
                        self.call_nos.delete_private_key(self.bucket_name,
                                                         private_key_name)
                private_key_url = self.call_nos.upload_private_key(
                                        self.bucket_name,
                                        private_key_name,
                                        private_key_content,
                                        expires,
                                        self.use_domain)

                keypair['private_key_url'] = private_key_url
            except (webob.exc.HTTPClientError, webob.exc.HTTPRequestTimeout):
                # NOTE(hzyangtk): when NOS connect error occurs, delete the
                #                 generated keypair.
                self._notify_NOS_connection_failure(context, tmp_data)
                try:
                    db.key_pair_destroy(context,
                                        context.user_id,
                                        keypair['name'])
                except exception.KeypairNotFound:
                    # NOTE(hzyangtk): when keypair not found, to do nothing
                    pass
                nos_url = FLAGS.nos_url
                nos_host = FLAGS.nos_host
                nos_accessKey = FLAGS.nos_accessKey
                nos_accessSecret = FLAGS.nos_accessSecret
                LOG.exception(_("Connect to NOS error, "
                                "nos_url: %(nos_url)s, "
                                "nos_host: %(nos_host)s, "
                                "nos_accessKey: %(nos_accessKey)s,"
                                "nos_accessSecret: %(nos_accessSecret)s."),
                              locals())
                err_msg = _("Private key URL generate failed")
                raise webob.exc.HTTPServerError(explanation=err_msg)
예제 #13
0
 def destroy(self, context):
     db.key_pair_destroy(context, self.user_id, self.name)
예제 #14
0
 def destroy_by_name(cls, context, user_id, name):
     db.key_pair_destroy(context, user_id, name)
예제 #15
0
 def test_destroy_by_name(self):
     self.mox.StubOutWithMock(db, 'key_pair_destroy')
     db.key_pair_destroy(self.context, 'fake-user', 'foo-keypair')
     self.mox.ReplayAll()
     keypair.KeyPair.destroy_by_name(self.context, 'fake-user',
                                     'foo-keypair')
예제 #16
0
파일: keypair.py 프로젝트: sapcc/nova
 def destroy_by_name(cls, context, user_id, name):
     try:
         cls._destroy_in_db(context, user_id, name)
     except exception.KeypairNotFound:
         db.key_pair_destroy(context, user_id, name)
예제 #17
0
 def test_destroy_by_name(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'key_pair_destroy')
     db.key_pair_destroy(ctxt, 'fake-user', 'foo-keypair')
     self.mox.ReplayAll()
     keypair.KeyPair.destroy_by_name(ctxt, 'fake-user', 'foo-keypair')
예제 #18
0
 def destroy_by_name(cls, context, user_id, name):
     try:
         cls._destroy_in_db(context, user_id, name)
     except exception.KeypairNotFound:
         db.key_pair_destroy(context, user_id, name)
예제 #19
0
 def destroy(self, context):
     db.key_pair_destroy(context, self.user_id, self.name)
예제 #20
0
 def destroy_by_name(cls, context, user_id, name):
     db.key_pair_destroy(context, user_id, name)
예제 #21
0
 def destroy(self):
     try:
         self._destroy_in_db(self._context, self.user_id, self.name)
     except exception.KeypairNotFound:
         db.key_pair_destroy(self._context, self.user_id, self.name)
예제 #22
0
파일: keypair.py 프로젝트: sapcc/nova
 def destroy(self):
     try:
         self._destroy_in_db(self._context, self.user_id, self.name)
     except exception.KeypairNotFound:
         db.key_pair_destroy(self._context, self.user_id, self.name)
예제 #23
0
 def test_destroy_by_name(self):
     self.mox.StubOutWithMock(db, 'key_pair_destroy')
     db.key_pair_destroy(self.context, 'fake-user', 'foo-keypair')
     self.mox.ReplayAll()
     keypair.KeyPair.destroy_by_name(self.context, 'fake-user',
                                     'foo-keypair')
예제 #24
0
 def test_destroy_by_name(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'key_pair_destroy')
     db.key_pair_destroy(ctxt, 'fake-user', 'foo-keypair')
     self.mox.ReplayAll()
     keypair.KeyPair.destroy_by_name(ctxt, 'fake-user', 'foo-keypair')