Example #1
0
 def coreos_bootstrap(self):
     '''
     Install python dependencies on CoreOS
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e', 'ansible_python_interpreter=/opt/bin/python',
         '-u',  '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'coreos-bootstrap.yml')
     ]
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
             'Bootstrap CoreOS servers with python ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     display.banner('BOOTSTRAP COREOS')
     self.logger.info(
         'Bootstrapping CoreOS with the command: %s' % cmd
     )
     rcode, emsg = run_command('Bootstrapping CoreOS', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         self.kill_ssh_agent()
         sys.exit(1)
Example #2
0
 def coreos_bootstrap(self):
     '''
     Install python dependencies on CoreOS
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e', 'ansible_python_interpreter=/opt/bin/python',
         '-u',  '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'coreos-bootstrap.yml')
     ]
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
             'Bootstrap CoreOS servers with python ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     display.banner('BOOTSTRAP COREOS')
     self.logger.info(
         'Bootstrapping CoreOS with the command: %s' % cmd
     )
     rcode, emsg = run_command('Bootstrapping CoreOS', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         self.kill_ssh_agent()
         sys.exit(1)
Example #3
0
 def deploy_kubernetes(self):
     '''
     Run the ansible playbook command
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e',
         'kube_network_plugin=%s' % self.options['network_plugin'], '-u',
         '%s' % self.options['ansible_user'], '-b', '--become-user=root',
         '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'cluster.yml')
     ]
     # Configure the network subnets pods and k8s services
     if not validate_cidr(self.options['kube_network'], version=4):
         display.error('Invalid Kubernetes network address')
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
     svc_network, pods_network = self.get_subnets()
     cmd = cmd + [
         '-e',
         'kube_service_addresses=%s' % svc_network.cidr, '-e',
         'kube_pods_subnet=%s' % pods_network
     ]
     # Add any additionnal Ansible option
     if 'ansible_opts' in self.options.keys():
         cmd = cmd + self.options['ansible_opts'].split(' ')
     for cloud in ['aws', 'gce']:
         if self.options[cloud]:
             cmd = cmd + ['-e', 'cloud_provider=%s' % cloud]
     if not self.options['coreos']:
         self.check_ping()
     display.display('Kubernetes services network : %s (%s IPs)' %
                     (svc_network.cidr, str(svc_network.size.real - 2)),
                     color='bright gray')
     display.display('Pods network : %s (%s IPs)' %
                     (pods_network.cidr, str(pods_network.size.real - 2)),
                     color='bright gray')
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
                 'Run kubernetes cluster deployment with the above command ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     if self.options['coreos']:
         self.coreos_bootstrap()
         self.check_ping()
         cmd = cmd + ['-e', 'ansible_python_interpreter=/opt/bin/python']
     display.banner('RUN PLAYBOOK')
     self.logger.info('Running kubernetes deployment with the command: %s' %
                      cmd)
     rcode, emsg = run_command('Run deployment', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
     display.display('Kubernetes deployed successfuly', color='green')
     os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
Example #4
0
 def deploy_kubernetes(self):
     '''
     Run the ansible playbook command
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e', 'kube_network_plugin=%s' % self.options['network_plugin'],
         '-u',  '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'cluster.yml')
     ]
     # Configure the network subnets pods and k8s services
     if not validate_cidr(self.options['kube_network'], version=4):
         display.error('Invalid Kubernetes network address')
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
     svc_network, pods_network = self.get_subnets()
     # Add any additionnal Ansible option
     if 'ansible-opts' in self.options.keys():
         cmd = cmd + self.options['ansible-opts'].split(' ')
     for cloud in ['aws', 'gce']:
         if self.options[cloud]:
             cmd = cmd + ['-e', 'cloud_provider=%s' % cloud]
     if not self.options['coreos']:
         self.check_ping()
     display.display(
         'Kubernetes services network : %s (%s IPs)'
         % (svc_network.cidr, str(svc_network.size.real - 2)),
         color='bright gray'
     )
     display.display(
         'Pods network : %s (%s IPs)'
         % (pods_network.cidr, str(pods_network.size.real - 2)),
         color='bright gray'
     )
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
             'Run kubernetes cluster deployment with the above command ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     if self.options['coreos']:
         self.coreos_bootstrap()
         self.check_ping()
         cmd = cmd + ['-e', 'ansible_python_interpreter=/opt/bin/python']
     display.banner('RUN PLAYBOOK')
     self.logger.info(
         'Running kubernetes deployment with the command: %s' % cmd
     )
     rcode, emsg = run_command('Run deployment', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
     display.display('Kubernetes deployed successfuly', color='green')
     os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
Example #5
0
 def create_instances(self):
     '''Run ansible-playbook for instances creation'''
     cmd = [
         playbook_exec, '-i', self.localcfg, '-e',
         'ansible_connection=local', self.playbook
     ]
     if not self.options['assume_yes']:
         if not query_yes_no('Create %s instances on %s ?' %
                             (self.options['count'], self.cloud)):
             display.display('Aborted', color='red')
             sys.exit(1)
     rcode, emsg = run_command('Create %s instances' % self.cloud, cmd)
     if rcode != 0:
         self.logger.critical('Cannot create instances: %s' % emsg)
         sys.exit(1)
Example #6
0
 def check_ping(self):
     '''
      Check if hosts are reachable
     '''
     display.banner('CHECKING SSH CONNECTIONS')
     cmd = [
         ansible_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-u',
         '%s' % self.options['ansible_user'], '-b', '--become-user=root',
         '-m', 'ping', 'all', '-i', self.inventorycfg
     ]
     rcode, emsg = run_command('SSH ping hosts', cmd)
     if rcode != 0:
         self.logger.critical('Cannot connect to hosts: %s' % emsg)
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
     display.display('All hosts are reachable', color='green')
Example #7
0
 def coreos_bootstrap(self):
     '''
     Install python dependencies on CoreOS
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e', 'ansible_python_interpreter=/opt/bin/python', '-u',
         '%s' % self.options['ansible_user'], '-b', '--become-user=root',
         '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'coreos-bootstrap.yml')
     ]
     display.banner('BOOTSTRAP COREOS')
     self.logger.info('Bootstrapping CoreOS with the command: %s' % cmd)
     rcode, emsg = run_command('Bootstrapping CoreOS', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
Example #8
0
 def check_ping(self):
     '''
      Check if hosts are reachable
     '''
     display.banner('CHECKING SSH CONNECTIONS')
     cmd = [
         ansible_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-u', '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-m', 'ping', 'all',
         '-i', self.inventorycfg
     ]
     if self.options['coreos']:
         cmd = cmd + ['-e', 'ansible_python_interpreter=/opt/bin/python']
     rcode, emsg = run_command('SSH ping hosts', cmd)
     if rcode != 0:
         self.logger.critical('Cannot connect to hosts: %s' % emsg)
         self.kill_ssh_agent()
         sys.exit(1)
     display.display('All hosts are reachable', color='green')
Example #9
0
 def coreos_bootstrap(self):
     '''
     Install python dependencies on CoreOS
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e', 'ansible_python_interpreter=/opt/bin/python',
         '-u',  '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'coreos-bootstrap.yml')
     ]
     display.banner('BOOTSTRAP COREOS')
     self.logger.info(
         'Bootstrapping CoreOS with the command: %s' % cmd
     )
     rcode, emsg = run_command('Bootstrapping CoreOS', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
Example #10
0
 def check_ping(self):
     '''
      Check if hosts are reachable
     '''
     display.banner('CHECKING SSH CONNECTIONS')
     cmd = [
         ansible_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-u', '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-m', 'ping', 'all',
         '-i', self.inventorycfg
     ]
     if 'sshkey' in self.options.keys():
         cmd = cmd + ['--private-key', self.options['sshkey']]
     if self.options['coreos']:
         cmd = cmd + ['-e', 'ansible_python_interpreter=/opt/bin/python']
     rcode, emsg = run_command('SSH ping hosts', cmd)
     if rcode != 0:
         self.logger.critical('Cannot connect to hosts: %s' % emsg)
         self.kill_ssh_agent()
         sys.exit(1)
     display.display('All hosts are reachable', color='green')
Example #11
0
 def create_instances(self):
     '''Run ansible-playbook for instances creation'''
     cmd = [
         playbook_exec, '-i', self.localcfg, '-e',
         'ansible_connection=local', self.playbook
     ]
     if not self.options['assume_yes']:
         if self.options['add_node']:
             display.warning(
                 '%s node(s) will be added to the current inventory %s' %
                 (str(self.options['count']), self.inventorycfg)
             )
         if not query_yes_no('Create %s instances on %s ?' % (
             self.options['count'], self.cloud
             )
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     rcode, emsg = run_command('Create %s instances' % self.cloud, cmd)
     if rcode != 0:
         self.logger.critical('Cannot create instances: %s' % emsg)
         sys.exit(1)
Example #12
0
 def deploy_kubernetes(self):
     '''
     Run the ansible playbook command
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-e',
         'kube_network_plugin=%s' % self.options['network_plugin'], '-u',
         '%s' % self.options['ansible_user'], '-b', '--become-user=root',
         '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'cluster.yml')
     ]
     if 'ansible-opts' in self.options.keys():
         cmd = cmd + self.options['ansible-opts'].split(' ')
     for cloud in ['aws', 'gce']:
         if self.options[cloud]:
             cmd = cmd + ['-e', 'cloud_provider=%s' % cloud]
     if not self.options['coreos']:
         self.check_ping()
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
                 'Run kubernetes cluster deployment with the above command ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     if self.options['coreos']:
         self.coreos_bootstrap()
         self.check_ping()
     display.banner('RUN PLAYBOOK')
     self.logger.info('Running kubernetes deployment with the command: %s' %
                      cmd)
     rcode, emsg = run_command('Run deployment', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
         sys.exit(1)
     display.display('Kubernetes deployed successfuly', color='green')
     os.kill(int(os.environ.get('SSH_AGENT_PID')), signal.SIGTERM)
Example #13
0
 def create_instances(self):
     '''Run ansible-playbook for instances creation'''
     cmd = [
         playbook_exec, '-i', self.localcfg, '-e',
         'ansible_connection=local', self.playbook
     ]
     if not self.options['assume_yes']:
         count = 0
         for role in ['masters', 'nodes', 'etcds']:
             if '%s_count' % role in self.options.keys():
                 count = count + self.options['%s_count' % role]
         if self.options['add_node']:
             display.warning(
                 '%s node(s) will be added to the current inventory %s' %
                 (count, self.inventorycfg)
             )
         if not query_yes_no('Create %s instances on %s ?' % (count, self.cloud)):
             display.display('Aborted', color='red')
             sys.exit(1)
     rcode, emsg = run_command('Create %s instances' % self.cloud, cmd)
     if rcode != 0:
         self.logger.critical('Cannot create instances: %s' % emsg)
         sys.exit(1)
Example #14
0
 def deploy_kubernetes(self):
     '''
     Run the ansible playbook command
     '''
     cmd = [
         playbook_exec, '--ssh-extra-args', '-o StrictHostKeyChecking=no',
         '-u',  '%s' % self.options['ansible_user'],
         '-b', '--become-user=root', '-i', self.inventorycfg,
         os.path.join(self.options['kargo_path'], 'cluster.yml')
     ]
     # Configure network plugin if defined
     if 'network_plugin' in self.options.keys():
         cmd = cmd + ['-e',
             'kube_network_plugin=%s' % self.options['network_plugin']
             ]
     # Configure the network subnets pods and k8s services
     if 'kube_network' in self.options.keys():
         if not validate_cidr(self.options['kube_network'], version=4):
             display.error('Invalid Kubernetes network address')
             self.kill_ssh_agent()
             sys.exit(1)
         svc_network, pods_network = self.get_subnets()
         cmd = cmd + [
             '-e', 'kube_service_addresses=%s' % svc_network.cidr,
             '-e', 'kube_pods_subnet=%s' % pods_network
         ]
     # Set kubernetes version
     if 'kube_version' in self.options.keys():
         available_kube_versions = self.read_kube_versions()
         if self.options['kube_version'] not in available_kube_versions:
             display.error(
                 'Kubernetes version %s is not supported, available versions = %s' %
                 (self.options['kube_version'], ','.join(available_kube_versions))
             )
             sys.exit(1)
         cmd = cmd + ['-e', 'kube_version=%s' % self.options['kube_version']]
     # Add root password for the apiserver
     if 'k8s_passwd' in self.options.keys():
         cmd = cmd + ['-e', 'kube_api_pwd=%s' % self.options['k8s_passwd']]
     # Ansible verbose mode
     if 'verbose' in self.options.keys() and self.options['verbose']:
         cmd = cmd + ['-vvvv']
     # Add any additionnal Ansible option
     if 'ansible_opts' in self.options.keys():
         cmd = cmd + self.options['ansible_opts'].split(' ')
     for cloud in ['aws', 'gce']:
         if self.options[cloud]:
             cmd = cmd + ['-e', 'cloud_provider=%s' % cloud]
     if not self.options['coreos']:
         self.check_ping()
     if self.options['coreos']:
         self.coreos_bootstrap()
         self.check_ping()
         cmd = cmd + ['-e', 'ansible_python_interpreter=/opt/bin/python']
     if 'kube_network' in self.options.keys():
         display.display(
             'Kubernetes services network : %s (%s IPs)'
             % (svc_network.cidr, str(svc_network.size.real - 2)),
             color='bright gray'
         )
         display.display(
             'Pods network : %s (%s IPs)'
             % (pods_network.cidr, str(pods_network.size.real - 2)),
             color='bright gray'
         )
     display.display(' '.join(cmd), color='bright blue')
     if not self.options['assume_yes']:
         if not query_yes_no(
             'Run kubernetes cluster deployment with the above command ?'
         ):
             display.display('Aborted', color='red')
             sys.exit(1)
     display.banner('RUN PLAYBOOK')
     self.logger.info(
         'Running kubernetes deployment with the command: %s' % ' '.join(cmd)
     )
     rcode, emsg = run_command('Run deployment', cmd)
     if rcode != 0:
         self.logger.critical('Deployment failed: %s' % emsg)
         self.kill_ssh_agent()
         sys.exit(1)
     display.display('Kubernetes deployed successfuly', color='green')
     self.kill_ssh_agent()