Example #1
0
 def _backend_mac_delete(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     if verb is not None:
         try:
             params = web.input()
             backend_id = params.get('backend_id', None)
             mac_id = params.get('mac_id', None)
             if backend_id is not None and mac_id is not None:
                 backend = backends.backend_get({'_id': backend_id})
                 transport = get_xmlrpc_transport(backend['backend_url'],
                                                  backend['is_kerberos'])
                 s = Macs(transport)
                 mac = s.get(id=mac_id)
                 if mac is not None:
                     result = s.delete(id=mac_id)
                     result = self._prepare_output(result={
                         'backend_id': backend_id,
                         'entry_type': 'boolean',
                         'entry': True})
                     return result
         except KerberosError as e:
             (first, last) = e.message
             (message, error_no) = last
             result = self._prepare_output(result={'backend_id': backend_id,
                                                   'error': True,
                                                   'error_type': 'Kerberos',
                                                   'error_msg': message,
                                                   'error_no': error_no})
             return result
         result = self._prepare_output(result={'backend_id': backend_id,
                                               'entry_type': 'boolean',
                                               'entry': False})
         return result
Example #2
0
 def _backend_host_list(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     if verb is not None:
         try:
             params = web.input()
             backend_id = params.get('backend_id', None)
             if backend_id is not None:
                 backend = backends.backend_get({'_id': backend_id})
                 transport = get_xmlrpc_transport(backend['backend_url'],
                                                  backend['is_kerberos'])
                 s = Hosts(transport)
                 hostlist = s.list()
                 result = self._prepare_output(
                     result={'backend_id': backend_id,
                             'datalist': hostlist})
                 return result
         except KerberosError as e:
             (first, last) = e.message
             (message, error_no) = last
             result = self._prepare_output(result={'backend_id': backend_id,
                                                   'error': True,
                                                   'error_type': 'Kerberos',
                                                   'error_msg': message,
                                                   'error_no': error_no})
             return result
     result = self._prepare_output(result={'backend_id': backend_id,
                                           'datalist': []})
     return result
Example #3
0
 def _update(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     defaultclass = {}
     result = json.loads(web.data())
     defaultclass['_id'] = verb['request_data']['id']
     defaultclass['classname'] = result['result']['defclass']['classname']
     defaultclass['description'] = result[
         'result']['defclass']['description']
     self._defaultclasses.update(defclass=defaultclass)
     output_format = verb.get('request_output_format', None)
     if output_format.lower() == 'json':
         result = self._prepare_output(
             'json',
             verb['request_content_type'],
             verb['request_output_format'],
             {'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '%s?backend_id=%s'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #4
0
 def _delete(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     defclass_id = verb['request_data']['id']
     result = self._defaultclasses.delete(id=defclass_id)
     output_format = verb.get('request_output_format', None)
     if output_format.lower() == 'json':
         result = self._prepare_output(
             'json',
             verb['request_content_type'],
             verb['request_output_format'],
             {'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #5
0
 def _update(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     result = json.loads(web.data())
     rec = {}
     rec = result['result']['pxe']
     self._pxemethods.update(pxe=rec)
     output_format = verb.get('request_output_format')
     if output_format.lower() == 'json':
         result = self._prepare_output(
             'json',
             verb['request_content_type'],
             verb['request_output_format'],
             {'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #6
0
 def _create(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     result = json.loads(web.data())
     rec = result['result']['user']
     if 'is_admin' in rec:
         rec['is_admin'] = str(rec['is_admin'])
     else:
         rec['is_admin'] = '0'
     self._sysusers.add(user=rec)
     output_format = verb.get('request_output_format')
     if output_format.lower() == 'json':
         result = self._prepare_output(
             'json',
             verb['request_content_type'],
             verb['request_output_format'],
             {'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #7
0
 def _update_hardware(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     self._pxemethods.update_hardware()
     output_format = verb.get('request_output_format', None)
     if output_format.lower() == 'json':
         result = self._prepare_output('json',
                                       verb['request_content_type'],
                                       verb['request_output_format'],
                                       {'redirect':
                                        {'url': '%s?backend_id=%s' %
                                         (self._controller_path,
                                          backend_id),
                                         'absolute': 'true'}})
     else:
         result = self._prepare_output(verb['request_type'],
                                       verb['request_content_type'],
                                       output={'redirect':
                                               {'url': '%s?backend_id=%s' %
                                                (self._controller_path,
                                                 backend_id),
                                                'absolute': 'true'}})
     return result
Example #8
0
 def _backend_servers_stats(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     if verb is not None:
         try:
             params = web.input()
             backend_id = params.get('backend_id', None)
             if backend_id is not None:
                 backend = backends.backend_get({'_id': backend_id})
                 if backend is not None:
                     transport = get_xmlrpc_transport(
                         backend['backend_url'],
                         backend['is_kerberos'])
                     s = Servers(transport)
                     count_servers = s.count()
                     result = self._prepare_output(result={
                         'backend_id': backend_id,
                         'server_count': count_servers})
                     return result
         except KerberosError as e:
             (first, last) = e.message
             (message, error_no) = last
             result = self._prepare_output(result={
                 'backend_id': backend_id,
                 'error': True,
                 'error_type': 'Kerberos',
                 'error_msg': message,
                 'error_no': error_no})
             return result
         result = self._prepare_output(result={
             'backend_id': backend_id,
             'server_count': 0})
         return result
Example #9
0
 def _delete(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     request_data = verb.get('request_data', None)
     backend_id = params.get('backend_id')
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     if (request_data is not None and
             request_data.get('id', None) is not None):
         environment = {'_id': request_data.get('id', None)}
         self._environments.delete(environment=environment)
     output_format = verb.get('request_output_format', None)
     if output_format is not None and output_format.lower() == 'json':
         result = self._prepare_output(
             'json',
             verb['request_content_type'],
             verb['request_output_format'],
             {'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #10
0
 def _create(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     result = json.loads(web.data())
     classtemplate = {}
     classtemplate['name'] = result['result']['classtemplate']['name']
     classtemplate['description'] = result[
         'result']['classtemplate']['description']
     classtemplate['classes'] = result['result']['classtemplate']['classes']
     self._classtemplates.add(classtemplate=classtemplate)
     output_format = verb.get('request_output_format', None)
     if output_format.lower() == 'json':
         result = self._prepare_output('json',
                                       verb['request_content_type'],
                                       verb['request_output_format'],
                                       {'redirect':
                                        {'url':
                                         '{0}?backend_id={1}'.format(
                                             self._controller_path,
                                             backend_id),
                                         'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #11
0
 def _edit(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backend_list = backends.backend_list()
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     defaultclasses = self._defaultclasses.list()
     classtemplate = self._classtemplates.get(id=verb['request_data']['id'])
     if classtemplate['classes'] is not None:
         for classe in classtemplate['classes']:
             for k in xrange(len(defaultclasses)):
                 if defaultclasses[k]['classname'] == classe:
                     a = defaultclasses[k]
                     defaultclasses.remove(a)
                     break
     else:
         classtemplate['classes'] = []
     page.set_title('DC2 Admindcenter - Backends - Class Templates - Edit')
     page.add_page_data({
         'backendlist': backend_list,
         'backend_id': backend_id,
         'defaultclasses': defaultclasses,
         'tmpl': classtemplate,
     })
     page.set_action('edit')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #12
0
 def _backend_deployment_stats(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     if verb is not None:
         try:
             params = web.input()
             backend_id = params.get('backend_id', None)
             what = params.get('status', None)
             if backend_id is not None:
                 backend = backends.backend_get({'_id': backend_id})
                 if backend is not None:
                     transport = get_xmlrpc_transport(
                         backend['backend_url'],
                         backend['is_kerberos'])
                     s = InstallState(transport)
                     if what is not None and what == 'all':
                         count_deploy = s.count('deploy')
                         count_localboot = s.count('localboot')
                         result = self._prepare_output(result={
                             'backend_id': backend_id,
                             'status': 'all',
                             'count_localboot': count_localboot,
                             'count_deploy': count_deploy})
                     elif (what is not None and
                             what in ('deploy', 'localboot')):
                         count = s.count(what)
                         result = self._prepare_output(result={
                             'backend_id': backend_id,
                             'status': what,
                             'count': count})
                     return result
         except KerberosError as e:
             (first, last) = e.message
             (message, error_no) = last
             result = self._prepare_output(result={
                 'backend_id': backend_id,
                 'error': True,
                 'error_type': 'Kerberos',
                 'error_msg': message,
                 'error_no': error_no})
             return result
         if what is None:
             result = self._prepare_output(result={
                 'backend_id': backend_id,
                 'status': 'all',
                 'count_localboot': 0,
                 'count_deploy': 0})
         elif what is not None and what == 'all':
             result = self._prepare_output(result={
                 'backend_id': backend_id,
                 'status': 'all',
                 'count_localboot': 0,
                 'count_deploy': 0})
         elif what is not None and what in ('deploy', 'localboot'):
             result = self._prepare_output(result={
                 'backend_id': backend_id,
                 'status': what,
                 'count': 0})
         return result
Example #13
0
File: servers.py Project: sadig/DC2
 def _init_backend(self):
     params = web.input()
     self._backend_id = params.get('backend_id', None)
     self._page.add_page_data({'backend_id': self._backend_id})
     self._backend = backends.backend_get({'_id': self._backend_id})
     self._transport = get_xmlrpc_transport(
         self._backend['backend_url'],
         self._backend['is_kerberos'])
     self._servers = Servers(self._transport)
     self._macs = Macs(self._transport)
     self._ribs = Ribs(self._transport)
     self._hosts = Hosts(self._transport)
Example #14
0
 def _edit(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backend = backends.backend_get({'_id': verb['request_data']['id']})
     backendlist = backends.backend_list()
     page.set_title('DC2 Admincenter - Backends - Edit')
     page.set_action('edit')
     page.add_page_data({
         'backendlist': backendlist,
         'backend': convert_values(backend)})
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #15
0
 def _index(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     self._page.template_name = verb['template']
     self._page.set_action('index')
     params = web.input()
     backend_id = params.get('backend_id', None)
     if backend_id is not None:
         backend = backends.backend_get({'_id': backend_id})
         self._page.add_page_data({'backend_id': backend_id})
         self._page.set_title('Backend %s (Loc: %s)' %
                              (backend['title'], backend['location']))
         result = self._prepare_output(
             verb['request_type'], verb['request_content_type'],
             output={'content': self._page.render()})
         return result
Example #16
0
File: hosts.py Project: sadig/DC2
 def _init_backend(self):
     params = web.input()
     self._backend_id = params.get('backend_id', None)
     self._page.add_page_data({'backend_id': self._backend_id})
     self._backend = backends.backend_get({'_id': self._backend_id})
     self._transport = get_xmlrpc_transport(
         self._backend['backend_url'], self._backend['is_kerberos'])
     self._servers = Servers(self._transport)
     self._macs = Macs(self._transport)
     self._ribs = Ribs(self._transport)
     self._hosts = Hosts(self._transport)
     self._backend_settings = BackendSettings(self._transport)
     self._environments = Environments(self._transport)
     self._defaultclasses = DefaultClasses(self._transport)
     self._classtemplates = ClassTemplates(self._transport)
     self._itypes_list = interfacetypes.itype_list()
     self._inet_list = inettypes.inet_list()
Example #17
0
    def _freeipa_host_check(self, *args, **kwargs):
        verb = kwargs.get('verb', None)
        if verb is not None:
            params = web.input()
            backend_id = params.get('backend_id', None)
            host_id = params.get('host_id', None)
            web.debug('_freeipa_host_check: backendID: %s, host_id: %s' %
                      (backend_id, host_id))

            if backend_id is not None:
                backend = backends.backend_get({'_id': backend_id})
                if backend is not None:
                    try:
                        transport = get_xmlrpc_transport(
                            backend['backend_url'],
                            backend['is_kerberos'])
                        fhosts = FreeIPAHosts(transport)
                        hosts = Hosts(transport)
                        if host_id is not None:
                            h = hosts.get(id=host_id)
                            if h is not None:
                                result = fhosts.check(
                                    '{0}.{1}'.format(
                                        h['hostname'],
                                        h['domainname']))
                                if result is not None and result is not False:
                                    output = self._prepare_output(result={
                                        'backend_id': backend_id,
                                        'in_freeipa': True})
                                    return output
                    except KerberosError as e:
                        (first, last) = e.message
                        (message, error_no) = last
                        result = self._prepare_output(
                            result={'backend_id': backend_id,
                                    'error': True,
                                    'error_type': 'Kerberos',
                                    'error_msg': message,
                                    'error_no': error_no})
                        return result
            output = self._prepare_output(
                result={'backend_id': backend_id, 'in_freeipa': False})
            return output
Example #18
0
 def _index(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backend_list = backends.backend_list()
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     page.set_title('DC2 Admincenter - Backends - System Groups - Index')
     page.add_page_data({
         'backendlist': backend_list,
         'backend_id': backend_id,
         'backend_sysgroups': self._sysgroups.list()
     })
     page.set_action('index')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #19
0
 def _new(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backend_list = backends.backend_list()
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     user = self._sysusers.new()
     page.set_title('DC2 Admincenter - Backends - System Users - Add')
     page.add_page_data({
         'backendlist': backend_list,
         'backend_id': backend_id,
         'user': user
     })
     page.set_action('new')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #20
0
 def _edit(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backendlist = backends.backend_list()
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     defaultclass = self._defaultclasses.get(id=verb['request_data']['id'])
     page.set_title('DC2 Admincenter - Backends - Defaultclasses - Edit')
     page.add_page_data({
         'backendlist': backendlist,
         'backend_id': backend_id,
         'defclass': defaultclass
     })
     page.set_action('edit')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #21
0
 def _init_backend(self):
     params = web.input()
     self._backend_id = params.get('backend_id', None)
     self._page.add_page_data({'backend_id': self._backend_id})
     self._backend = backends.backend_get({'_id': self._backend_id})
     self._transport = get_xmlrpc_transport(
         self._backend['backend_url'], self._backend['is_kerberos'])
     self._installstate = InstallState(self._transport)
     self._backend_settings = BackendSettings(self._transport)
     self._hosts = Hosts(self._transport)
     self._freeipa = None
     backendsettings = self._backend_settings.get()
     if backendsettings['IS_FREEIPA_ENABLED']:
         try:
             from dc2.api.dc2.addons.freeipa import Hosts as FreeIPA_Hosts
         except ImportError as e:
             print('You did not install dc2.api')
             print(e)
             sys.exit(1)
         self._freeipa = FreeIPA_Hosts(self._transport)
Example #22
0
 def _new(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backendlist = backends.backend_list()
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     environment = self._environments.new()
     page.set_title('DC2 Admincenter - Backends - Environments - Add')
     page.add_page_data({
         'backendlist': backendlist,
         'backend': convert_values(backend),
         'backend_id': backend_id,
         'environment': environment
     })
     page.set_action('new')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #23
0
 def _edit(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backend_id = params.get('backend_id', None)
     backend_list = backends.backend_list()
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     pxe = self._pxemethods.get(id=verb['request_data']['id'])
     pxe_methods = pxemethods.pxe_list()
     page.set_title('DC2 Admincenter - Backends - PXE Bootmethods - Index')
     page.add_page_data({
         'backendlist': backend_list,
         'backend_id': backend_id,
         'pxe': pxe,
         'pxemethods': pxe_methods,
     })
     page.set_action('edit')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #24
0
 def _new(self, *args, **kwargs):
     params = web.input()
     verb = kwargs.get('verb', None)
     page = self._prepare_page(verb)
     backend_list = backends.backend_list()
     backend_id = params.get('backend_id', None)
     backend = backends.backend_get({'_id': backend_id})
     self._init_backend(backend)
     defaultclasses = self._defaultclasses.list()
     classtemplate = self._classtemplates.new()
     page.set_title('DC2 Admindcenter - Backends - Class Templates - Add')
     page.add_page_data({
         'backendlist': backend_list,
         'backend_id': backend_id,
         'defaultclasses': defaultclasses,
         'tmpl': classtemplate,
     })
     page.set_action('new')
     result = self._prepare_output(verb['request_type'],
                                   verb['request_content_type'],
                                   output={'content': page.render()})
     return result
Example #25
0
 def _update(self, *args, **kwargs):
     verb = kwargs.get('verb', None)
     params = web.input()
     raw_data = web.data()
     result = json.loads(raw_data)
     backend_id = params.get('backend_id')
     backend = backends.backend_get({'_id': backend_id})
     environment_id = verb['request_data']['id']
     self._init_backend(backend)
     environment = self._environments.get(id=environment_id)
     output_format = verb.get('request_output_format')
     environment['description'] = result[
         'result']['environment']['description']
     environment['variables'] = []
     if 'variables' in result['result']['environment']:
         for i in result['result']['environment']['variables'].keys():
             environment['variables'].append(
                 result['result']['environment']['variables'][i])
     self._environments.update(environment=environment)
     if output_format.lower() == 'json':
         result = self._prepare_output(
             'json',
             verb['request_content_type'],
             verb['request_output_format'],
             {'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     else:
         result = self._prepare_output(
             verb['request_type'],
             verb['request_content_type'],
             output={'redirect': {
                 'url': '{0}?backend_id={1}'.format(
                     self._controller_path,
                     backend_id),
                 'absolute': 'true'}})
     return result
Example #26
0
 def _init_backends(self, backend_id):
     backend = backends.backend_get({'_id':backend_id})
     transport = get_xmlrpc_transport(backend['backend_url'],
                                      backend['is_kerberos'])
     self._servers = Servers(transport)