Пример #1
0
 def _create(self, exclude_id, exclude_type):
     exclude_type_int = -1
     if exclude_type == 'domain':
         exclude_type_int = 0
     elif exclude_type == 'project':
         exclude_type_int = 1
     elif exclude_type == 'user':
         exclude_type_int = 2
     endpoint = get_endpoint(self.app.client_manager)
     headers = {
         'Content-Type': 'application/json',
         'X-Auth-Token': self.app.client_manager.auth_ref.auth_token
     }
     req = requests.post(endpoint + '/vmexcludes/' + exclude_id,
                         headers=headers,
                         json={
                             'id': exclude_id,
                             'type': exclude_type_int
                         })
     if not req.status_code == 202:
         raise osvmexpire_exc.HTTPNotFound('creation failed')
     res = req.json()
     if 'vmexclude' not in res:
         raise osvmexpire_exc.HTTPNotFound('no exclude created')
     return res['vmexclude']
Пример #2
0
 def _extend(self, expire_id):
     endpoint = get_endpoint(self.app.client_manager)
     headers = {
         'Content-Type': 'application/json',
         'X-Auth-Token': self.app.client_manager.auth_ref.auth_token
     }
     req = requests.put(endpoint + '/vmexpires/' + expire_id,
                        headers=headers)
     if not req.status_code == 202:
         raise osvmexpire_exc.HTTPNotFound('no expiration found')
     res = req.json()
     if 'vmexpire' not in res:
         raise osvmexpire_exc.HTTPNotFound('no expiration found')
     return res['vmexpire']
Пример #3
0
 def _list(self, all=False):
     endpoint = get_endpoint(self.app.client_manager)
     headers = {
         'Content-Type': 'application/json',
         'X-Auth-Token': self.app.client_manager.auth_ref.auth_token
     }
     req_params = ''
     if all:
         req_params = '?all_tenants=1'
     req = requests.get(endpoint + '/vmexpires/' + req_params,
                        headers=headers)
     if not req.status_code == 200:
         raise osvmexpire_exc.HTTPNotFound()
     res = req.json()
     if 'vmexpires' not in res:
         raise osvmexpire_exc.HTTPNotFound()
     return res['vmexpires']
Пример #4
0
 def _list(self):
     endpoint = get_endpoint(self.app.client_manager)
     headers = {
         'Content-Type': 'application/json',
         'X-Auth-Token': self.app.client_manager.auth_ref.auth_token
     }
     req = requests.get(endpoint + '/vmexcludes/', headers=headers)
     if not req.status_code == 200:
         raise osvmexpire_exc.HTTPNotFound()
     res = req.json()
     if 'vmexcludes' not in res:
         raise osvmexpire_exc.HTTPNotFound()
     for exclude in res['vmexcludes']:
         if exclude['exclude_type'] == 0:
             exclude['exclude_type'] = 'domain'
         if exclude['exclude_type'] == 1:
             exclude['exclude_type'] = 'project'
         if exclude['exclude_type'] == 2:
             exclude['exclude_type'] = 'user'
     return res['vmexcludes']
Пример #5
0
 def _delete(self, exclude_id):
     endpoint = get_endpoint(self.app.client_manager)
     headers = {
         'Content-Type': 'application/json',
         'X-Auth-Token': self.app.client_manager.auth_ref.auth_token
     }
     req = requests.delete(endpoint + '/vmexcludes/' + exclude_id,
                           headers=headers)
     if req.status_code == 404:
         raise osvmexpire_exc.HTTPNotFound('no exclude found')
     elif req.status_code == 403:
         raise osvmexpire_exc.HTTPUnauthorized('not authorized')
     elif req.status_code != 204:
         raise osvmexpire_exc.HTTPInternalServerError('Error')
     return