Added WebServer and AD
This commit is contained in:
parent
2dd0b2cc4f
commit
c9396320b9
@ -49,8 +49,8 @@ class Manager(object):
|
||||
def __init__(self, api):
|
||||
self.api = api
|
||||
|
||||
def _list(self, url, response_key=None, obj_class=None, body=None):
|
||||
resp, body = self.api.json_request('GET', url)
|
||||
def _list(self, url, response_key=None, obj_class=None, body=None, headers={}):
|
||||
resp, body = self.api.json_request('GET', url, headers=headers)
|
||||
|
||||
if obj_class is None:
|
||||
obj_class = self.resource_class
|
||||
@ -61,8 +61,8 @@ class Manager(object):
|
||||
data = body
|
||||
return [obj_class(self, res, loaded=True) for res in data if res]
|
||||
|
||||
def _delete(self, url):
|
||||
self.api.raw_request('DELETE', url)
|
||||
def _delete(self, url, headers={}):
|
||||
self.api.raw_request('DELETE', url, headers=headers)
|
||||
|
||||
def _update(self, url, body, response_key=None):
|
||||
resp, body = self.api.json_request('PUT', url, body=body)
|
||||
@ -72,11 +72,11 @@ class Manager(object):
|
||||
return self.resource_class(self, body[response_key])
|
||||
return self.resource_class(self, body)
|
||||
|
||||
def _create(self, url, body=None, response_key=None, return_raw=False):
|
||||
def _create(self, url, body=None, response_key=None, return_raw=False, headers={}):
|
||||
if body:
|
||||
resp, body = self.api.json_request('POST', url, body=body)
|
||||
resp, body = self.api.json_request('POST', url, body=body, headers=headers)
|
||||
else:
|
||||
resp, body = self.api.json_request('POST', url)
|
||||
resp, body = self.api.json_request('POST', url, headers=headers)
|
||||
if return_raw:
|
||||
if response_key:
|
||||
return body[response_key]
|
||||
|
@ -14,7 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
from portasclient.common import http
|
||||
from portasclient.v1 import environments, sessions
|
||||
from portasclient.v1 import environments, sessions, services
|
||||
|
||||
|
||||
class Client(http.HTTPClient):
|
||||
@ -31,4 +31,6 @@ class Client(http.HTTPClient):
|
||||
""" Initialize a new client for the Portas v1 API. """
|
||||
super(Client, self).__init__(*args, **kwargs)
|
||||
self.environments = environments.EnvironmentManager(self)
|
||||
self.sessions = sessions.SessionManager(self)
|
||||
self.sessions = sessions.SessionManager(self)
|
||||
self.activeDirectories = services.ActiveDirectoryManager(self)
|
||||
self.webServers = services.WebServerManager(self)
|
@ -12,7 +12,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import anyjson
|
||||
|
||||
from portasclient.common import base
|
||||
|
||||
|
74
python-portasclient/portasclient/v1/services.py
Normal file
74
python-portasclient/portasclient/v1/services.py
Normal file
@ -0,0 +1,74 @@
|
||||
# Copyright 2012 OpenMeter LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from portasclient.common import base
|
||||
|
||||
|
||||
class ActiveDirectory(base.Resource):
|
||||
def __repr__(self):
|
||||
return '<ActiveDirectory %s>' % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class ActiveDirectoryManager(base.Manager):
|
||||
resource_class = ActiveDirectory
|
||||
|
||||
def list(self, environment_id, session_id):
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
return self._list('environments/{id}/activeDirectories'.format(id=environment_id), 'activeDirectories',
|
||||
headers=headers)
|
||||
|
||||
def create(self, environment_id, session_id, active_directory):
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
|
||||
return self._create('environments/{id}/activeDirectories'.format(id=environment_id), active_directory,
|
||||
headers=headers)
|
||||
|
||||
def delete(self, environment_id, session_id, active_directory_id):
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
|
||||
return self._delete('environments/{id}/activeDirectories/{active_directory_id}'
|
||||
.format(id=environment_id, active_directory_id=active_directory_id), headers=headers)
|
||||
|
||||
|
||||
class WebServer(base.Resource):
|
||||
def __repr__(self):
|
||||
return '<WebServer %s>' % self._info
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
|
||||
class WebServerManager(base.Manager):
|
||||
resource_class = ActiveDirectory
|
||||
|
||||
def list(self, environment_id, session_id):
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
return self._list('environments/{id}/webServers'.format(id=environment_id), 'webServers',
|
||||
headers=headers)
|
||||
|
||||
def create(self, environment_id, session_id, web_server):
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
|
||||
return self._create('environments/{id}/webServers'.format(id=environment_id), web_server,
|
||||
headers=headers)
|
||||
|
||||
def delete(self, environment_id, session_id, web_server_id):
|
||||
headers = {'X-Configuration-Session': session_id}
|
||||
|
||||
return self._delete('environments/{id}/webServers/{web_server_id}'
|
||||
.format(id=environment_id, web_server_id=web_server_id), headers=headers)
|
Loading…
x
Reference in New Issue
Block a user