Esempio n. 1
0
 def __init__(self, dhcp_server, group=None, host=None):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_options_class = 'dhcpOptions'
     self.dhcp_service_class = 'dhcpService'
     self.dhcp_option_attr = 'dhcpOption'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix',
                                             '-config')
     self.dhcp_server = dhcp_server
     self.service_name = self.dhcp_server + self.dhcp_conf_suffix
     self.dhcp_service = self._get_dhcp_service(self.dhcp_server)
     self.dhcp_service_dn = self.dhcp_service['data'][0].__getitem__(0)
     self.target_dn = self.dhcp_service_dn
     if group is not None:
         self.dhcp_group_name = group
         self.dhcp_group = self._get_dhcp_group(self.dhcp_server, \
                                                     self.dhcp_group_name)
         self.dhcp_group_dn = self.dhcp_group['data'][0].__getitem__(0)
         self.target_dn = self.dhcp_group_dn
     if host is not None:
         self.dhcp_host_name = host
         self.dhcp_host = self._get_dhcp_host(self.dhcp_server, \
                                 self.dhcp_group_name, self.dhcp_host_name)
         self.dhcp_host_dn = self.dhcp_host['data'][0].__getitem__(0)
         self.target_dn = self.dhcp_host_dn
Esempio n. 2
0
File: ca.py Progetto: mattmb/spoke
 def __init__(self, ca_name):    
     """Get config, setup logging."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.ca_name = common.is_shell_safe(ca_name)
     self.ca_base_dir = self.config.get('CA', 'ca_base_dir')
     self.ca_dir = os.path.join(self.ca_base_dir, self.ca_name) 
     self.ca_key_rdir = self.config.get('CA', 'ca_key_dir', 'private')
     self.ca_cert_rdir = self.config.get('CA', 'ca_cert_dir', 'certs')
     self.ca_req_rdir = self.config.get('CA', 'ca_req_dir', 'reqs')
     self.ca_cert_name = self.config.get('CA', 'ca_pub_cert', 'ca-cert.pem')
     self.ca_bundle_name = self.config.get('CA', 'ca_bundle', 'ca-bundle.pem')
     self.ca_req_name = self.config.get('CA', 'ca_req', 'ca-req.pem')
     self.ca_key_name = self.config.get('CA', 'ca_priv_key', 'ca-key.pem')
     self.ca_index_name = self.config.get('CA', 'ca_index', 'index')
     self.ca_serial_name = self.config.get('CA', 'ca_serial', 'serial')
     self.ca_cert_dir = os.path.join(self.ca_dir, self.ca_cert_rdir)
     self.ca_key_dir = os.path.join(self.ca_dir, self.ca_key_rdir)
     self.ca_req_dir = os.path.join(self.ca_dir, self.ca_req_rdir)
     self.ca_cert_file = os.path.join(self.ca_cert_dir, self.ca_cert_name)
     self.ca_bundle_file = os.path.join(self.ca_base_dir, 
                                        self.ca_bundle_name)
     
     self.ca_key_file = os.path.join(self.ca_key_dir, self.ca_key_name)
     self.ca_req_file = os.path.join(self.ca_req_dir, self.ca_req_name)
     self.ca_index_file = os.path.join(self.ca_cert_dir, self.ca_index_name)
     self.ca_serial_file = os.path.join(self.ca_dir, self.ca_serial_name)
         
     self.ca_key = os.path.join(self.ca_key_dir, self.ca_key_file)
     self.ca_cert = os.path.join(self.ca_cert_dir, self.ca_cert_file)
     self.req_dirs = [ self.ca_base_dir, self.ca_dir, self.ca_key_dir, 
                      self.ca_req_dir, self.ca_cert_dir ]
     self.req_files = [ self.ca_index_file, self.ca_serial_file,
                       self.ca_key_file, self.ca_cert_file ]
     try:
         ca_cert = X509.load_cert(self.ca_cert_file, format=1)
         self.ca_cn = ca_cert.get_subject().CN
         self.ca_cert_as_pem = ca_cert.as_pem()
     except:
         msg = 'CA cert file %s does not exist' % self.ca_cert_file
         self.log.debug(msg)      
     self.ca_country = self.config.get('CA', 'ca_country', 'GB')
     try:
         self.ca_state = self.config.get('CA', 'ca_state')
     except:
         self.ca_state = None
     self.ca_locality = self.config.get('CA', 'ca_locality', 'London')
     self.ca_org = self.config.get('CA', 'ca_org', 'Acme Ltd')
     self.ca_ou = self.config.get('CA', 'ca_ou', 'Certificate Services')
     self.ca_email = self.config.get('CA', 'ca_email', '*****@*****.**')
     self.ca_def_duration = self.config.get('CA', 'ca_def_duration', 1095)
     self.ca_keypass = self.config.get('CA', 'ca_keypass', '')
     # Try to get some more info from req/cert files if they are present
     self.ca_info = self._get_ca_info()
     try:
         self.ca_cn = self.ca_info['ca_cn']
     except:pass
     try:
         self.ca_cert_as_pem = self.ca_info['ca_cert_as_pem']
     except:pass
Esempio n. 3
0
File: dhcp.py Progetto: mattmb/spoke
 def __init__(self, dhcp_server, group=None, host=None):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_options_class = 'dhcpOptions'
     self.dhcp_service_class = 'dhcpService'
     self.dhcp_option_attr = 'dhcpOption'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config')
     self.dhcp_server = dhcp_server
     self.service_name = self.dhcp_server + self.dhcp_conf_suffix
     self.dhcp_service = self._get_dhcp_service(self.dhcp_server)
     self.dhcp_service_dn = self.dhcp_service['data'][0].__getitem__(0)
     self.target_dn = self.dhcp_service_dn
     if group is not None:
         self.dhcp_group_name = group
         self.dhcp_group = self._get_dhcp_group(self.dhcp_server, \
                                                     self.dhcp_group_name)
         self.dhcp_group_dn = self.dhcp_group['data'][0].__getitem__(0)
         self.target_dn = self.dhcp_group_dn
     if host is not None:
         self.dhcp_host_name = host
         self.dhcp_host = self._get_dhcp_host(self.dhcp_server, \
                                 self.dhcp_group_name, self.dhcp_host_name)
         self.dhcp_host_dn = self.dhcp_host['data'][0].__getitem__(0)
         self.target_dn = self.dhcp_host_dn
Esempio n. 4
0
 def __init__(self, org_name, user_id):
     """Get config, setup logging and LDAP connection."""   
     SpokeLDAP.__init__(self)     
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 0 #ldap.SCOPE_BASE
     self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o')
     self.org_def_children = self.config.get('ATTR_MAP', \
                             'org_def_children', 'people,groups,dns,hosts')
     self.org_children = self.org_def_children.split(',')
     self.user_login = self.config.get('ATTR_MAP', 'user_login', 'aenetAccountLoginName')
     self.user_id = user_id
     self.user = self._get_user(org_name, self.user_id)
     self.user_dn = self.user['data'][0].__getitem__(0)
     self.user_attrs = self.user['data'][0].__getitem__(1)
     self.user_classes = self.user_attrs['objectClass']
     self.imap_class = self.config.get('ATTR_MAP', 'imap_class', 'aenetCyrus')
     self.imap_enable = self.config.get('ATTR_MAP', 'imap_enable', 'aenetCyrusEnabled')
     self.imap_mailbox = self.config.get('ATTR_MAP', 'imap_mailbox', 'aenetCyrusMailboxName')
     self.imap_domain = self.config.get('ATTR_MAP', 'imap_domain', 'aenetCyrusMailboxDomain')
     self.imap_partition = self.config.get('ATTR_MAP', 'imap_partition', 'aenetCyrusMailboxPartition')
     self.imap_partition_def = self.config.get('ATTR_MAP', \
                                 'imap_partition_def', 'partition-default')
     self.smtp_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix')
     self.smtp_address = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept')
     self.smtp_destination = self.config.get('ATTR_MAP', \
                             'smtp_destination', 'aenetPostfixEmailDeliver')
     self.smtp_enable = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled')
     self.smtp_pri_address = self.config.get('ATTR_MAP', \
                             'smtp_pri_address', 'aenetPostfixEmailAddress')
Esempio n. 5
0
    def __init__(self, org_name, list_address):
        """Get config, setup logging and LDAP connection."""
        SpokeLDAP.__init__(self)
        self.config = config.setup()
        self.log = logger.setup(self.__module__)
        self.base_dn = self.config.get('LDAP', 'basedn')
        self.search_scope = 0  #ldap.SCOPE_BASE
        self.org_name = org_name
        self.list_address = self._validate_input(list_address)
        self.list_name, self.list_domain = self.list_address.split('@')
        self.list = self._get_list(self.org_name, self.list_address)
        self.list_dn = self.list['data'][0].__getitem__(0)
        self.list_attrs = self.list['data'][0].__getitem__(1)
        self.list_classes = self.list_attrs['objectClass']

        self.list_key = self.config.get('ATTR_MAP', 'user_key', 'uid')
        self.list_class = self.config.get('ATTR_MAP', 'smtp_class',
                                          'aenetPostfix')
        self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address',
                                                 'aenetPostfixEmailAccept')
        self.list_destination_attr = self.config.get('ATTR_MAP', \
                                'smtp_destination', 'aenetPostfixEmailDeliver')
        self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable',
                                                'aenetPostfixEnabled')
        self.list_pri_address_attr = self.config.get('ATTR_MAP', \
                                'smtp_pri_address', 'aenetPostfixEmailAddress')
        self.retrieve_attr = [self.list_destination_attr]
Esempio n. 6
0
File: host.py Progetto: mattmb/spoke
 def __init__(self, org_name):    
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou')
     self.host_container = self.config.get('HOST', 'host_container', 'hosts')
     self.host_container_dn = '%s=%s,%s' % (self.container_attr, \
                                         self.host_container, self.org_dn)
     self.host_class = self.config.get('HOST', 'host_class', 'aenetHost')
     self.host_key = self.config.get('HOST', 'host_key', 'cn')
     self.host_uuid_attr = self.config.get('HOST', 'host_uuid_attr', 'aenetHostUUID')
     self.host_name_attr = self.config.get('HOST', 'host_name_attr', 'aenetHostName')
     self.host_cpu_attr = self.config.get('HOST', 'host_cpu_attr', 'aenetHostCPU')
     self.host_mem_attr = self.config.get('HOST', 'host_mem_attr', 'aenetHostMem')
     self.host_extra_opts_attr = self.config.get('HOST', 
                             'host_extra_opts_attr', 'aenetHostExtraOpts')
     self.host_family_attr = self.config.get('HOST', 'host_family_attr', 'aenetHostFamily')
     self.host_network_layout_attr = self.config.get('HOST', 
                     'host_network_layout_attr', 'aenetHostNetworkLayout')
     self.host_storage_layout_attr = self.config.get('HOST', 
                     'host_storage_layout_attr', 'aenetHostStorageLayout')
     self.host_type_attr = self.config.get('HOST', 'host_type_attr', 'aenetHostType')
Esempio n. 7
0
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 2  #ldap.SCOPE_SUB
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr',
                                           'ou')
     self.list_container = self.config.get('ATTR_MAP', 'user_container',
                                           'people')
     self.list_key = self.config.get('ATTR_MAP', 'user_key', 'uid')
     self.list_class = self.config.get('ATTR_MAP', 'smtp_class',
                                       'aenetPostfix')
     self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address',
                                              'aenetPostfixEmailAccept')
     self.list_destination_attr = self.config.get('ATTR_MAP', \
                             'smtp_destination', 'aenetPostfixEmailDeliver')
     self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable',
                                             'aenetPostfixEnabled')
     self.list_pri_address_attr = self.config.get('ATTR_MAP', \
                             'smtp_pri_address', 'aenetPostfixEmailAddress')
     self.retrieve_attr = [self.list_address_attr]
Esempio n. 8
0
 def __init__(self):
     """Bind to LDAP directory, return an ldap object."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = ldap.SCOPE_SUBTREE #(2)
     self.server = self.config.get('LDAP', 'server')
     self.port = self.config.get('LDAP', 'port', '389')
     self.bind_dn = self.config.get('LDAP', 'binddn')
     self.start_tls = self.config.get('LDAP', 'start_tls', False)
     self.bind_password = self.config.get('LDAP', 'bindpw')
     try:
         self.LDAP = ldap.initialize('ldap://%s:%s' %
                                      (self.server, self.port))
         self.LDAP.protocol_version = 3 #ldap.VERSION3
         if self.start_tls:
             self.LDAP.start_tls_s()
         self.LDAP.simple_bind_s(self.bind_dn, self.bind_password)
         self.log.debug('Bound to LDAP server %s:%s as %s' % 
                        (self.server, self.port, self.bind_dn))
     except ldap.LDAPError:
         trace = traceback.format_exc()
         msg = 'Failed to bind to LDAP server %s:%s as %s' % \
             (self.server,self.port, self.bind_dn)
         raise error.SpokeLDAPError(msg, trace)
     except Exception:
         trace = traceback.format_exc()
         msg = 'Unknown error'
         raise error.SpokeError(msg, trace)
