mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-23 17:34:17 +03:00
Fixes for python 3 (pep related, code warns, etc...)
This commit is contained in:
parent
6293c09ca8
commit
429eead46d
@ -26,9 +26,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import http
|
||||
@ -52,17 +52,17 @@ AUTH_TOKEN_HEADER = 'X-Auth-Token'
|
||||
|
||||
|
||||
class Dispatcher(View):
|
||||
'''
|
||||
"""
|
||||
This class is responsible of dispatching REST requests
|
||||
'''
|
||||
"""
|
||||
# This attribute will contain all paths-->handler relations, added at Initialized method
|
||||
services = {'': None} # Will include a default /rest handler, but rigth now this will be fine
|
||||
|
||||
@method_decorator(csrf_exempt)
|
||||
def dispatch(self, request, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Processes the REST request and routes it wherever it needs to be routed
|
||||
'''
|
||||
"""
|
||||
logger.debug('Language in dispatcher: {0}'.format(request.LANGUAGE_CODE))
|
||||
from uds.REST import processors
|
||||
|
||||
@ -159,9 +159,9 @@ class Dispatcher(View):
|
||||
|
||||
@staticmethod
|
||||
def registerSubclasses(classes):
|
||||
'''
|
||||
"""
|
||||
Try to register Handler subclasses that have not been inherited
|
||||
'''
|
||||
"""
|
||||
for cls in classes:
|
||||
if len(cls.__subclasses__()) == 0: # Only classes that has not been inherited will be registered as Handlers
|
||||
logger.debug('Found class {0}'.format(cls))
|
||||
@ -186,10 +186,10 @@ class Dispatcher(View):
|
||||
# Initializes the dispatchers
|
||||
@staticmethod
|
||||
def initialize():
|
||||
'''
|
||||
"""
|
||||
This imports all packages that are descendant of this package, and, after that,
|
||||
it register all subclases of Handler. (In fact, it looks for packages inside "methods" package, child of this)
|
||||
'''
|
||||
"""
|
||||
import os.path
|
||||
import pkgutil
|
||||
import sys
|
||||
|
@ -84,16 +84,16 @@ class ResponseError(HandlerError):
|
||||
|
||||
|
||||
class NotSupportedError(HandlerError):
|
||||
'''
|
||||
"""
|
||||
Some elements do not support some operations (as searching over an authenticator that does not supports it)
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Handler(object):
|
||||
'''
|
||||
"""
|
||||
REST requests handler base class
|
||||
'''
|
||||
"""
|
||||
raw = False # If true, Handler will return directly an HttpResponse Object
|
||||
name = None # If name is not used, name will be the class name in lower case
|
||||
path = None # Path for this method, so we can do /auth/login, /auth/logout, /auth/auths in a simple way
|
||||
@ -141,31 +141,31 @@ class Handler(object):
|
||||
self._user = self.getUser()
|
||||
|
||||
def headers(self):
|
||||
'''
|
||||
"""
|
||||
Returns the headers of the REST request (all)
|
||||
'''
|
||||
"""
|
||||
return self._headers
|
||||
|
||||
def header(self, headerName):
|
||||
'''
|
||||
"""
|
||||
Get's an specific header name from REST request
|
||||
:param headerName: name of header to get
|
||||
'''
|
||||
"""
|
||||
return self._headers.get(headerName)
|
||||
|
||||
def addHeader(self, header, value):
|
||||
'''
|
||||
"""
|
||||
Inserts a new header inside the headers list
|
||||
:param header: name of header to insert
|
||||
:param value: value of header
|
||||
'''
|
||||
"""
|
||||
self._headers[header] = value
|
||||
|
||||
def removeHeader(self, header):
|
||||
'''
|
||||
"""
|
||||
Removes an specific header from the headers list
|
||||
:param header: Name of header to remove
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
del self._headers[header]
|
||||
except Exception:
|
||||
@ -173,14 +173,14 @@ class Handler(object):
|
||||
|
||||
# Auth related
|
||||
def getAuthToken(self):
|
||||
'''
|
||||
"""
|
||||
Returns the authentication token for this REST request
|
||||
'''
|
||||
"""
|
||||
return self._authToken
|
||||
|
||||
@staticmethod
|
||||
def storeSessionAuthdata(session, id_auth, username, password, locale, platform, is_admin, staff_member, scrambler):
|
||||
'''
|
||||
"""
|
||||
Stores the authentication data inside current session
|
||||
:param session: session handler (Djano user session object)
|
||||
:param id_auth: Authenticator id (DB object id)
|
||||
@ -188,7 +188,7 @@ class Handler(object):
|
||||
:param locale: Assigned locale
|
||||
:param is_admin: If user is considered admin or not
|
||||
:param staff_member: If is considered as staff member
|
||||
'''
|
||||
"""
|
||||
if is_admin:
|
||||
staff_member = True # Make admins also staff members :-)
|
||||
|
||||
@ -203,7 +203,7 @@ class Handler(object):
|
||||
}
|
||||
|
||||
def genAuthToken(self, id_auth, username, password, locale, platform, is_admin, staf_member, scrambler):
|
||||
'''
|
||||
"""
|
||||
Generates the authentication token from a session, that is basically
|
||||
the session key itself
|
||||
:param id_auth: Authenticator id (DB object id)
|
||||
@ -211,7 +211,7 @@ class Handler(object):
|
||||
:param locale: Assigned locale
|
||||
:param is_admin: If user is considered admin or not
|
||||
:param staf_member: If user is considered staff member or not
|
||||
'''
|
||||
"""
|
||||
session = SessionStore()
|
||||
session.set_expiry(GlobalConfig.ADMIN_IDLE_TIME.getInt())
|
||||
Handler.storeSessionAuthdata(session, id_auth, username, password, locale, platform, is_admin, staf_member, scrambler)
|
||||
@ -221,9 +221,9 @@ class Handler(object):
|
||||
return self._authToken
|
||||
|
||||
def cleanAuthToken(self):
|
||||
'''
|
||||
"""
|
||||
Cleans up the authentication token
|
||||
'''
|
||||
"""
|
||||
self._authToken = None
|
||||
if self._session:
|
||||
self._session.delete()
|
||||
@ -231,18 +231,18 @@ class Handler(object):
|
||||
|
||||
# Session related (from auth token)
|
||||
def getValue(self, key):
|
||||
'''
|
||||
"""
|
||||
Get REST session related value for a key
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
return self._session['REST'].get(key)
|
||||
except Exception:
|
||||
return None # _session['REST'] does not exists?
|
||||
|
||||
def setValue(self, key, value):
|
||||
'''
|
||||
"""
|
||||
Set a session key value
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
self._session['REST'][key] = value
|
||||
self._session.accessed = True
|
||||
@ -251,21 +251,21 @@ class Handler(object):
|
||||
logger.exception('Got an exception setting session value {} to {}'.format(key, value))
|
||||
|
||||
def is_admin(self):
|
||||
'''
|
||||
"""
|
||||
True if user of this REST request is administrator
|
||||
'''
|
||||
"""
|
||||
return self.getValue('is_admin') and True or False
|
||||
|
||||
def is_staff_member(self):
|
||||
'''
|
||||
"""
|
||||
True if user of this REST request is member of staff
|
||||
'''
|
||||
"""
|
||||
return self.getValue('staff_member') and True or False
|
||||
|
||||
def getUser(self):
|
||||
'''
|
||||
"""
|
||||
If user is staff member, returns his Associated user on auth
|
||||
'''
|
||||
"""
|
||||
logger.debug('REST : {}'.format(self._session))
|
||||
authId = self.getValue('auth')
|
||||
username = self.getValue('username')
|
||||
|
@ -108,7 +108,6 @@ class Connection(Handler):
|
||||
'thumb': servicePool.image.thumb64 if servicePool.image is not None else DEFAULT_THUMB_BASE64,
|
||||
'show_transports': servicePool.show_transports,
|
||||
'allow_users_remove': servicePool.allow_users_remove,
|
||||
'maintenance': servicePool.isInMaintenance(),
|
||||
'not_accesible': not servicePool.isAccessAllowed(),
|
||||
'to_be_replaced': False, # Manually assigned will not be autoremoved never
|
||||
'transports': trans,
|
||||
@ -139,7 +138,6 @@ class Connection(Handler):
|
||||
'thumb': servicePool.image.thumb64 if servicePool.image is not None else DEFAULT_THUMB_BASE64,
|
||||
'show_transports': servicePool.show_transports,
|
||||
'allow_users_remove': servicePool.allow_users_remove,
|
||||
'maintenance': servicePool.isInMaintenance(),
|
||||
'not_accesible': not servicePool.isAccessAllowed(),
|
||||
'to_be_replaced': servicePool.toBeReplaced(),
|
||||
'transports': trans,
|
||||
|
@ -297,6 +297,7 @@ class BaseModelHandler(Handler):
|
||||
|
||||
# Details do not have types at all
|
||||
# so, right now, we only process details petitions for Handling & tables info
|
||||
# noinspection PyMissingConstructor
|
||||
class DetailHandler(BaseModelHandler): # pylint: disable=abstract-class-not-used
|
||||
"""
|
||||
Detail handler (for relations such as provider-->services, authenticators-->users,groups, deployed services-->cache,assigned, groups, transports
|
||||
@ -407,10 +408,9 @@ class DetailHandler(BaseModelHandler): # pylint: disable=abstract-class-not-use
|
||||
|
||||
parent = self._kwargs['parent']
|
||||
|
||||
if len(self._args) == 0:
|
||||
# Create new
|
||||
item = None
|
||||
elif len(self._args) == 1:
|
||||
# Create new item unless param received
|
||||
item = None
|
||||
if len(self._args) == 1:
|
||||
item = self._args[0]
|
||||
else:
|
||||
self.invalidRequestException()
|
||||
@ -770,6 +770,7 @@ class ModelHandler(BaseModelHandler):
|
||||
for cm in self.custom_methods:
|
||||
if nArgs > 1 and cm[1] is True: # Method needs parent (existing item)
|
||||
if self._args[1] == cm[0]:
|
||||
item = operation = None
|
||||
try:
|
||||
operation = getattr(self, self._args[1])
|
||||
item = self.model.objects.get(uuid=self._args[0].lower())
|
||||
@ -780,6 +781,7 @@ class ModelHandler(BaseModelHandler):
|
||||
return operation(item)
|
||||
|
||||
elif self._args[0] == cm[0]:
|
||||
operation = None
|
||||
try:
|
||||
operation = getattr(self, self._args[0])
|
||||
except Exception:
|
||||
|
@ -61,4 +61,5 @@ def __init__():
|
||||
for cls in a.__subclasses__():
|
||||
auths.factory().insert(cls)
|
||||
|
||||
|
||||
__init__()
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
@ -45,7 +45,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Module(UserInterface, Environmentable, Serializable):
|
||||
'''
|
||||
"""
|
||||
Base class for all modules used by UDS.
|
||||
This base module provides all the needed methods that modules must implement
|
||||
|
||||
@ -93,7 +93,7 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
|
||||
Environmentable is a base class that provides utility method to access a separate Environment for every single
|
||||
module.
|
||||
'''
|
||||
"""
|
||||
# : Which coded to use to encode module by default.
|
||||
# : Basic name used to provide the administrator an "huma readable" form for the module
|
||||
typeName = 'Base Module'
|
||||
@ -105,13 +105,13 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
iconFile = 'base.png' # This is expected to be png, use this format always
|
||||
|
||||
class ValidationException(Exception):
|
||||
'''
|
||||
"""
|
||||
Exception used to indicate that the params assigned are invalid
|
||||
'''
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def name(cls):
|
||||
'''
|
||||
"""
|
||||
Returns "translated" typeName, using ugettext for transforming
|
||||
cls.typeName
|
||||
|
||||
@ -120,12 +120,12 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
|
||||
Returns:
|
||||
Translated type name (using ugettext)
|
||||
'''
|
||||
"""
|
||||
return _(cls.typeName)
|
||||
|
||||
@classmethod
|
||||
def type(cls):
|
||||
'''
|
||||
"""
|
||||
Returns typeType
|
||||
|
||||
Args:
|
||||
@ -133,12 +133,12 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
|
||||
Returns:
|
||||
the typeType of this class (or derived class)
|
||||
'''
|
||||
"""
|
||||
return cls.typeType
|
||||
|
||||
@classmethod
|
||||
def description(cls):
|
||||
'''
|
||||
"""
|
||||
This method returns the "translated" description, that is, using
|
||||
ugettext for transforming cls.typeDescription.
|
||||
|
||||
@ -148,12 +148,12 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
Returns:
|
||||
Translated description (using ugettext)
|
||||
|
||||
'''
|
||||
"""
|
||||
return _(cls.typeDescription)
|
||||
|
||||
@classmethod
|
||||
def icon(cls, inBase64=True):
|
||||
'''
|
||||
"""
|
||||
Reads the file specified by iconFile at module folder, and returns it content.
|
||||
This is used to obtain an icon so administration can represent it.
|
||||
|
||||
@ -165,19 +165,19 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
Returns:
|
||||
Base 64 encoded or raw image, obtained from the specified file at
|
||||
'iconFile' class attribute
|
||||
'''
|
||||
"""
|
||||
logger.debug('Loading icon for class {0} ({1})'.format(cls, cls.iconFile))
|
||||
file_ = open(os.path.dirname(sys.modules[cls.__module__].__file__) + '/' + cls.iconFile, 'rb')
|
||||
data = file_.read()
|
||||
file_.close()
|
||||
if inBase64 == True:
|
||||
if inBase64:
|
||||
return encoders.encode(data, 'base64', asText=True)
|
||||
else:
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def test(env, data):
|
||||
'''
|
||||
"""
|
||||
Test if the connection data is ok.
|
||||
|
||||
Returns an array, first value indicates "Ok" if true, "Bad" or "Error"
|
||||
@ -193,11 +193,11 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
Array of two elements, first is True of False, depending on test
|
||||
(True is all right, false is error),
|
||||
second is an String with error, preferably internacionalizated..
|
||||
'''
|
||||
"""
|
||||
return [True, _("No connection checking method is implemented.")]
|
||||
|
||||
def __init__(self, environment, values=None):
|
||||
'''
|
||||
"""
|
||||
Do not forget to invoke this in your derived class using
|
||||
"super(self.__class__, self).__init__(environment, values)".
|
||||
|
||||
@ -218,7 +218,7 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
If you override marshal, unmarshal and inherited UserInterface method
|
||||
valuesDict, you must also take account of values (dict) provided at the
|
||||
__init__ method of your class.
|
||||
'''
|
||||
"""
|
||||
#
|
||||
UserInterface.__init__(self, values)
|
||||
Environmentable.__init__(self, environment)
|
||||
@ -228,33 +228,33 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
return "Base Module"
|
||||
|
||||
def isDirty(self):
|
||||
'''
|
||||
"""
|
||||
This method informs the core if the module has changed serializable data,
|
||||
and that must be re-serialized
|
||||
|
||||
Default implemetation is that on every method call, module will be dirty
|
||||
|
||||
Note: The implementation of this is a work in progress, so right now the module will be serialized out on every access
|
||||
'''
|
||||
"""
|
||||
return True
|
||||
|
||||
def marshal(self):
|
||||
'''
|
||||
"""
|
||||
By default and if not overriden by descendants, this method, overridden
|
||||
from Serializable, and returns the serialization of
|
||||
form field stored values.
|
||||
'''
|
||||
"""
|
||||
return self.serializeForm()
|
||||
|
||||
def unmarshal(self, str_):
|
||||
'''
|
||||
"""
|
||||
By default and if not overriden by descendants, this method recovers
|
||||
data serialized using serializeForm
|
||||
'''
|
||||
"""
|
||||
self.unserializeForm(str_)
|
||||
|
||||
def check(self):
|
||||
'''
|
||||
"""
|
||||
Method that will provide the "check" capability for the module.
|
||||
|
||||
The return value that this method must provide is simply an string,
|
||||
@ -262,11 +262,11 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
|
||||
Returns:
|
||||
Internacionalized (using ugettext) string of result of the check.
|
||||
'''
|
||||
"""
|
||||
return _("No check method provided.")
|
||||
|
||||
def destroy(self):
|
||||
'''
|
||||
"""
|
||||
Invoked before deleting an module from database.
|
||||
|
||||
Do whatever needed here, as deleting associated data if needed
|
||||
@ -274,5 +274,5 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
|
||||
Returns:
|
||||
Nothing
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
@ -27,12 +27,12 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
Provides useful functions for authenticating, used by web interface.
|
||||
|
||||
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from functools import wraps
|
||||
@ -65,9 +65,9 @@ ROOT_ID = -20091204 # Any negative number will do the trick
|
||||
|
||||
|
||||
def getUDSCookie(request, response=None, force=False):
|
||||
'''
|
||||
"""
|
||||
Generates a random cookie for uds, used, for example, to encript things
|
||||
'''
|
||||
"""
|
||||
if 'uds' not in request.COOKIES:
|
||||
import random
|
||||
import string
|
||||
@ -103,18 +103,18 @@ def getIp(request):
|
||||
|
||||
# Decorator to make easier protect pages that needs to be logged in
|
||||
def webLoginRequired(admin=False):
|
||||
'''
|
||||
"""
|
||||
Decorator to set protection to access page
|
||||
Look for samples at uds.core.web.views
|
||||
'''
|
||||
"""
|
||||
|
||||
def decorator(view_func):
|
||||
|
||||
@wraps(view_func, assigned=available_attrs(view_func))
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Wrapped function for decorator
|
||||
'''
|
||||
"""
|
||||
if request.user is None:
|
||||
url = request.build_absolute_uri(GlobalConfig.LOGIN_URL.get())
|
||||
if GlobalConfig.REDIRECT_TO_HTTPS.getBool() is True:
|
||||
@ -135,16 +135,16 @@ def webLoginRequired(admin=False):
|
||||
|
||||
# Decorator to protect pages that needs to be accessed from "trusted sites"
|
||||
def trustedSourceRequired(view_func):
|
||||
'''
|
||||
"""
|
||||
Decorator to set protection to access page
|
||||
look for sample at uds.dispatchers.pam
|
||||
'''
|
||||
"""
|
||||
|
||||
@wraps(view_func)
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Wrapped function for decorator
|
||||
'''
|
||||
"""
|
||||
from uds.core.util import net
|
||||
if net.ipInNetwork(request.ip, GlobalConfig.TRUSTED_SOURCES.get(True)) is False:
|
||||
return HttpResponseForbidden()
|
||||
@ -154,11 +154,11 @@ def trustedSourceRequired(view_func):
|
||||
|
||||
|
||||
def __registerUser(authenticator, authInstance, username):
|
||||
'''
|
||||
"""
|
||||
Check if this user already exists on database with this authenticator, if don't, create it with defaults
|
||||
This will work correctly with both internal or externals cause we first authenticate the user, if internal and user do not exists in database
|
||||
authenticate will return false, if external and return true, will create a reference in database
|
||||
'''
|
||||
"""
|
||||
from uds.core.util.request import getRequest
|
||||
|
||||
username = authInstance.transformUsername(username)
|
||||
@ -179,7 +179,7 @@ def __registerUser(authenticator, authInstance, username):
|
||||
|
||||
|
||||
def authenticate(username, password, authenticator, useInternalAuthenticate=False):
|
||||
'''
|
||||
"""
|
||||
Given an username, password and authenticator, try to authenticate user
|
||||
@param username: username to authenticate
|
||||
@param password: password to authenticate this user
|
||||
@ -187,7 +187,7 @@ def authenticate(username, password, authenticator, useInternalAuthenticate=Fals
|
||||
@param useInternalAuthenticate: If True, tries to authenticate user using "internalAuthenticate". If false, it uses "authenticate".
|
||||
This is so because in some situations we may want to use a "trusted" method (internalAuthenticate is never invoked directly from web)
|
||||
@return: None if authentication fails, User object (database object) if authentication is o.k.
|
||||
'''
|
||||
"""
|
||||
logger.debug('Authenticating user {0} with authenticator {1}'.format(username, authenticator))
|
||||
|
||||
# If global root auth is enabled && user/password is correct,
|
||||
@ -214,7 +214,7 @@ def authenticate(username, password, authenticator, useInternalAuthenticate=Fals
|
||||
|
||||
|
||||
def authenticateViaCallback(authenticator, params):
|
||||
'''
|
||||
"""
|
||||
Given an username, this method will get invoked whenever the url for a callback
|
||||
for an authenticator is requested.
|
||||
|
||||
@ -231,7 +231,7 @@ def authenticateViaCallback(authenticator, params):
|
||||
* Update user group membership using Authenticator getGroups, so, in your
|
||||
callbacks, remember to store (using provided environment storage, for example)
|
||||
the groups of this user so your getGroups will work correctly.
|
||||
'''
|
||||
"""
|
||||
gm = auths.GroupsManager(authenticator)
|
||||
authInstance = authenticator.getInstance()
|
||||
|
||||
@ -248,16 +248,16 @@ def authenticateViaCallback(authenticator, params):
|
||||
|
||||
|
||||
def authCallbackUrl(authenticator):
|
||||
'''
|
||||
"""
|
||||
Helper method, so we can get the auth call back url for an authenticator
|
||||
'''
|
||||
"""
|
||||
return reverse('uds.web.views.authCallback', kwargs={'authName': authenticator.name})
|
||||
|
||||
|
||||
def authInfoUrl(authenticator):
|
||||
'''
|
||||
"""
|
||||
Helper method, so we can get the info url for an authenticator
|
||||
'''
|
||||
"""
|
||||
if isinstance(authenticator, (six.text_type, six.binary_type)):
|
||||
name = authenticator
|
||||
else:
|
||||
@ -267,10 +267,10 @@ def authInfoUrl(authenticator):
|
||||
|
||||
|
||||
def webLogin(request, response, user, password):
|
||||
'''
|
||||
"""
|
||||
Helper function to, once the user is authenticated, store the information at the user session.
|
||||
@return: Always returns True
|
||||
'''
|
||||
"""
|
||||
from uds import REST
|
||||
|
||||
if user.id != ROOT_ID: # If not ROOT user (this user is not inside any authenticator)
|
||||
@ -291,21 +291,21 @@ def webLogin(request, response, user, password):
|
||||
|
||||
|
||||
def webPassword(request):
|
||||
'''
|
||||
"""
|
||||
The password is stored at session using a simple scramble algorithm that keeps the password splited at
|
||||
session (db) and client browser cookies. This method uses this two values to recompose the user password
|
||||
so we can provide it to remote sessions.
|
||||
@param request: DJango Request
|
||||
@return: Unscrambled user password
|
||||
'''
|
||||
"""
|
||||
return CryptoManager.manager().xor(request.session.get(PASS_KEY, ''), getUDSCookie(request)).decode('utf-8') # recover as original unicode string
|
||||
|
||||
|
||||
def webLogout(request, exit_url=None):
|
||||
'''
|
||||
"""
|
||||
Helper function to clear user related data from session. If this method is not used, the session we be cleaned anyway
|
||||
by django in regular basis.
|
||||
'''
|
||||
"""
|
||||
# Invoke exit for authenticator
|
||||
|
||||
if request.user is not None and request.user.id != ROOT_ID:
|
||||
@ -322,9 +322,9 @@ def webLogout(request, exit_url=None):
|
||||
|
||||
|
||||
def authLogLogin(request, authenticator, userName, logStr=''):
|
||||
'''
|
||||
"""
|
||||
Logs authentication
|
||||
'''
|
||||
"""
|
||||
if logStr == '':
|
||||
logStr = 'Logged in'
|
||||
|
||||
|
@ -107,7 +107,7 @@ class DelayedTaskRunner(object):
|
||||
with transaction.atomic(): # Encloses
|
||||
task = dbDelayedTask.objects.select_for_update().filter(filt).order_by('execution_time')[0] # @UndefinedVariable
|
||||
if task.insert_date > now + timedelta(seconds=30):
|
||||
logger.warn('EXecuted {} due to insert_date being in the future!'.format(task.type))
|
||||
logger.warning('EXecuted {} due to insert_date being in the future!'.format(task.type))
|
||||
taskInstanceDump = encoders.decode(task.instance, 'base64')
|
||||
task.delete()
|
||||
taskInstance = loads(taskInstanceDump)
|
||||
|
@ -64,7 +64,7 @@ class JobThread(threading.Thread):
|
||||
try:
|
||||
self._jobInstance.execute()
|
||||
except Exception:
|
||||
logger.warn("Exception executing job {0}".format(self._dbJobId))
|
||||
logger.warning("Exception executing job {0}".format(self._dbJobId))
|
||||
finally:
|
||||
self.jobDone()
|
||||
|
||||
@ -144,7 +144,7 @@ class Scheduler(object):
|
||||
# This params are all set inside fltr (look at __init__)
|
||||
job = dbScheduler.objects.select_for_update().filter(fltr).order_by('next_execution')[0] # @UndefinedVariable
|
||||
if job.last_execution > now:
|
||||
logger.warn('EXecuted {} due to last_execution being in the future!'.format(job.name))
|
||||
logger.warning('EXecuted {} due to last_execution being in the future!'.format(job.name))
|
||||
job.state = State.RUNNING
|
||||
job.owner_server = self._hostname
|
||||
job.last_execution = now
|
||||
|
@ -103,9 +103,10 @@ class Report(UserInterface):
|
||||
return dict(string=image,
|
||||
mime_type='image/png')
|
||||
elif url.startswith('image://'):
|
||||
img = '' # Empty image
|
||||
if isinstance(images, dict):
|
||||
img = images.get(url[8:], None)
|
||||
logger.debug('Getting image {}? {}'.format(url[8:], img != None))
|
||||
logger.debug('Getting image {}? {}'.format(url[8:], img is not None))
|
||||
return dict(string=img,
|
||||
mime_type='image/png')
|
||||
else:
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
@ -49,13 +49,13 @@ TUNNELED_GROUP = _('Tunneled')
|
||||
|
||||
|
||||
class Transport(Module):
|
||||
'''
|
||||
"""
|
||||
An OS Manager is responsible for communication the service the different actions to take (i.e. adding a windows machine to a domain)
|
||||
The Service (i.e. virtual machine) communicates with the OSManager via a published web method, that must include the unique ID.
|
||||
In order to make easier to agents identify themselfs, the Unique ID can be a list with various Ids (i.e. the macs of the virtual machine).
|
||||
Server will iterate thought them and look for an identifier associated with the service. This list is a comma separated values (i.e. AA:BB:CC:DD:EE:FF,00:11:22:...)
|
||||
Remember also that we inherit the test and check methods from BaseModule
|
||||
'''
|
||||
"""
|
||||
# Transport informational related data, inherited from BaseModule
|
||||
typeName = 'Base Transport Manager'
|
||||
typeType = 'Base Transport'
|
||||
@ -85,7 +85,7 @@ class Transport(Module):
|
||||
self.initialize(values)
|
||||
|
||||
def initialize(self, values):
|
||||
'''
|
||||
"""
|
||||
This method will be invoked from __init__ constructor.
|
||||
This is provided so you don't have to provide your own __init__ method,
|
||||
and invoke base methods.
|
||||
@ -98,13 +98,13 @@ class Transport(Module):
|
||||
be called after this.
|
||||
|
||||
Default implementation does nothing
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def destroy(self):
|
||||
'''
|
||||
"""
|
||||
Invoked when Transport is deleted
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def testServer(self, userService, ip, port, timeout=4):
|
||||
@ -114,17 +114,17 @@ class Transport(Module):
|
||||
return connection.testServer(ip, six.text_type(port), timeout)
|
||||
|
||||
def isAvailableFor(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Checks if the transport is available for the requested destination ip
|
||||
Override this in yours transports
|
||||
'''
|
||||
"""
|
||||
return False
|
||||
|
||||
def getCustomAvailableErrorMsg(self, userService, ip):
|
||||
'''
|
||||
"""
|
||||
Returns a customized error message, that will be used when a service fails to check "isAvailableFor"
|
||||
Override this in yours transports if needed
|
||||
'''
|
||||
"""
|
||||
return "Not accessible (using service ip {0})".format(ip)
|
||||
|
||||
@classmethod
|
||||
@ -138,22 +138,22 @@ class Transport(Module):
|
||||
|
||||
@classmethod
|
||||
def supportsOs(cls, osName):
|
||||
'''
|
||||
"""
|
||||
Helper method to check if transport supports requested operating system.
|
||||
Class method
|
||||
'''
|
||||
"""
|
||||
logger.debug('Checking suported os {0} against {1}'.format(osName, cls.supportedOss))
|
||||
return cls.supportedOss.count(osName) > 0
|
||||
|
||||
@classmethod
|
||||
def providesConnetionInfo(cls):
|
||||
'''
|
||||
"""
|
||||
Helper method to check if transport provides information about connection
|
||||
'''
|
||||
"""
|
||||
return cls.getConnectionInfo != Transport.getConnectionInfo
|
||||
|
||||
def getConnectionInfo(self, service, user, password):
|
||||
'''
|
||||
"""
|
||||
This method must provide information about connection.
|
||||
We don't have to implement it, but if we wont to allow some types of connections
|
||||
(such as Client applications, some kinds of TC, etc... we must provide it or those
|
||||
@ -174,22 +174,22 @@ class Transport(Module):
|
||||
I have implemented processUserPassword in both so in most cases we do not need if the service is
|
||||
DeployedService or UserService. In case of processUserPassword for an DeployedService, no transformation
|
||||
is done, because there is no relation at that level between user and service.
|
||||
'''
|
||||
"""
|
||||
return {'protocol': self.protocol, 'username': '', 'password': '', 'domain': ''}
|
||||
|
||||
def processedUser(self, userService, user):
|
||||
'''
|
||||
"""
|
||||
Used to "transform" username that will be sent to service
|
||||
This is used to make the "user" that will receive the service match with that sent in notification
|
||||
@return: transformed username
|
||||
'''
|
||||
"""
|
||||
return user.name
|
||||
|
||||
def getUDSTransportScript(self, userService, transport, ip, os, user, password, request):
|
||||
'''
|
||||
"""
|
||||
If this is an uds transport, this will return the tranport script needed for executing
|
||||
this on client
|
||||
'''
|
||||
"""
|
||||
return "raise Exception('The transport {transport} is not supported on your platform.'.format(transport=params['transport']))", \
|
||||
'EH/91J7u9+/sHtB5+EUVRDW1+jqF0LuZzfRi8qxyIuSdJuWt'\
|
||||
'8V8Yngu24p0NNr13TaxPQ1rpGN8x0NsU/Ma8k4GGohc+zxdf'\
|
||||
@ -216,10 +216,10 @@ class Transport(Module):
|
||||
return encoders.encode(encoders.encode(script, 'bz2'), 'base64', asText=True).replace('\n', ''), signature, params
|
||||
|
||||
def getLink(self, userService, transport, ip, os, user, password, request):
|
||||
'''
|
||||
"""
|
||||
Must override if transport does provides its own link
|
||||
If transport provides own link, this method provides the link itself
|
||||
'''
|
||||
"""
|
||||
return None
|
||||
|
||||
def __str__(self):
|
||||
|
@ -781,7 +781,7 @@ class UserInterfaceType(type):
|
||||
better place
|
||||
"""
|
||||
|
||||
def __new__(self, classname, bases, classDict):
|
||||
def __new__(mcs, classname, bases, classDict):
|
||||
newClassDict = {}
|
||||
_gui = {}
|
||||
# We will keep a reference to gui elements also at _gui so we can access them easily
|
||||
@ -790,11 +790,11 @@ class UserInterfaceType(type):
|
||||
_gui[attrName] = attr
|
||||
newClassDict[attrName] = attr
|
||||
newClassDict['_gui'] = _gui
|
||||
return type.__new__(self, classname, bases, newClassDict)
|
||||
return type.__new__(mcs, classname, bases, newClassDict)
|
||||
|
||||
|
||||
@six.add_metaclass(UserInterfaceType)
|
||||
class UserInterface(object):
|
||||
#@six.add_metaclass(UserInterfaceType)
|
||||
class UserInterface(object, metaclass=UserInterfaceType):
|
||||
'''
|
||||
This class provides the management for gui descriptions (user forms)
|
||||
|
||||
@ -821,7 +821,7 @@ class UserInterface(object):
|
||||
if k in values:
|
||||
v.value = values[k]
|
||||
else:
|
||||
logger.warn('Field {} not found'.format(k))
|
||||
logger.warning('Field {} not found'.format(k))
|
||||
|
||||
def initGui(self):
|
||||
'''
|
||||
|
File diff suppressed because one or more lines are too long
@ -63,6 +63,7 @@ class Attribute(object):
|
||||
self._value = self._type(value)
|
||||
|
||||
|
||||
# noinspection PyMissingConstructor
|
||||
class AutoAttributes(Serializable):
|
||||
'''
|
||||
Easy creation of attributes to marshal & unmarshal at modules
|
||||
@ -94,7 +95,7 @@ class AutoAttributes(Serializable):
|
||||
self.dict = d
|
||||
|
||||
def marshal(self):
|
||||
return encoders.encode('\2'.join(['%s\1%s' % (k, pickle.dumps(v)) for k, v in self.dict.iteritems()]), 'bz2')
|
||||
return encoders.encode('\2'.join(['%s\1%s' % (k, pickle.dumps(v)) for k, v in self.dict.items()]), 'bz2')
|
||||
|
||||
def unmarshal(self, data):
|
||||
if data == b'': # Can be empty
|
||||
|
@ -113,7 +113,6 @@ class CalendarChecker(object):
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def _updateEvents(self, checkFrom, startEvent=True):
|
||||
|
||||
next_event = None
|
||||
@ -142,7 +141,8 @@ class CalendarChecker(object):
|
||||
dtime = getSqlDatetime()
|
||||
|
||||
# First, try to get data from cache if it is valid
|
||||
cacheKey = six.text_type(hash(self.calendar.modified)) + six.text_type(dtime.date().toordinal()) + self.calendar.uuid + 'checker'
|
||||
cacheKey = six.text_type(hash(self.calendar.modified)) + six.text_type(
|
||||
dtime.date().toordinal()) + self.calendar.uuid + 'checker'
|
||||
cached = CalendarChecker.cache.get(cacheKey, None)
|
||||
|
||||
if cached is not None:
|
||||
@ -170,11 +170,14 @@ class CalendarChecker(object):
|
||||
if offset is None:
|
||||
offset = datetime.timedelta(minutes=0)
|
||||
|
||||
cacheKey = six.text_type(hash(self.calendar.modified)) + self.calendar.uuid + six.text_type(offset.seconds) + six.text_type(int(time.mktime(checkFrom.timetuple()))) + 'event' + ('x' if startEvent is True else '_')
|
||||
cacheKey = six.text_type(hash(self.calendar.modified)) + self.calendar.uuid + six.text_type(
|
||||
offset.seconds) + six.text_type(int(time.mktime(checkFrom.timetuple()))) + 'event' + (
|
||||
'x' if startEvent is True else '_')
|
||||
next_event = CalendarChecker.cache.get(cacheKey, None)
|
||||
if next_event is None:
|
||||
logger.debug('Regenerating cached nextEvent')
|
||||
next_event = self._updateEvents(checkFrom + offset, startEvent) # We substract on checkin, so we can take into account for next execution the "offset" on start & end (just the inverse of current, so we substract it)
|
||||
next_event = self._updateEvents(checkFrom + offset,
|
||||
startEvent) # We substract on checkin, so we can take into account for next execution the "offset" on start & end (just the inverse of current, so we substract it)
|
||||
if next_event is not None:
|
||||
next_event += offset
|
||||
CalendarChecker.cache.put(cacheKey, next_event, 3600)
|
||||
|
@ -80,7 +80,7 @@ def deprecated(func):
|
||||
def new_func(*args, **kwargs):
|
||||
try:
|
||||
caller = inspect.stack()[1]
|
||||
logger.warn(
|
||||
logger.warning(
|
||||
"Call to deprecated function {0} from {1}:{2}.".format(func.__name__,
|
||||
caller[1], caller[2]
|
||||
)
|
||||
|
@ -71,6 +71,7 @@ def connection(username, password, host, port=-1, ssl=False, timeout=3, debug=Fa
|
||||
@raise exception: If connection could not be established
|
||||
"""
|
||||
logger.debug('Login in to {} as user {}'.format(host, username))
|
||||
l = None
|
||||
if isinstance(password, six.text_type):
|
||||
password = password.encode('utf-8')
|
||||
try:
|
||||
@ -111,9 +112,11 @@ def getAsDict(con, base, ldapFilter, attrList, sizeLimit, scope=ldap.SCOPE_SUBTR
|
||||
if attrList is not None:
|
||||
attrList = [tools.b2(i) for i in attrList]
|
||||
|
||||
res = None
|
||||
try:
|
||||
# On python2, attrs and search string is str (not unicode), in 3, str (not bytes)
|
||||
res = con.search_ext_s(base,
|
||||
res = con.search_ext_s(
|
||||
base,
|
||||
scope=scope,
|
||||
filterstr=tools.b2(ldapFilter),
|
||||
attrlist=attrList,
|
||||
|
@ -49,6 +49,7 @@ class XUACompatibleMiddleware(object):
|
||||
response['X-UA-Compatible'] = 'IE=edge'
|
||||
return response
|
||||
|
||||
|
||||
class RedirectMiddleware(object):
|
||||
NO_REDIRECT = [
|
||||
'rest',
|
||||
|
@ -35,7 +35,6 @@ from __future__ import unicode_literals
|
||||
import os.path
|
||||
import pkgutil
|
||||
import sys
|
||||
import imp
|
||||
import logging
|
||||
import uds.dispatchers # @UnusedImport
|
||||
|
||||
|
@ -99,7 +99,9 @@ class CaseInsensitiveDict(dict):
|
||||
def setdefault(self, key, *args, **kwargs):
|
||||
return super(CaseInsensitiveDict, self).setdefault(self.__class__._k(key), *args, **kwargs)
|
||||
|
||||
def update(self, E={}, **F):
|
||||
def update(self, E=None, **F):
|
||||
if E is None:
|
||||
E = {}
|
||||
super(CaseInsensitiveDict, self).update(self.__class__(E))
|
||||
super(CaseInsensitiveDict, self).update(self.__class__(**F))
|
||||
|
||||
|
@ -99,7 +99,6 @@ def unmarshalTRDP(str_):
|
||||
}
|
||||
|
||||
|
||||
|
||||
def transformTransports(apps, schema_editor):
|
||||
"""
|
||||
Move serialization to a better model (it's time, the mode is there since 1.1 :) )
|
||||
|
@ -116,7 +116,7 @@ class CalendarRule(UUIDModel):
|
||||
if self.interval == 0: # Fix 0 intervals
|
||||
self.interval = 1
|
||||
|
||||
end = datetime.datetime.combine(self.end if self.end is not None else datetime.datetime.max.date(), datetime.datetime.max.time());
|
||||
end = datetime.datetime.combine(self.end if self.end is not None else datetime.datetime.max.date(), datetime.datetime.max.time())
|
||||
|
||||
if self.frequency == WEEKDAYS:
|
||||
dw = []
|
||||
@ -133,7 +133,7 @@ class CalendarRule(UUIDModel):
|
||||
if self.interval == 0: # Fix 0 intervals
|
||||
self.interval = 1
|
||||
|
||||
end = datetime.datetime.combine(self.end if self.end is not None else datetime.datetime.max.date(), datetime.datetime.max.time());
|
||||
end = datetime.datetime.combine(self.end if self.end is not None else datetime.datetime.max.date(), datetime.datetime.max.time())
|
||||
|
||||
if self.frequency == WEEKDAYS:
|
||||
dw = []
|
||||
|
@ -165,7 +165,7 @@ class WinDomainOsManager(WindowsOsManager):
|
||||
error = None
|
||||
break
|
||||
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
|
||||
logger.warn('Could not find _ldap._tcp.' + self._domain)
|
||||
logger.warning('Could not find _ldap._tcp.' + self._domain)
|
||||
log.doLog(userService, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER)
|
||||
except ldap.ALREADY_EXISTS:
|
||||
# Already added this machine to this group, pass
|
||||
@ -195,7 +195,7 @@ class WinDomainOsManager(WindowsOsManager):
|
||||
try:
|
||||
l = self.__connectLdap()
|
||||
except dns.resolver.NXDOMAIN: # No domain found, log it and pass
|
||||
logger.warn('Could not find _ldap._tcp.' + self._domain)
|
||||
logger.warning('Could not find _ldap._tcp.' + self._domain)
|
||||
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER)
|
||||
return
|
||||
except ldaputil.LDAPError:
|
||||
|
@ -49,4 +49,5 @@ def __init__():
|
||||
for _, name, _ in pkgutil.iter_modules([pkgpath]):
|
||||
__import__(name, globals(), locals(), [], 1)
|
||||
|
||||
|
||||
__init__()
|
||||
|
@ -99,6 +99,7 @@ class CountersPoolAssigned(StatsReport):
|
||||
|
||||
data = []
|
||||
|
||||
pool = None
|
||||
for poolUuid in self.pools.value:
|
||||
try:
|
||||
pool = ServicePool.objects.get(uuid=poolUuid)
|
||||
|
@ -76,7 +76,7 @@ class OVirtDeferredRemoval(jobs.Job):
|
||||
logger.info('Machine {} could not be removed right now, queued for later: {}'.format(vmId, e))
|
||||
|
||||
except Exception as e:
|
||||
logger.warn('Exception got queuing for Removal: {}'.format(e))
|
||||
logger.warning('Exception got queuing for Removal: {}'.format(e))
|
||||
|
||||
def run(self):
|
||||
from .OVirtProvider import Provider as OVirtProvider
|
||||
|
@ -41,14 +41,15 @@ from . import template
|
||||
from . import vm
|
||||
# Import submodules
|
||||
from .common import *
|
||||
import types
|
||||
|
||||
__updated__ = '2017-03-28'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
module = sys.modules[__name__]
|
||||
VmState = imp.new_module('VmState')
|
||||
ImageState = imp.new_module('ImageState')
|
||||
VmState = types.ModuleType('VmState')
|
||||
ImageState = types.ModuleType('ImageState')
|
||||
|
||||
for i in enumerate(['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED', 'POWEROFF', 'UNDEPLOYED']):
|
||||
setattr(VmState, i[1], i[0])
|
||||
|
@ -32,7 +32,7 @@
|
||||
"""
|
||||
|
||||
import sys
|
||||
import imp
|
||||
import types
|
||||
import re
|
||||
|
||||
import logging
|
||||
@ -42,7 +42,7 @@ __updated__ = '2016-02-09'
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
module = sys.modules[__name__]
|
||||
VmState = imp.new_module('VmState')
|
||||
VmState = types.ModuleType('VmState')
|
||||
|
||||
for i in enumerate(['INIT', 'PENDING', 'HOLD', 'ACTIVE', 'STOPPED', 'SUSPENDED', 'DONE', 'FAILED', 'POWEROFF', 'UNDEPLOYED', 'UNKNOWN']):
|
||||
setattr(VmState, i[1], i[0])
|
||||
|
@ -27,9 +27,9 @@
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
'''
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
from django.utils.translation import ugettext_noop as _, ugettext
|
||||
from uds.core.transports import protocols
|
||||
from uds.core.services import Service, types as serviceTypes
|
||||
@ -48,9 +48,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LiveService(Service):
|
||||
'''
|
||||
"""
|
||||
OpenStack Live Service
|
||||
'''
|
||||
"""
|
||||
# : Name to show the administrator. This string will be translated BEFORE
|
||||
# : sending it to administration interface, so don't forget to
|
||||
# : mark it as _ (using ugettext_noop)
|
||||
@ -144,12 +144,12 @@ class LiveService(Service):
|
||||
ev = gui.HiddenField(value=None) # We need to keep the env so we can instantiate the Provider
|
||||
|
||||
def initialize(self, values):
|
||||
'''
|
||||
"""
|
||||
We check here form values to see if they are valid.
|
||||
|
||||
Note that we check them through FROM variables, that already has been
|
||||
initialized by __init__ method of base class, before invoking this.
|
||||
'''
|
||||
"""
|
||||
if values is not None:
|
||||
length = int(self.lenName.value)
|
||||
if len(self.baseName.value) + length > 15:
|
||||
@ -163,9 +163,9 @@ class LiveService(Service):
|
||||
self._api = None
|
||||
|
||||
def initGui(self):
|
||||
'''
|
||||
"""
|
||||
Loads required values inside
|
||||
'''
|
||||
"""
|
||||
api = self.parent().api()
|
||||
regions = [gui.choiceItem(r['id'], r['id']) for r in api.listRegions()]
|
||||
self.region.setValues(regions)
|
||||
@ -198,13 +198,13 @@ class LiveService(Service):
|
||||
return self.api.createVolumeSnapshot(self.volume.value, templateName, description)
|
||||
|
||||
def getTemplate(self, snapshotId):
|
||||
'''
|
||||
"""
|
||||
Checks current state of a template (an snapshot)
|
||||
'''
|
||||
"""
|
||||
return self.api.getSnapshot(snapshotId)
|
||||
|
||||
def deployFromTemplate(self, name, snapshotId):
|
||||
'''
|
||||
"""
|
||||
Deploys a virtual machine on selected cluster from selected template
|
||||
|
||||
Args:
|
||||
@ -214,7 +214,7 @@ class LiveService(Service):
|
||||
|
||||
Returns:
|
||||
Id of the machine being created form template
|
||||
'''
|
||||
"""
|
||||
logger.debug('Deploying from template {0} machine {1}'.format(snapshotId, name))
|
||||
# self.datastoreHasSpace()
|
||||
return self.api.createServerFromSnapshot(snapshotId=snapshotId,
|
||||
@ -225,13 +225,13 @@ class LiveService(Service):
|
||||
securityGroupsIdsList=self.securityGroups.value)['id']
|
||||
|
||||
def removeTemplate(self, templateId):
|
||||
'''
|
||||
"""
|
||||
invokes removeTemplate from parent provider
|
||||
'''
|
||||
"""
|
||||
self.api.deleteSnapshot(templateId)
|
||||
|
||||
def getMachineState(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Invokes getServer from openstack client
|
||||
|
||||
Args:
|
||||
@ -256,11 +256,11 @@ class LiveService(Service):
|
||||
STOPPED. The server is powered off and the disk image still persists.
|
||||
SUSPENDED. The server is suspended, either by request or necessity. This status appears for only the XenServer/XCP, KVM, and ESXi hypervisors. Administrative users can suspend an instance if it is infrequently used or to perform system maintenance. When you suspend an instance, its VM state is stored on disk, all memory is written to disk, and the virtual machine is stopped. Suspending an instance is similar to placing a device in hibernation; memory and vCPUs become available to create other instances.
|
||||
VERIFY_RESIZE. System is awaiting confirmation that the server is operational after a move or resize.
|
||||
'''
|
||||
"""
|
||||
return self.api.getServer(machineId)['status']
|
||||
|
||||
def startMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenStack.
|
||||
|
||||
This start also "resume" suspended/paused machines
|
||||
@ -269,80 +269,80 @@ class LiveService(Service):
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
self.api.startServer(machineId)
|
||||
|
||||
def stopMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to stop a machine. No check is done, it is simply requested to OpenStack
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
self.api.stopServer(machineId)
|
||||
|
||||
def resetMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to stop a machine. No check is done, it is simply requested to OpenStack
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
self.api.resetServer(machineId)
|
||||
|
||||
def suspendMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to suspend a machine. No check is done, it is simply requested to OpenStack
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
self.api.suspendServer(machineId)
|
||||
|
||||
def resumeMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to start a machine. No check is done, it is simply requested to OpenStack
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
self.api.resumeServer(machineId)
|
||||
|
||||
def removeMachine(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Tries to delete a machine. No check is done, it is simply requested to OpenStack
|
||||
|
||||
Args:
|
||||
machineId: Id of the machine
|
||||
|
||||
Returns:
|
||||
'''
|
||||
"""
|
||||
self.api.deleteServer(machineId)
|
||||
|
||||
def getNetInfo(self, machineId):
|
||||
'''
|
||||
"""
|
||||
Gets the mac address of first nic of the machine
|
||||
'''
|
||||
"""
|
||||
net = self.api.getServer(machineId)['addresses']
|
||||
vals = six.next(six.itervalues(net))[0] # Returns "any" mac address of any interface. We just need only one interface info
|
||||
return (vals['OS-EXT-IPS-MAC:mac_addr'].upper(), vals['addr'])
|
||||
|
||||
def getBaseName(self):
|
||||
'''
|
||||
"""
|
||||
Returns the base name
|
||||
'''
|
||||
"""
|
||||
return self.baseName.value
|
||||
|
||||
def getLenName(self):
|
||||
'''
|
||||
"""
|
||||
Returns the length of numbers part
|
||||
'''
|
||||
"""
|
||||
return int(self.lenName.value)
|
||||
|
@ -396,13 +396,14 @@ class XenServer(object):
|
||||
logger.debug('Removing machine')
|
||||
vdisToDelete = []
|
||||
for vdb in self.VM.get_VBDs(vmId):
|
||||
vdi = None
|
||||
try:
|
||||
vdi = self.VBD.get_VDI(vdb)
|
||||
if vdi == 'OpaqueRef:NULL':
|
||||
logger.debug('VDB without VDI')
|
||||
continue
|
||||
logger.debug('VDI: {0}'.format(vdi))
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception('Exception getting VDI from VDB')
|
||||
if self.VDI.get_read_only(vdi) is True:
|
||||
logger.debug('{0} is read only, skipping'.format(vdi))
|
||||
|
@ -58,4 +58,4 @@ def javascript_auths(authenticators):
|
||||
'priority': a.priority,
|
||||
'isCustom': theType.isCustom()
|
||||
})
|
||||
return mark_safe('<script type="text/javascript">\nvar authenticators = ' + json.dumps(res, indent=4) + ';\n</script>');
|
||||
return mark_safe('<script type="text/javascript">\nvar authenticators = ' + json.dumps(res, indent=4) + ';\n</script>')
|
||||
|
Loading…
Reference in New Issue
Block a user