コード例 #1
0
ファイル: deploy.py プロジェクト: joshuacox/kargo-cli
 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)
コード例 #2
0
ファイル: deploy.py プロジェクト: pcm32/kargo-cli
 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)
コード例 #3
0
ファイル: deploy.py プロジェクト: Krylon360/kargo-cli
 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)
コード例 #4
0
ファイル: deploy.py プロジェクト: fuhbar/kargo-cli
 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)
コード例 #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)
コード例 #6
0
ファイル: cloud.py プロジェクト: Krylon360/kargo-cli
 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)
コード例 #7
0
ファイル: deploy.py プロジェクト: syed/kargo-cli
 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)
コード例 #8
0
ファイル: cloud.py プロジェクト: shiywang/kargo-cli
 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)
コード例 #9
0
ファイル: deploy.py プロジェクト: donchh/kargo-cli
 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()