Esempio n. 9
0
File: ca.py Progetto: mattmb/spoke
 def __init__(self, cn, requester, signer=None):
     """Get config, setup logging."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.reqca = self._get_ca(requester)
     if signer:
         self.signca = self._get_ca(signer)
     else:
         self.signca = self.reqca
Esempio n. 10
0
 def __init__(self, vm_name):
     """Get config and setup logging."""
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     def _error_handler(self, err):
         msg = "Ignoring Libvirt error %s)" % err
         pass
     # Prevent libvirt errors from reaching the console
     libvirt.registerErrorHandler(_error_handler, None)
Esempio n. 11
0
File: ca.py Progetto: mattmb/spoke
 def __init__(self, cn, requester, signer=None):    
     """Get config, setup logging."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.reqca = self._get_ca(requester)
     if signer:
         self.signca = self._get_ca(signer)
     else:
         self.signca = self.reqca
Esempio n. 12
0
 def __init__(self, org_name, domain_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.dns_cont_attr = self.config.get('DNS', 'dns_cont_attr', 'ou')
     self.dns_cont_name = self.config.get('DNS', 'dns_cont_name', 'dns')
     self.dns_cont_class = self.config.get('ATTR_MAP', \
                                     'container_class', 'organizationalUnit')
     self.dns_zone_name_attr = self.config.get('DNS', 'dns_zone_attr',
                                               'zoneName')
     self.dns_zone_class = self.config.get('DNS', 'dns_zone_class',
                                           'dNSZone')
     self.dns_resource_attr = self.config.get('DNS', 'dns_resource_attr',
                                              'relativeDomainName')
     self.dns_record_class = self.config.get('DNS', 'dns_record_class',
                                             'IN')
     self.dns_default_ttl = self.config.get('DNS', 'dns_default_ttl',
                                            '86400')
     self.dns_min_ttl = self.config.get('DNS', 'dns_min_ttl', '3600')
     self.dns_serial_start = self.config.get('DNS', 'dns_serial_start', '1')
     self.dns_slave_refresh = self.config.get('DNS', 'dns_slave_refresh',
                                              '3600')
     self.dns_slave_retry = self.config.get('DNS', 'dns_slave_retry', '600')
     self.dns_slave_expire = self.config.get('DNS', 'dns_slave_expire',
                                             '86400')
     self.dns_ns_attr = self.config.get('DNS', 'dns_ns_attr', 'nSRecord')
     self.dns_soa_attr = self.config.get('DNS', 'dns_soa_attr', 'sOARecord')
     self.dns_a_attr = self.config.get('DNS', 'dns_a_attr', 'aRecord')
     self.dns_cname_attr = self.config.get('DNS', 'dns_cname_attr',
                                           'cNAMERecord')
     self.dns_mx_attr = self.config.get('DNS', 'dns_mx_attr', 'mXRecord')
     self.dns_txt_attr = self.config.get('TXT', 'dns_txt_attr', 'tXTRecord')
     self.dns_ptr_attr = self.config.get('PTR', 'dns_ptr_attr', 'pTRRecord')
     self.dns_type_attrs = {
         'SOA': self.dns_soa_attr,
         'NS': self.dns_ns_attr,
         'A': self.dns_a_attr,
         'CNAME': self.dns_cname_attr,
         'MX': self.dns_mx_attr,
         'TXT': self.dns_txt_attr,
         'PTR': self.dns_ptr_attr
     }
     self.domain_name = common.validate_domain(domain_name)
     self.dns_dn = '%s=%s,%s' % (self.dns_cont_attr, self.dns_cont_name, \
                                                             self.org_dn)
     self.zone_dn = '%s=%s,%s' % (self.dns_zone_name_attr, \
                                             self.domain_name, self.dns_dn)
Esempio n. 13
0
File: dhcp.py Progetto: mattmb/spoke
 def __init__(self):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_server_class = 'dhcpServer'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config') 
Esempio n. 14
0
 def __init__(self):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_server_class = 'dhcpServer'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix',
                                             '-config')
