Skip to content

Commit

Permalink
director: do not send cloud credentials to managers anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrivat committed Jul 21, 2016
1 parent 0b79d0e commit 7a19068
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 96 deletions.
124 changes: 36 additions & 88 deletions conpaas-director/cpsdirector/iaas/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ConfigParser import ConfigParser
from cpsdirector.common import config_parser as default_config_parser


class Controller(object):

def __init__(self):
Expand Down Expand Up @@ -99,11 +100,6 @@ def _set_clouds(self):
raise e
self._logger.debug("succeeded iaas.get_clouds()")



#=========================================================================#
# generate_context(self, service_name, replace, cloud) #
#=========================================================================#
def generate_context(self, clouds, context_replacement={}, startup_script=None):
"""Generates the contextualization file for the given clouds.
"""
Expand All @@ -113,11 +109,6 @@ def generate_context(self, clouds, context_replacement={}, startup_script=None):
context = self._generate_context_file(cloud, context_replacement, startup_script)
cloud.set_context(context)

def generate_config_file(self, cloud_name):
#TODO (genc) copy the config generation part of the method below here
pass


def get_cloud_by_name(self, cloud_name):
"""
@param cloud_name
Expand All @@ -132,9 +123,6 @@ def get_cloud_by_name(self, cloud_name):
except IndexError:
raise Exception("Unknown cloud: %s. Available clouds: %s" % (cloud_name, self._available_clouds))

#=========================================================================#
# create_nodes(self, count, contextFile, test_agent) #
#=========================================================================#
def create_nodes(self, nodes_info, clouds):
self._logger.debug('[create_nodes]: %s' % nodes_info)

Expand Down Expand Up @@ -186,7 +174,6 @@ def _create_nodes(self, nodes_info, cloud):
self._logger.debug("[create_nodes]: cloud.new_instances(%s)" % str(nodes_info) )
return cloud.new_instances(nodes_info)


# def create_nodes(self, count, cloud_name=None, inst_type=None):
# """
# Creates the VMs associated with the list of nodes. It also tests
Expand Down Expand Up @@ -368,9 +355,6 @@ def _check_node(self, node):

return False

#=========================================================================#
# list_vms(self, cloud=None) #
#=========================================================================#
def list_vms(self, cloud=None):
"""Returns an array with the VMs running at the given/default(s) cloud.
Expand All @@ -382,9 +366,6 @@ def list_vms(self, cloud=None):

return cloud.list_vms()

#=========================================================================#
# delete_nodes(self, nodes) #
#=========================================================================#
def delete_nodes(self, nodes):
"""Kills the VMs associated with the list of nodes.
Expand Down Expand Up @@ -416,7 +397,6 @@ def create_volume(self, size, name, vm_id, cloud=None):

return cloud.create_volume(size, name, vm_id)


def attach_volume(self, vm_id, volume_id, device, cloud=None):
cloud = self.get_cloud_by_name(cloud)
if cloud.connected is False:
Expand Down Expand Up @@ -449,7 +429,6 @@ class volume:
self._logger.debug("destroy_volume(volume=%s)" % volume.id)
return cloud.destroy_volume(volume)


def _create_manager_config(self, user_id, app_id, vpn=None):
"""Add manager configuration"""
config_string = StringIO.StringIO()
Expand Down Expand Up @@ -494,6 +473,7 @@ def check_process(self, host):
return self._check(https.client.jsonrpc_get(host, self.port, '/', method))

class AgentController(Controller):

