def display_services_ports(self): dns_started = docker.container_running('docker_dns') apache_url = '{}.docker'.format(self.get_vm_item('apache', 'name')) if dns_started is True else self.get_vm_item('apache', 'ip') puts('{} URL : http://{}'.format(colored.yellow('Web server'), apache_url)) if self.get_vm_item('mailcatcher', 'ip') != '': mailcatcher_ip = '{}.docker'.format(self.get_vm_item('mailcatcher', 'name')) if dns_started is True else self.get_vm_item('mailcatcher', 'ip') puts('For {} use : http://{}'.format(colored.yellow('mailcatcher'), mailcatcher_ip)) puts(' '*16 + 'and in your VM use the server "{}" with the port 25\n'.format(colored.yellow('mailcatcher'))) if self.get_vm_item('maildev', 'ip') != '': maildev_ip = '{}.docker'.format(self.get_vm_item('maildev', 'name')) if dns_started is True else self.get_vm_item('maildev', 'ip') puts('For {} use : http://{}'.format(colored.yellow('maildev'), maildev_ip)) puts(' '*12 + 'and in your VM use the server "{}" with the port 25\n'.format(colored.yellow('maildev'))) if self.get_vm_item('mongoclient', 'ip') != '': mongoclient_ip = '{}.docker'.format(self.get_vm_item('mongoclient', 'name')) if dns_started is True else self.get_vm_item('mongoclient', 'ip') puts('For {} use : http://{}:3000\n'.format(colored.yellow('mongoclient'), mongoclient_ip)) if self.get_vm_item('phpmyadmin', 'ip') != '': pma_ip = '{}.docker'.format(self.get_vm_item('phpmyadmin', 'name')) if dns_started is True else self.get_vm_item('phpmyadmin', 'ip') puts('For {} use : http://{}\n'.format(colored.yellow('phpMyAdmin'), pma_ip)) if self.get_vm_item('xhgui', 'ip') != '': xhgui_ip = '{}.docker'.format(self.get_vm_item('xhgui', 'name')) if dns_started is True else self.get_vm_item('xhgui', 'ip') puts('For {} use : http://{}\n'.format(colored.yellow('xhgui'), xhgui_ip))
def status(self): self.check_vms_are_running() dns_started = docker.container_running('docker_dns') puts( columns([(colored.green('VM')), 16], [(colored.green('HostName' if dns_started else 'IP')), 38], [(colored.green('Ports')), 25], [(colored.green('Image')), 25], [(colored.green('Docker ID')), 15], [(colored.green('Docker Name')), 25])) puts( columns(['-' * 16, 16], ['-' * 38, 38], ['-' * 25, 25], ['-' * 25, 25], ['-' * 15, 15], ['-' * 25, 25])) for vm_id, vm_data in self.vms.items(): if vm_data['ip'] == '': continue puts( columns([vm_data['compose_name'], 16], [ '{}.docker'.format(vm_data['name']) if dns_started else vm_data['ip'], 38 ], [', '.join(vm_data['ports']), 25], [vm_data['image'], 25], [vm_id[:12], 15], [vm_data['name'], 25]))
def display_services_ports(self): dns_started = docker.container_running('docker_dns') services_to_display = { 'apache': { 'name': 'Web Server', 'url': 'http://{URL}' }, 'mailcatcher': { 'name': 'Mailcatcher (fake SMTP)', 'url': 'http://{URL}', 'extra_port': 25 }, 'maildev': { 'name': 'Maildev (Fake SMTP)', 'url': 'http://{URL}', 'extra_port': 25 }, 'mongoclient': { 'name': 'MongoDB Client', 'url': 'http://{URL}:3000' }, 'phpmyadmin': { 'name': 'PhpMyAdmin', 'url': 'http://{URL}' }, 'xhgui': { 'name': 'XHGui (PHP Profiling)', 'url': 'http://{URL}' } } for service, options in sorted(services_to_display.items()): ip = self.get_vm_item(service, 'ip') if ip == '': continue url = options['url'].replace('{URL}', self.get_vm_item(service, 'ip')) if dns_started is True: url = options['url'].replace( '{URL}', '{}.docker'.format(self.get_vm_item(service, 'name'))) puts(' - For {}'.format(colored.yellow(options['name'])).ljust( 55, ' ') + ' : ' + url) if 'extra_port' in options: puts(' ' * 3 + ' ... and in your VM use the port {}'.format( options['extra_port'])) print('')
def manage_dns(self, action: str): dns_started = docker.container_running('docker_dns') if (dns_started is True and action == 'start') or (dns_started is False and action == 'stop'): puts( colored.red( "Can't {} the dns container as (already done?)".format( action, action))) sys.exit(1) if dns_started is True and action == 'stop': cmd = ['docker', 'stop', 'docker_dns'] subprocess.check_output(cmd) cmd = ['docker', 'rm', 'docker_dns'] subprocess.check_output(cmd) elif dns_started is False and action == 'start': self.docker_run_dns()
def manage_dns(self, action: str): dns_started = docker.container_running('docker_dns') if dns_started is True and action == 'start': puts(colored.red("Can't start the dns container as it's already started")) sys.exit(1) elif dns_started is False and action == 'stop': puts(colored.red("Can't stop the dns container as it's not running")) sys.exit(1) elif dns_started is True and action == 'stop': cmd = ['docker', 'stop', 'docker_dns'] subprocess.check_output(cmd) cmd = ['docker', 'rm', 'docker_dns'] subprocess.check_output(cmd) elif dns_started is False and action == 'start': cmd = ['docker', 'run', '-d', '--hostname', 'docker-dns', '--name', 'docker_dns'] cmd += ['-v', '/var/run/docker.sock:/tmp/docker.sock', '-v', '/etc/resolv.conf:/tmp/resolv.conf'] cmd += ['mgood/resolvable'] subprocess.check_output(cmd)