Esempio n. 15
0
    def __init__(self, vm_name):
        """Get config and setup logging."""
        self.config = config.setup()
        self.log = logger.setup(self.__module__)

        def _error_handler(self, err):
            msg = "Ignoring Libvirt error %s)" % err
            pass

        # Prevent libvirt errors from reaching the console
        libvirt.registerErrorHandler(_error_handler, None)
Esempio n. 16
0
 def test_write_read_log_message(self):
     """Write message to log file; read it back."""
     logger.gLog = None
     self.config = config.setup(self.test_config_filename)
     self.log = logger.setup(self.__module__)
     test_phrase = 'This is a Spoke logger test'
     self.log.critical(test_phrase)
     lf = open(self.test_log_filename, 'r')
     lines = lf.readlines()
     lf.close()
     res = lines[-1].find(test_phrase)
     self.assert_(res > -1)
Esempio n. 17
0
 def test_write_read_log_message(self):
     """Write message to log file; read it back."""
     logger.gLog = None
     self.config = config.setup(self.test_config_filename)
     self.log = logger.setup(self.__module__)
     test_phrase = 'This is a Spoke logger test'
     self.log.critical(test_phrase)
     lf = open(self.test_log_filename, 'r')
     lines = lf.readlines()
     lf.close()
     res = lines[-1].find(test_phrase)
     self.assert_(res > -1)