def __init__(self, user_id, app_id, service_id, service_type, manager_ip):
Controller.__init__(self)
self.config_parser = self._create_agent_config(str(user_id), str(app_id), service_id, service_type, manager_ip)
Expand All @@ -511,38 +491,11 @@ def _create_agent_config(self, user_id, app_id, service_id, service_type, manage
config_parser.set('manager', 'MANAGER_IP', manager_ip)
return config_parser

def _generate_context_file(self, cloud, context_replacement={}, startup_script=None):
'''
the context file runs the scripts necessary on each node created
it's installing all the necessary dependencies for the service
on the cloud you are installing
'''

cloud_type = cloud.get_cloud_type()
# conpaas_home = self.config_parser.get('manager', 'CONPAAS_HOME')
def generate_config_file(self, context_replacement):
conpaas_home = self.config_parser.get('conpaas', 'CONF_DIR')

cloud_scripts_dir = conpaas_home + '/scripts/cloud'
agent_cfg_dir = conpaas_home + '/config/agent'
agent_scripts_dir = conpaas_home + '/scripts/agent'

# COMMENT (genc): the following line is temporarily commented, should be uncommented when we know how to reactivate ipop
# bootstrap = self.config_parser.get('manager', 'BOOTSTRAP')
# bootstrap = 'lesh'
director = self.config_parser.get('director', 'DIRECTOR_URL')
manager_ip = self.config_parser.get('manager', 'MANAGER_IP')


# Get contextualization script for the corresponding cloud
cloud_script_file = open(cloud_scripts_dir + '/' + cloud_type, 'r')
cloud_script = cloud_script_file.read()

# Get agent setup file
agent_setup_file = open(agent_scripts_dir + '/agent-setup', 'r')

agent_setup = Template(agent_setup_file.read()).safe_substitute(DIRECTOR=director)

# Get agent config file - add to the default one the one specific
# to the service if it exists
default_agent_cfg_file = open(agent_cfg_dir + '/default-agent.cfg')
Expand All @@ -552,7 +505,6 @@ def _generate_context_file(self, cloud, context_replacement={}, startup_script=N
CONPAAS_USER_ID=self._conpaas_user_id,
CONPAAS_SERVICE_ID=self._conpaas_service_id,
CONPAAS_APP_ID=self._conpaas_app_id,
CLOUD_TYPE=cloud_type,
# IPOP_BASE_NAMESPACE=self._ipop_base_namespace
)

Expand All @@ -566,9 +518,39 @@ def _generate_context_file(self, cloud, context_replacement={}, startup_script=N

if os.path.isfile(agent_cfg_dir + '/' + self._conpaas_service_type + '-agent.cfg'):
agent_cfg_file = open(agent_cfg_dir +'/' + self._conpaas_service_type + '-agent.cfg')
# agent_cfg += '\n' + Template(agent_cfg_file.read()).safe_substitute(CLOUD_TYPE=cloud_type,)
agent_cfg += '\n' + Template(agent_cfg_file.read()).safe_substitute(context_replacement)

return agent_cfg

def _generate_context_file(self, cloud, context_replacement={}, startup_script=None):
'''
the context file runs the scripts necessary on each node created
it's installing all the necessary dependencies for the service
on the cloud you are installing
'''
cloud_type = cloud.get_cloud_type()
# conpaas_home = self.config_parser.get('manager', 'CONPAAS_HOME')
conpaas_home = self.config_parser.get('conpaas', 'CONF_DIR')

cloud_scripts_dir = conpaas_home + '/scripts/cloud'
agent_scripts_dir = conpaas_home + '/scripts/agent'

# COMMENT (genc): the following line is temporarily commented, should be uncommented when we know how to reactivate ipop
# bootstrap = self.config_parser.get('manager', 'BOOTSTRAP')
director = self.config_parser.get('director', 'DIRECTOR_URL')

# Get contextualization script for the corresponding cloud
cloud_script_file = open(cloud_scripts_dir + '/' + cloud_type, 'r')
cloud_script = cloud_script_file.read()

# Get agent setup file
agent_setup_file = open(agent_scripts_dir + '/agent-setup', 'r')
agent_setup = Template(agent_setup_file.read()).safe_substitute(DIRECTOR=director)

# Get agent config file
agent_cfg = self.generate_config_file(context_replacement)

# Get agent start file - if none for this service, use the default one
if os.path.isfile(agent_scripts_dir +'/' + self._conpaas_service_type + '-agent-start'):
agent_start_file = open(agent_scripts_dir +'/' + self._conpaas_service_type + '-agent-start')
Expand All @@ -577,7 +559,6 @@ def _generate_context_file(self, cloud, context_replacement={}, startup_script=N
agent_start = agent_start_file.read()

# Get key and a certificate from CA
# agent_certs = self._get_certificate()
agent_certs = self._get_certificate(role="agent",
email="[email protected]",
cn="ConPaaS",
Expand All @@ -595,17 +576,7 @@ def _generate_context_file(self, cloud, context_replacement={}, startup_script=N
+ 'cat <<EOF > $ROOT_DIR/config.cfg\n'
+ agent_cfg + '\n' + 'EOF\n\n')

# COMMENT (genc): the following code copies the start script from the menager to agents
# i don't know if this can be possible at this point since we are at the director and agent
# startup scritps are at the manager

# # Get user-provided startup script's absolute path
# basedir = self.config_parser.get('manager', 'CONPAAS_HOME')
# startup_script = os.path.join(basedir, 'startup.sh')

# # Append user-provided startup script (if any)
# if os.path.isfile(startup_script):
# context_file += open(startup_script).read() + '\n'
if startup_script:
context_file += startup_script + '\n'

Expand All @@ -625,7 +596,6 @@ def __init__(self, user_id, app_id, vpn):
self.port = 443

def generate_config_file(self):
tmpl_values = {}
# cloud_name = cloud.get_cloud_name()
conpaas_home = self.config_parser.get('conpaas', 'CONF_DIR')
mngr_cfg_dir = os.path.join(conpaas_home, 'config', 'manager')
Expand All @@ -635,26 +605,9 @@ def generate_config_file(self):
else:
conpaas_deployment_name = 'conpaas'

cloud_sections = ['iaas']
if self.config_parser.has_option('iaas', 'OTHER_CLOUDS'):
cloud_sections.extend(
[cld_name for cld_name
in self.config_parser.get('iaas', 'OTHER_CLOUDS').split(',')
if self.config_parser.has_section(cld_name)])


def _extract_cloud_cfg(section_name):
tmpl_values['cloud_cfg'] += "["+section_name+"]\n"
for key, value in self.config_parser.items(section_name):
tmpl_values['cloud_cfg'] += key.upper() + " = " + value + "\n"

tmpl_values['cloud_cfg'] = ''
for section_name in cloud_sections:
_extract_cloud_cfg(section_name)

# Get manager config file
# mngr_cfg = file_get_contents(os.path.join(mngr_cfg_dir, 'default-manager.cfg'))
# TODO (genc): Don't forget about having two default manager files (delete one when done)
# mngr_cfg = file_get_contents(os.path.join(mngr_cfg_dir, 'default-manager.cfg'))
mngr_cfg = file_get_contents(os.path.join(mngr_cfg_dir, 'default-manager-new.cfg'))

# Modify manager config file setting the required variables
Expand Down Expand Up @@ -686,7 +639,6 @@ def _extract_cloud_cfg(section_name):
# # mngr_cfg = mngr_cfg.replace('%CLOUD_COST_PER_TIME%', cloud_cost_per_time);



# COMMENT (genc): the IPOP part is commented until we have a working IPOP

# # Check if we want to use IPOP. If so, add IPOP directives to manager
Expand All @@ -707,11 +659,7 @@ def _extract_cloud_cfg(section_name):
# if self.config_parser.has_option('conpaas', 'VPN_BOOTSTRAP_NODES'):
# mngr_cfg += '\nIPOP_BOOTSTRAP_NODES = %s' % self.config_parser.get('conpaas', 'VPN_BOOTSTRAP_NODES')

tmpl_values['mngr_cfg'] = mngr_cfg
return """
%(cloud_cfg)s
%(mngr_cfg)s
""" % tmpl_values
return mngr_cfg

def _generate_context_file(self, cloud, context_replacement={}, startup_script=None):
"""Override default _get_context_file. Here we generate the context
Expand Down
3 changes: 1 addition & 2 deletions conpaas-services/sbin/manager/default-cpsmanager
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ if __name__ == '__main__':
Verify some sections and variables that must exist in the configuration file
"""
config_vars = {
# 'manager': ['TYPE', 'BOOTSTRAP', 'LOG_FILE','CREDIT_URL', 'TERMINATE_URL', 'SERVICE_ID'],
# 'manager': ['TYPE', 'BOOTSTRAP', 'LOG_FILE', 'CREDIT_URL', 'TERMINATE_URL', 'SERVICE_ID'],
# 'manager': ['BOOTSTRAP', 'LOG_FILE', 'CREDIT_URL', 'TERMINATE_URL'],
'iaas': ['DRIVER'],
}
config_ok = True
for section in config_vars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
is_int, is_pos_nul_int, is_pos_int, is_dict, is_dict2, is_bool,\
is_uploaded_file

try:
from conpaas.services.webservers.manager.autoscaling.scaler import ProvisioningManager
except ImportError as ex:
provision_mng_error = "%s" % ex
ProvisioningManager = None
# try:
# from conpaas.services.webservers.manager.autoscaling.scaler import ProvisioningManager
# except ImportError as ex:
# provision_mng_error = "%s" % ex
ProvisioningManager = None

from multiprocessing.pool import ThreadPool

Expand All @@ -41,7 +41,7 @@ def __init__(self, config_parser, **kwargs):
self._create_initial_configuration()

if ProvisioningManager is None:
self.logger.info('Provisioning Manager can not be initialized: %s' % provision_mng_error)
# self.logger.info('Provisioning Manager can not be initialized: %s' % provision_mng_error)
self.scaler = None
else:
try:
Expand Down

0 comments on commit 7a19068

Please sign in to comment.