<s> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from sahara import context <EOL> from sahara . i18n import _LI <EOL> from sahara . swift import utils as su <EOL> from sahara . utils import xmlutils as x <EOL> LOG = logging . getLogger ( __name__ ) <EOL> CONF = cfg . CONF <EOL> HADOOP_SWIFT_AUTH_URL = '<STR_LIT>' <EOL> HADOOP_SWIFT_TENANT = '<STR_LIT>' <EOL> HADOOP_SWIFT_USERNAME = '<STR_LIT>' <EOL> HADOOP_SWIFT_PASSWORD = '<STR_LIT>' <EOL> HADOOP_SWIFT_REGION = '<STR_LIT>' <EOL> HADOOP_SWIFT_TRUST_ID = '<STR_LIT>' <EOL> HADOOP_SWIFT_DOMAIN_NAME = '<STR_LIT>' <EOL> opts = [ <EOL> cfg . StrOpt ( "<STR_LIT>" , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) , <EOL> cfg . StrOpt ( "<STR_LIT>" , <EOL> help = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> ] <EOL> public_endpoint_cert_group = cfg . OptGroup ( <EOL> name = "<STR_LIT>" , title = "<STR_LIT>" ) <EOL> CONF . register_group ( public_endpoint_cert_group ) <EOL> CONF . register_opts ( opts , group = public_endpoint_cert_group ) <EOL> def retrieve_tenant ( ) : <EOL> return context . current ( ) . tenant_name <EOL> def get_swift_configs ( ) : <EOL> configs = x . load_hadoop_xml_defaults ( '<STR_LIT>' ) <EOL> for conf in configs : <EOL> if conf [ '<STR_LIT:name>' ] == HADOOP_SWIFT_AUTH_URL : <EOL> conf [ '<STR_LIT:value>' ] = su . retrieve_auth_url ( ) + "<STR_LIT>" <EOL> if conf [ '<STR_LIT:name>' ] == HADOOP_SWIFT_TENANT : <EOL> conf [ '<STR_LIT:value>' ] = retrieve_tenant ( ) <EOL> if CONF . os_region_name and conf [ '<STR_LIT:name>' ] == HADOOP_SWIFT_REGION : <EOL> conf [ '<STR_LIT:value>' ] = CONF . os_region_name <EOL> result = [ cfg for cfg in configs if cfg [ '<STR_LIT:value>' ] ] <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( result = result ) ) <EOL> return result <EOL> def read_default_swift_configs ( ) : <EOL> return x . load_hadoop_xml_defaults ( '<STR_LIT>' ) <EOL> def install_ssl_certs ( instances ) : <EOL> certs = [ ] <EOL> if CONF . object_store_access . public_identity_ca_file : <EOL> certs . append ( CONF . object_store_access . public_identity_ca_file ) <EOL> if CONF . object_store_access . public_object_store_ca_file : <EOL> certs . append ( CONF . object_store_access . public_object_store_ca_file ) <EOL> if not certs : <EOL> return <EOL> with context . ThreadGroup ( ) as tg : <EOL> for inst in instances : <EOL> tg . spawn ( "<STR_LIT>" % inst . instance_id , <EOL> _install_ssl_certs , inst , certs ) <EOL> def _install_ssl_certs ( instance , certs ) : <EOL> register_cmd = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> with instance . remote ( ) as r : <EOL> for idx , cert in enumerate ( certs ) : <EOL> with open ( cert ) as cert_fd : <EOL> data = cert_fd . read ( ) <EOL> r . write_file_to ( "<STR_LIT>" , data ) <EOL> try : <EOL> r . execute_command ( register_cmd % idx ) <EOL> finally : <EOL> r . execute_command ( "<STR_LIT>" ) </s>