Esempio n. 18
0
File: dhcp.py Progetto: mattmb/spoke
 def __init__(self, dhcp_server):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_group_class = 'dhcpGroup'
     self.dhcp_options_class = 'dhcpOptions'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config')
     self.service_name = dhcp_server + self.dhcp_conf_suffix
     self.service_dn = 'cn=%s,%s' % (self.service_name, self.base_dn)
Esempio n. 19
0
 def __init__(self, dhcp_server):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_group_class = 'dhcpGroup'
     self.dhcp_options_class = 'dhcpOptions'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix',
                                             '-config')
     self.service_name = dhcp_server + self.dhcp_conf_suffix
     self.service_dn = 'cn=%s,%s' % (self.service_name, self.base_dn)
Esempio n. 20
0
File: dhcp.py Progetto: mattmb/spoke
 def __init__(self, dhcp_server):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_subnet_class = 'dhcpSubnet'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config')
     self.dhcp_server = dhcp_server
     self.dhcp_service_name = self.dhcp_server + self.dhcp_conf_suffix
     self.dhcp_service = self._get_dhcp_service(self.dhcp_server)
     self.dhcp_service_dn = self.dhcp_service['data'][0].__getitem__(0)
Esempio n. 21
0
 def __init__(self, dhcp_server):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_subnet_class = 'dhcpSubnet'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix',
                                             '-config')
     self.dhcp_server = dhcp_server
     self.dhcp_service_name = self.dhcp_server + self.dhcp_conf_suffix
     self.dhcp_service = self._get_dhcp_service(self.dhcp_server)
     self.dhcp_service_dn = self.dhcp_service['data'][0].__getitem__(0)
Esempio n. 22
0
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)      
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 0 #ldap.SCOPE_BASE
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.smtp_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix')
     self.smtp_domain = self.config.get('ATTR_MAP', 'smtp_domain', 'aenetPostfixDomain')
     self.retrieve_attr = [self.smtp_domain]
Esempio n. 23
0
 def __init__(self):
     """Get config and setup loggings."""
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     #This block gets interface and interface type from config file
     self._lookupInterfaces()
     #And this one does the same for disks.
     self._lookupDisks()
     self.search_headers = self.config.get('VM', 'search_headers', 'name,uuid')
     self.headers = self.search_headers.split(',')
     def _error_handler(self, err):
         msg = "Ignoring Libvirt error %s)" % err
         pass
     # Prevent libvirt errors from reaching the console
     libvirt.registerErrorHandler(_error_handler, None)
