text stringlengths 0 93.6k |
|---|
# shutit.send_and_match_output(send, matches) |
# - Returns True if any lines in output match any of |
# the regexp strings in the matches list |
# shutit.send_until(send,regexps) - Send command over and over until one of the regexps seen in the output. |
# shutit.run_script(script) - Run the passed-in string as a script |
# shutit.install(package) - Install a package |
# shutit.remove(package) - Remove a package |
# shutit.login(user='root', command='su -') |
# - Log user in with given command, and set up prompt and expects. |
# Use this if your env (or more specifically, prompt) changes at all, |
# eg reboot, bash, ssh |
# shutit.logout(command='exit') - Clean up from a login. |
# |
# COMMAND HELPER FUNCTIONS |
# shutit.add_to_bashrc(line) - Add a line to bashrc |
# shutit.get_url(fname, locations) - Get a file via url from locations specified in a list |
# shutit.get_ip_address() - Returns the ip address of the target |
# shutit.command_available(command) - Returns true if the command is available to run |
# |
# LOGGING AND DEBUG |
# shutit.log(msg,add_final_message=False) - |
# Send a message to the log. add_final_message adds message to |
# output at end of build |
# shutit.pause_point(msg='') - Give control of the terminal to the user |
# shutit.step_through(msg='') - Give control to the user and allow them to step through commands |
# |
# SENDING FILES/TEXT |
# shutit.send_file(path, contents) - Send file to path on target with given contents as a string |
# shutit.send_host_file(path, hostfilepath) |
# - Send file from host machine to path on the target |
# shutit.send_host_dir(path, hostfilepath) |
# - Send directory and contents to path on the target |
# shutit.insert_text(text, fname, pattern) |
# - Insert text into file fname after the first occurrence of |
# regexp pattern. |
# shutit.delete_text(text, fname, pattern) |
# - Delete text from file fname after the first occurrence of |
# regexp pattern. |
# shutit.replace_text(text, fname, pattern) |
# - Replace text from file fname after the first occurrence of |
# regexp pattern. |
# ENVIRONMENT QUERYING |
# shutit.host_file_exists(filename, directory=False) |
# - Returns True if file exists on host |
# shutit.file_exists(filename, directory=False) |
# - Returns True if file exists on target |
# shutit.user_exists(user) - Returns True if the user exists on the target |
# shutit.package_installed(package) - Returns True if the package exists on the target |
# shutit.set_password(password, user='') |
# - Set password for a given user on target |
# |
# USER INTERACTION |
# shutit.get_input(msg,default,valid[],boolean?,ispass?) |
# - Get input from user and return output |
# shutit.fail(msg) - Fail the program and exit with status 1 |
# |
vagrant_image = shutit.cfg[self.module_id]['vagrant_image'] |
vagrant_provider = shutit.cfg[self.module_id]['vagrant_provider'] |
module_name = 'docker_101_tutorial_' + ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(6)) |
shutit.send('rm -rf /tmp/' + module_name + ' && mkdir -p /tmp/' + module_name + ' && cd /tmp/' + module_name) |
shutit.send('vagrant init ' + vagrant_image) |
shutit.send('vagrant up --provider virtualbox',timeout=99999) |
shutit.login(command='vagrant ssh') |
shutit.login(command='sudo su -',password='vagrant') |
# DOCKER SETUP |
shutit.install('docker.io') |
shutit.send('docker pull centos') |
shutit.send('cat /etc/issue',note='We are in an ubuntu vm') |
shutit.send('yum',check_exit=False,note='yum is not available, for example') |
# DOCKER RUN |
shutit.login('docker run -ti --name docker-101-centos centos /bin/bash',note='Run up a centos docker image and attach to it with the bash command.',timeout=999) |
shutit.install('iproute') |
shutit.send('ps -ef',note='We are in a container, only the bash process is running') |
shutit.send('ip route',note='We have our own network stack') |
shutit.send('whoami',note='By default I am root') |
shutit.send('ls',note='And we have our own filesystem') |
shutit.logout(note='log out of the bash shell, terminating the container - type exit') |
# DOCKER PS |
shutit.send('docker ps -a',note='That container is still there, but not running because the bash process terminated when we logged out.') |
# DOCKER RM |
shutit.send('docker rm docker-101-centos',note='Remove the container.') |
shutit.send('docker ps -a',note='The container has gone.') |
shutit.send('echo',note='Next we start up 100 containers.') |
for i in range(1,100): |
shutit.send('docker run -d --name centos_container_' + str(i) + ' centos sleep infinity',timeout=500) |
shutit.send('docker ps',note='Show all 100 containers.') |
# DOCKER EXEC |
shutit.login(command='docker exec -ti centos_container_1 /bin/bash',note='Log onto container 1 to create a file that only exists in that container') |
shutit.send('pwd',note='We start in the root folder.') |
shutit.send('touch myfile',note='Create file: myfile.') |
shutit.send('ls',note='The file is there.') |
shutit.logout(note='log out of the bash shell - type exit') |
shutit.login('docker exec -ti centos_container_2 /bin/bash',note='Log onto container 2 to show the file is not there.') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.