Esempio n. 24
0
File: dhcp.py Progetto: mattmb/spoke
 def __init__(self, dhcp_server, group_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_host_class = 'dhcpHost'
     self.dhcp_options_class = 'dhcpOptions'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix', '-config')
     self.dhcp_server = dhcp_server
     self.dhcp_group_name = group_name
     group = self._get_dhcp_group(self.dhcp_server, self.dhcp_group_name)
     self.dhcp_group_dn = group['data'][0].__getitem__(0)
Esempio n. 25
0
File: host.py Progetto: mattmb/spoke
 def __init__(self):    
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 0 #ldap.SCOPE_BASE
     self.next_uuid_attr = self.config.get('UUID','next_uuid_attr', 'aenetHostUUID')
     self.base_dn = self.config.get('LDAP','basedn')
     self.next_uuid_dn = self.config.get('UUID','next_uuid_dn', self.base_dn)
     self.next_uuid_class = self.config.get('UUID','next_uuid_class', 'aenetNextUUID')
     self.next_uuid_start = self.config.get('UUID','next_uuid_start', 1)   
     self.next_uuid = self._get_next_uuid_dn()['data']
     self.next_uuid_attrs = self.next_uuid[0].__getitem__(1)
     self.next_uuid_classes = self.next_uuid_attrs['objectClass']
     self.retrieve_attr = [self.next_uuid_attr]
     self.filter = '%s=*' % self.next_uuid_attr
Esempio n. 26
0
 def __init__(self, dhcp_server, group_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('DHCP', 'dhcp_basedn')
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.dhcp_host_class = 'dhcpHost'
     self.dhcp_options_class = 'dhcpOptions'
     self.dhcp_conf_suffix = self.config.get('DHCP', 'dhcp_conf_suffix',
                                             '-config')
     self.dhcp_server = dhcp_server
     self.dhcp_group_name = group_name
     group = self._get_dhcp_group(self.dhcp_server, self.dhcp_group_name)
     self.dhcp_group_dn = group['data'][0].__getitem__(0)
Esempio n. 27
0
File: tftp.py Progetto: mattmb/spoke
 def __init__(self, tftp_root=None):
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.type = 'TFTP config'
     if not tftp_root:
         tftp_root = self.config.get('TFTP', 'tftp_root')
     self.tftp_root = common.validate_filename(tftp_root)
     self.tftp_conf_dir = self.config.get('TFTP', 'tftp_conf_dir', 'pxelinux.cfg')
     self.tftp_mac_prefix = self.config.get('TFTP', 'tftp_mac_prefix', '01')
     # Add the delimiter (makes life easier when concating strings
     self.tftp_prefix = self.tftp_mac_prefix + '-' 
     #check file exists in the TFTP directory
     self.tftp_dir = self.tftp_root + "/" + self.tftp_conf_dir + "/"
     if not os.path.isdir(self.tftp_dir):
         msg = "TFTP config directory %s not found" % self.tftp_dir
         raise error.NotFound, msg
Esempio n. 28
0
File: dns.py Progetto: mattmb/spoke
 def __init__(self, org_name, domain_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 2 # ldap.SUB
     self.retrieve_attr = None
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.dns_cont_attr = self.config.get('DNS', 'dns_cont_attr', 'ou')
     self.dns_cont_name = self.config.get('DNS', 'dns_cont_name', 'dns')
     self.dns_cont_class = self.config.get('ATTR_MAP', \
                                     'container_class', 'organizationalUnit')
     self.dns_zone_name_attr = self.config.get('DNS', 'dns_zone_attr', 'zoneName')
     self.dns_zone_class = self.config.get('DNS', 'dns_zone_class', 'dNSZone')
     self.dns_resource_attr = self.config.get('DNS','dns_resource_attr', 'relativeDomainName')
     self.dns_record_class = self.config.get('DNS','dns_record_class', 'IN')
     self.dns_default_ttl = self.config.get('DNS', 'dns_default_ttl', '86400')
     self.dns_min_ttl = self.config.get('DNS', 'dns_min_ttl', '3600')
     self.dns_serial_start = self.config.get('DNS', 'dns_serial_start', '1')
     self.dns_slave_refresh = self.config.get('DNS','dns_slave_refresh', '3600')
     self.dns_slave_retry = self.config.get('DNS', 'dns_slave_retry', '600')
     self.dns_slave_expire = self.config.get('DNS', 'dns_slave_expire', '86400')
     self.dns_ns_attr = self.config.get('DNS', 'dns_ns_attr', 'nSRecord')
     self.dns_soa_attr = self.config.get('DNS', 'dns_soa_attr', 'sOARecord')
     self.dns_a_attr = self.config.get('DNS', 'dns_a_attr', 'aRecord')
     self.dns_cname_attr = self.config.get('DNS', 'dns_cname_attr', 'cNAMERecord')
     self.dns_mx_attr = self.config.get('DNS', 'dns_mx_attr', 'mXRecord')
     self.dns_txt_attr = self.config.get('TXT', 'dns_txt_attr', 'tXTRecord')
     self.dns_ptr_attr = self.config.get('PTR', 'dns_ptr_attr', 'pTRRecord')
     self.dns_type_attrs = {'SOA':self.dns_soa_attr,
                            'NS':self.dns_ns_attr,
                            'A':self.dns_a_attr,
                            'CNAME':self.dns_cname_attr,
                            'MX': self.dns_mx_attr,
                            'TXT': self.dns_txt_attr,
                            'PTR': self.dns_ptr_attr}
     self.domain_name = common.validate_domain(domain_name)
     self.dns_dn = '%s=%s,%s' % (self.dns_cont_attr, self.dns_cont_name, \
                                                             self.org_dn)
     self.zone_dn = '%s=%s,%s' % (self.dns_zone_name_attr, \
                                             self.domain_name, self.dns_dn)
Esempio n. 29
0
File: tftp.py Progetto: mattmb/spoke
 def __init__(self, tftp_root=None):
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.type = 'TFTP config'
     if not tftp_root:
         tftp_root = self.config.get('TFTP', 'tftp_root')
     self.tftp_root = common.validate_filename(tftp_root)
     self.tftp_conf_dir = self.config.get('TFTP', 'tftp_conf_dir',
                                          'pxelinux.cfg')
     self.tftp_mac_prefix = self.config.get('TFTP', 'tftp_mac_prefix', '01')
     # Add the delimiter (makes life easier when concating strings
     self.tftp_prefix = self.tftp_mac_prefix + '-'
     #check file exists in the TFTP directory
     self.tftp_dir = self.tftp_root + "/" + self.tftp_conf_dir + "/"
     if not os.path.isdir(self.tftp_dir):
         msg = "TFTP config directory %s not found" % self.tftp_dir
         raise error.NotFound, msg
Esempio n. 30
0
 def __init__(self):
     """Bind to Redis server, return an redis connection object."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.kv_host = self.config.get('KV', 'kv_host')
     self.kv_port = int(self.config.get('KV', 'kv_port', 6379))
     self.kv_db = self.config.get('KV', 'kv_db', '0')
     try:
         self.KV = redis.StrictRedis(host=self.kv_host, port=self.kv_port,
                                      db=self.kv_db)
         # We have to query something to know if the connection is good
         self.KV.keys()
     except redis.exceptions.ConnectionError:
         msg = 'Connection to Redis server %s:%s as %s failed' % \
             (self.kv_host, self.kv_port, self.kv_db)
         trace = traceback.format_exc()
         raise error.RedisError(msg, trace)
Esempio n. 31
0
File: vcs.py Progetto: mattmb/spoke
 def __init__(self, org_name, user_id):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.org_name = org_name
     self.user_id = user_id
     self.user = self._get_user(self.org_name, self.user_id)
     self.user_dn = self.user['data'][0].__getitem__(0)
     self.user_attrs = self.user['data'][0].__getitem__(1)
     self.user_classes = self.user_attrs['objectClass']
     self.svn_class = self.config.get('VCS', 'svn_class', 'aenetSubversion')
     self.svn_repo_attr = self.config.get('VCS', 'svn_repo_attr', 'aenetSubversionRepos')
     self.svn_enable_attr = self.config.get('VCS', 'svn_enable_attr', 'aenetSubversionEnabled')
     self.retrieve_attr = [self.svn_repo_attr, self.svn_enable_attr]
     self.filter = self.svn_repo_attr + '=*'
     self.search_scope = 2 # ldap.SUB
Esempio n. 32
0
File: org.py Progetto: mattmb/spoke
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2 # ldap.SCOPE_SUBTREE
     self.retrieve_attr = None
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     if self.org['data'] == []:
         msg = 'Org %s not found: cannot delete children' % self.org_name
         raise error.NotFound(msg)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou')
     self.container_class = self.config.get('ATTR_MAP', \
                                     'container_class', 'organizationalUnit')
Esempio n. 33
0
File: mbx.py Progetto: mattmb/spoke
 def __init__(self):
     """Get config, setup logging and cyrus connection."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     server = self.config.get('IMAP', 'server')
     port = int(self.config.get('IMAP', 'port', 143))
     self.user = self.config.get('IMAP', 'user')
     password = self.config.get('IMAP', 'password')
     self.mailbox_group = self.config.get('IMAP', 'mailbox_group', 'user')
     self.sep = '/'
     try:
         self.imap = imaplib.IMAP4(server, port)
     except imaplib.socket.error:
         trace = traceback.format_exec()
         msg = '%s: %s' % ('IMAP connection error')
         raise error.SpokeIMAPError(msg, trace)
     self.imap.login(self.user, password)
Esempio n. 34
0
File: mbx.py Progetto: mattmb/spoke
 def __init__(self):
     """Get config, setup logging and cyrus connection."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     server = self.config.get('IMAP', 'server')
     port = int(self.config.get('IMAP', 'port', 143))
     self.user = self.config.get('IMAP', 'user')
     password = self.config.get('IMAP', 'password')
     self.mailbox_group = self.config.get('IMAP', 'mailbox_group', 'user')
     self.sep = '/'
     try:
         self.imap = imaplib.IMAP4(server, port)
     except imaplib.socket.error:
         trace = traceback.format_exec()
         msg = '%s: %s' % ('IMAP connection error')
         raise error.SpokeIMAPError(msg, trace)
     self.imap.login(self.user, password)
Esempio n. 35
0
    def __init__(self):
        """Get config and setup loggings."""
        self.config = config.setup()
        self.log = logger.setup(self.__module__)
        #This block gets interface and interface type from config file
        self._lookupInterfaces()
        #And this one does the same for disks.
        self._lookupDisks()
        self.search_headers = self.config.get('VM', 'search_headers',
                                              'name,uuid')
        self.headers = self.search_headers.split(',')

        def _error_handler(self, err):
            msg = "Ignoring Libvirt error %s)" % err
            pass

        # Prevent libvirt errors from reaching the console
        libvirt.registerErrorHandler(_error_handler, None)
Esempio n. 36
0
File: org.py Progetto: mattmb/spoke
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2  # ldap.SCOPE_SUBTREE
     self.retrieve_attr = None
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     if self.org['data'] == []:
         msg = 'Org %s not found: cannot delete children' % self.org_name
         raise error.NotFound(msg)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr',
                                           'ou')
     self.container_class = self.config.get('ATTR_MAP', \
                                     'container_class', 'organizationalUnit')
Esempio n. 37
0
File: org.py Progetto: mattmb/spoke
 def __init__(self):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2 # ldap.SCOPE_SUBTREE
     self.retrieve_attr = None
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.org_class = self.config.get('ATTR_MAP', 'org_class', 'organization')
     self.user_class = self.config.get('ATTR_MAP', 'user_class', 'aenetAccount')
     self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o')
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou')
     self.container_class = self.config.get('ATTR_MAP', \
                                     'container_class', 'organizationalUnit')
     self.org_def_children = self.config.get('ATTR_MAP', \
                             'org_def_children', 'people,groups,dns,hosts')
     self.org_children = self.org_def_children.split(',')
     self.org_suffix_attr = self.config.get('ATTR_MAP', 'org_suffix', 'aenetAccountSuffix')
Esempio n. 38
0
File: vcs.py Progetto: mattmb/spoke
 def __init__(self, org_name, user_id):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.org_name = org_name
     self.user_id = user_id
     self.user = self._get_user(self.org_name, self.user_id)
     self.user_dn = self.user['data'][0].__getitem__(0)
     self.user_attrs = self.user['data'][0].__getitem__(1)
     self.user_classes = self.user_attrs['objectClass']
     self.svn_class = self.config.get('VCS', 'svn_class', 'aenetSubversion')
     self.svn_repo_attr = self.config.get('VCS', 'svn_repo_attr',
                                          'aenetSubversionRepos')
     self.svn_enable_attr = self.config.get('VCS', 'svn_enable_attr',
                                            'aenetSubversionEnabled')
     self.retrieve_attr = [self.svn_repo_attr, self.svn_enable_attr]
     self.filter = self.svn_repo_attr + '=*'
     self.search_scope = 2  # ldap.SUB
Esempio n. 39
0
File: host.py Progetto: mattmb/spoke
 def __init__(self):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 0  #ldap.SCOPE_BASE
     self.next_uuid_attr = self.config.get('UUID', 'next_uuid_attr',
                                           'aenetHostUUID')
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.next_uuid_dn = self.config.get('UUID', 'next_uuid_dn',
                                         self.base_dn)
     self.next_uuid_class = self.config.get('UUID', 'next_uuid_class',
                                            'aenetNextUUID')
     self.next_uuid_start = self.config.get('UUID', 'next_uuid_start', 1)
     self.next_uuid = self._get_next_uuid_dn()['data']
     self.next_uuid_attrs = self.next_uuid[0].__getitem__(1)
     self.next_uuid_classes = self.next_uuid_attrs['objectClass']
     self.retrieve_attr = [self.next_uuid_attr]
     self.filter = '%s=*' % self.next_uuid_attr
Esempio n. 40
0
File: ip.py Progetto: mattmb/spoke
    def __init__(self, ip=None, mask=None, dc=None):
        """Get config, setup logging and Redis connection."""
        SpokeKV.__init__(self)
        self.config = config.setup()
        self.log = logger.setup(__name__)
        self.max_mask = 16  # This is the largest network we can work with
        # Check our subnet is well formatted in dotted decimal
        if ip and mask:
            common.validate_ip_address(ip)
            # Check our netmask is well formatted and NOT in dotted decimal
            try:
                common.validate_ip_address(mask)
            except:
                pass  # It's not a dotted decimal format subnet, good
            else:
                # It validated as a dotted decimal, but we need an integer
                msg = 'IPv4 subnet mask must be between %s and 32' % self.max_mask
                raise error.InputError(msg)

            self.subnet = ip_helper.Network(ip, int(mask))
            self.network = self.subnet.network()
            self.mask = self.subnet.mask

            if dc is not None:
                self.kv_name = dc + str(self.network)
                self.kv_free = '%s:%s:%s:free' % (dc, self.network, self.mask)
                self.kv_aloc = '%s:%s:%s:aloc' % (dc, self.network, self.mask)
            else:
                self.kv_name = str(self.network)
                self.kv_free = '%s:%s:free' % (self.network, self.mask)
                self.kv_aloc = '%s:%s:aloc' % (self.network, self.mask)
            self.ip_ldap_enabled = self.config.get('IP', 'ip_ldap_enabled',
                                                   False)
            self.ip_ldap_attr = self.config.get('IP', 'ip_ldap_attr',
                                                'dhcpStatements')
            self.ip_ldap_key = self.config.get('IP', 'ip_ldap_key',
                                               'fixed-address')
            self.ip_ldap_search_base = self.config.get('IP',
                                                       'ip_ldap_search_base',
                                                       False)
        else:
            (self.network, self.mask) = (None, None)
Esempio n. 41
0
File: user.py Progetto: mattmb/spoke
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)     
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2 #ldap.SCOPE_SUBTREE
     self.retrieve_attr = None
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o')
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou')
     self.user_login = self.config.get('ATTR_MAP', 'user_login', 'aenetAccountLoginName')
     self.user_class = self.config.get('ATTR_MAP', 'user_class', 'aenetAccount')
     self.user_key = self.config.get('ATTR_MAP', 'user_key', 'uid')
     self.user_name = self.config.get('ATTR_MAP', 'user_name', 'aenetAccountDisplayName')
     self.user_enable = self.config.get('ATTR_MAP', 'user_enable', 'aenetAccountEnabled')
     self.user_container = self.config.get('ATTR_MAP', 'user_container', 'people')
Esempio n. 42
0
 def __init__(self, org_name, user_id):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     try:
         self.user_pwd_attr = self.config.get('ATTR_MAP', 'user_password')
     except:
         self.user_pwd_attr = 'userPassword'
     self.retrieve_attr = [self.user_pwd_attr]
     self.filter = self.user_pwd_attr + '=*'
     self.org_name = org_name
     self.user_id = user_id
     self.user = self._get_user(self.org_name, self.user_id)
     self.user_dn = self.user['data'][0].__getitem__(0)
     self.user_attrs = self.user['data'][0].__getitem__(1)
     self.user_classes = self.user_attrs['objectClass']
     self.server = self.config.get('LDAP', 'server')
     self.port = self.config.get('LDAP', 'port', '389')
     self.start_tls = self.config.get('LDAP', 'start_tls', False)
     self.search_scope = 2 # ldap.SUB
Esempio n. 43
0
File: host.py Progetto: mattmb/spoke
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2  # ldap.SUB
     self.retrieve_attr = None
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr',
                                           'ou')
     self.host_container = self.config.get('HOST', 'host_container',
                                           'hosts')
     self.host_container_dn = '%s=%s,%s' % (self.container_attr, \
                                         self.host_container, self.org_dn)
     self.host_class = self.config.get('HOST', 'host_class', 'aenetHost')
     self.host_key = self.config.get('HOST', 'host_key', 'cn')
     self.host_uuid_attr = self.config.get('HOST', 'host_uuid_attr',
                                           'aenetHostUUID')
     self.host_name_attr = self.config.get('HOST', 'host_name_attr',
                                           'aenetHostName')
     self.host_cpu_attr = self.config.get('HOST', 'host_cpu_attr',
                                          'aenetHostCPU')
     self.host_mem_attr = self.config.get('HOST', 'host_mem_attr',
                                          'aenetHostMem')
     self.host_extra_opts_attr = self.config.get('HOST',
                                                 'host_extra_opts_attr',
                                                 'aenetHostExtraOpts')
     self.host_family_attr = self.config.get('HOST', 'host_family_attr',
                                             'aenetHostFamily')
     self.host_network_layout_attr = self.config.get(
         'HOST', 'host_network_layout_attr', 'aenetHostNetworkLayout')
     self.host_storage_layout_attr = self.config.get(
         'HOST', 'host_storage_layout_attr', 'aenetHostStorageLayout')
     self.host_type_attr = self.config.get('HOST', 'host_type_attr',
                                           'aenetHostType')
Esempio n. 44
0
File: ca.py Progetto: mattmb/spoke
 def __init__(self, cn, requester=None, ca=None):
     """Get config, setup logging."""
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     if not requester:
         requester = self.config.get('CA', 'ca_default_ca')
     requester = common.is_shell_safe(requester)
     self.is_a_ca = ca
     self.reqca = SpokeCA(requester)
     if not self.reqca.get()['data']:
         msg = 'CA %s does not exist; please create' % requester
         raise error.NotFound(msg)
     if self.is_a_ca:
         self.cn = common.is_shell_safe(cn)
         self.req_file = self.reqca.ca_req_file
         self.key_file = self.reqca.ca_key_file
     else:  # We're dealing with a host CSR
         self.cn = common.validate_domain(cn)
         key_name = '%s.key.pem' % cn
         req_name = '%s.req' % cn
         self.key_file = os.path.join(self.reqca.ca_dir, key_name)
         self.req_file = os.path.join(self.reqca.ca_dir, req_name)
Esempio n. 45
0
File: org.py Progetto: mattmb/spoke
 def __init__(self):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.search_scope = 2  # ldap.SCOPE_SUBTREE
     self.retrieve_attr = None
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.org_class = self.config.get('ATTR_MAP', 'org_class',
                                      'organization')
     self.user_class = self.config.get('ATTR_MAP', 'user_class',
                                       'aenetAccount')
     self.org_attr = self.config.get('ATTR_MAP', 'org_attr', 'o')
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr',
                                           'ou')
     self.container_class = self.config.get('ATTR_MAP', \
                                     'container_class', 'organizationalUnit')
     self.org_def_children = self.config.get('ATTR_MAP', \
                             'org_def_children', 'people,groups,dns,hosts')
     self.org_children = self.org_def_children.split(',')
     self.org_suffix_attr = self.config.get('ATTR_MAP', 'org_suffix',
                                            'aenetAccountSuffix')
Esempio n. 46
0
File: ca.py Progetto: mattmb/spoke
 def __init__(self, cn, requester=None, ca=None):    
     """Get config, setup logging."""
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     if not requester:
         requester = self.config.get('CA', 'ca_default_ca')
     requester = common.is_shell_safe(requester)
     self.is_a_ca = ca
     self.reqca = SpokeCA(requester)
     if not self.reqca.get()['data']:
         msg = 'CA %s does not exist; please create' % requester
         raise error.NotFound(msg)
     if self.is_a_ca:
         self.cn = common.is_shell_safe(cn)
         self.req_file = self.reqca.ca_req_file
         self.key_file = self.reqca.ca_key_file
     else: # We're dealing with a host CSR
         self.cn = common.validate_domain(cn)
         key_name = '%s.key.pem' % cn
         req_name = '%s.req' % cn
         self.key_file = os.path.join(self.reqca.ca_dir, key_name)
         self.req_file = os.path.join(self.reqca.ca_dir, req_name)
Esempio n. 47
0
File: list.py Progetto: mattmb/spoke
 def __init__(self, org_name):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 2 #ldap.SCOPE_SUB
     self.org_name = org_name
     self.org = self._get_org(self.org_name)
     self.org_dn = self.org['data'][0].__getitem__(0)
     self.org_attrs = self.org['data'][0].__getitem__(1)
     self.org_classes = self.org_attrs['objectClass']
     self.container_attr = self.config.get('ATTR_MAP', 'container_attr', 'ou')
     self.list_container = self.config.get('ATTR_MAP', 'user_container', 'people')
     self.list_key = self.config.get('ATTR_MAP', 'user_key', 'uid')
     self.list_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix')
     self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept')
     self.list_destination_attr = self.config.get('ATTR_MAP', \
                             'smtp_destination', 'aenetPostfixEmailDeliver')
     self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled')
     self.list_pri_address_attr = self.config.get('ATTR_MAP', \
                             'smtp_pri_address', 'aenetPostfixEmailAddress')
     self.retrieve_attr = [self.list_address_attr]
Esempio n. 48
0
File: ip.py Progetto: mattmb/spoke
 def __init__(self, ip=None, mask=None, dc=None):   
     """Get config, setup logging and Redis connection."""
     SpokeKV.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.max_mask = 16 # This is the largest network we can work with
     # Check our subnet is well formatted in dotted decimal
     if ip and mask:
         common.validate_ip_address(ip)
         # Check our netmask is well formatted and NOT in dotted decimal
         try:
             common.validate_ip_address(mask)
         except:
             pass # It's not a dotted decimal format subnet, good
         else:
             # It validated as a dotted decimal, but we need an integer
             msg = 'IPv4 subnet mask must be between %s and 32' % self.max_mask
             raise error.InputError(msg)
         
         self.subnet = ip_helper.Network(ip, int(mask))
         self.network = self.subnet.network()
         self.mask = self.subnet.mask
     
         if dc is not None:
             self.kv_name = dc + str(self.network)
             self.kv_free = '%s:%s:%s:free' % (dc, self.network, self.mask)
             self.kv_aloc = '%s:%s:%s:aloc' % (dc, self.network, self.mask)
         else:
             self.kv_name = str(self.network)
             self.kv_free = '%s:%s:free' % (self.network, self.mask)
             self.kv_aloc = '%s:%s:aloc' % (self.network, self.mask)
         self.ip_ldap_enabled = self.config.get('IP', 'ip_ldap_enabled', False)
         self.ip_ldap_attr = self.config.get('IP', 'ip_ldap_attr', 'dhcpStatements')
         self.ip_ldap_key = self.config.get('IP', 'ip_ldap_key', 'fixed-address')
         self.ip_ldap_search_base = self.config.get('IP', 'ip_ldap_search_base', False)
     else:
         (self.network, self.mask) = (None, None)
Esempio n. 49
0
File: list.py Progetto: mattmb/spoke
 def __init__(self, org_name, list_address):
     """Get config, setup logging and LDAP connection."""
     SpokeLDAP.__init__(self)
     self.config = config.setup()
     self.log = logger.setup(self.__module__)
     self.base_dn = self.config.get('LDAP', 'basedn')
     self.search_scope = 0 #ldap.SCOPE_BASE
     self.org_name = org_name
     self.list_address = self._validate_input(list_address)
     self.list_name, self.list_domain = self.list_address.split('@')
     self.list = self._get_list(self.org_name, self.list_address)
     self.list_dn = self.list['data'][0].__getitem__(0)
     self.list_attrs = self.list['data'][0].__getitem__(1)
     self.list_classes = self.list_attrs['objectClass']
     
     self.list_key = self.config.get('ATTR_MAP', 'user_key', 'uid')
     self.list_class = self.config.get('ATTR_MAP', 'smtp_class', 'aenetPostfix')
     self.list_address_attr = self.config.get('ATTR_MAP', 'smtp_address', 'aenetPostfixEmailAccept')
     self.list_destination_attr = self.config.get('ATTR_MAP', \
                             'smtp_destination', 'aenetPostfixEmailDeliver')
     self.list_enable_attr = self.config.get('ATTR_MAP', 'smtp_enable', 'aenetPostfixEnabled')
     self.list_pri_address_attr = self.config.get('ATTR_MAP', \
                             'smtp_pri_address', 'aenetPostfixEmailAddress')
     self.retrieve_attr = [self.list_destination_attr]
Esempio n. 50
0
import sys
# own modules
import spoke.lib.error as error
import spoke.lib.config as config
import spoke.lib.logger as logger
import spoke.lib.mc_helper as mc

# TODO This only works for Xen until we can hide VM Storage types in the vm_storage module
# TODO Implement access to vm power via vm host modify (e.g. vm.modify(vm_name, power=on).
from spoke.lib.vm_storage import SpokeVMStorageXen

config_file = '/usr/local/pkg/spoke/etc/spoke.conf'
config = config.setup(config_file)
    
if __name__ == '__main__':
    log = logger.setup('main', verbose=False, quiet=True)
    mc = mc.MCollectiveAction()
    request = mc.request()
    try:
        hv_uri = config.get('VM', 'hv_uri')
        mc.info('Connecting to hypervisor URI %s' % hv_uri)
        vm = SpokeVMStorageXen(hv_uri)
    except error.SpokeError, e:
        mc.fail(e.msg, e.exit_code)
            
    if request['action'] == 'create':
        vm_name             = request['data']['hostname']
        vm_uuid             = request['data']['uuid']
        vm_mem              = request['data']['mem']
        vm_cpu              = request['data']['cpu']
        vm_family           = request['data']['family']
Esempio n. 51
0
File: lvm.py Progetto: mattmb/spoke
 def __init__(self, vg_name):
     """Get config, setup logging."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.vg_name = common.is_shell_safe(vg_name)
     self.lv_units = self.config.get('LVM', 'lv_units', 'g')
Esempio n. 52
0
 def __init__(self):
     """Bind to LDAP directory; return an LDAP connection object."""
     self.config = config.setup()
     self.log = logger.setup(__name__)
     self.LDAP = setup().LDAP