-
Notifications
You must be signed in to change notification settings - Fork 0
Play with docker task #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: souhair-patch-1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #! /bin/bash | ||
| # a script to create the second virtual machine | ||
| echo "create network bridge between first (192.168.18.10) and second (192.168.18.1) servers | ||
| .... | ||
| ...." | ||
| ip a | ||
| ip link add macvlan1 link eth0 type macvlan mode bridge | ||
| ip address add dev macvlan1 192.168.18.10/24 | ||
| ip link set macvlan1 up | ||
| ip a | ||
| echo "create tcp connection between first and second servers | ||
| .... | ||
| ...." | ||
| apk add tcpdump | ||
| tcpdump | ||
| echo "check connection with the second server | ||
| .... | ||
| ...." | ||
| ping 192.168.18.1 | ||
| echo "check the routes for first server | ||
| .... | ||
| ...." | ||
| ip route | ||
| echo "tcp connection between first(192.168.18.10) and third (192.168.4.100) servers | ||
| .... | ||
| ...." | ||
| tcpdump | ||
| echo "create sub netwoek with third server by routing | ||
| .... | ||
| ...." | ||
| ip route add 192.168.4.0/24 via 192.168.18.1 | ||
| echo "check connect with the third server (192.168.4.100) | ||
| .... | ||
| ...." | ||
| ping 192.168.4.100 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. infinity loop |
||
| echo "create a web server on port 5000 with third server as a client | ||
| .... | ||
| ...." | ||
| pip install flask | ||
| mkdir myapp | ||
| cd myapp | ||
| echo "web-server configration with requests: GET, PUT, POST | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. echo command should be used with PIPE syntax. So you need echo some text and than try to move output of this command to file like this: echo 'Hello world' > my_test_file.txt
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you want to use multiple raws, check this syntax https://stackoverflow.com/a/51864828 |
||
| ..load app.py from the File VM_A file or open the A_bash file and look at the end of it.. | ||
| ...." | ||
| vim app.py | ||
| python3 app.py | ||
|
|
||
| """ | ||
| from crypt import methods | ||
| from flask import Flask | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| @app.route("/", methods=['GET']) | ||
| def hello_world(): | ||
| return "<p>Hello, World!</p>" | ||
|
|
||
| @app.route("/", methods=['PUT']) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you try to change put and post requests to something better? for example, you can put and post some data and return it to html (hello world is just example) https://pythonbasics.org/flask-rest-api/ @app.route('/', methods=['PUT'])
def create_record():
record = json.loads(request.data)
with open('/tmp/data.txt', 'r') as f:
data = f.read()
if not data:
records = [record]
else:
records = json.loads(data)
records.append(record)
with open('/tmp/data.txt', 'w') as f:
f.write(json.dumps(records, indent=2))
return jsonify(record)
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, i will do it . Thank you) |
||
| def hello_world_put(): | ||
| return "<p>Hello, World!</p>" | ||
|
|
||
| @app.route("/", methods=['POST']) | ||
| def hello_world_post(): | ||
| return "<p>Hello, World!</p>" | ||
|
|
||
| app.run(host='0.0.0.0', port=5000) | ||
| """ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| echo "create network bridge between second (192.168.18.1) and first (192.168.18.10) servers | ||
| .... | ||
| ...." | ||
| ip a | ||
| ip link add macvlan1 link eth0 type macvlan mode bridge | ||
| ip address add dev macvlan1 192.168.18.1/24 | ||
| ip link set macvlan1 up | ||
| ip a | ||
| echo "create network bridge between second (192.168.4.1) and third (192.168.4.100) servers | ||
| .... | ||
| ...." | ||
| ip link add macvlan2 link eth0 type macvlan mode bridge | ||
| ip address add dev macvlan2 192.168.4.1/24 | ||
| ip link set macvlan2 up | ||
| ip a | ||
| echo "check connection with the third server | ||
| .... | ||
| ...." | ||
| ping 192.168.4.100 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. infinity loop |
||
| echo "check connection with the first server | ||
| .... | ||
| ...." | ||
| ping 192.168.18.10 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. infinity loop |
||
| echo "tcp connection between second (192.168.18.1) and first (192.168.18.10) servers | ||
| .... | ||
| ...." | ||
| apk add tcpdump | ||
| tcpdump -i macvlan1 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. infinity loop |
||
| echo "tcp connection between second(192.168.4.1) and third (192.168.4.100) servers | ||
| .... | ||
| ...." | ||
| tcpdump -i macvlan2 | ||
| echo "check the routes for second server | ||
| .... | ||
| ...." | ||
| ip route | ||
| echo "create tcp connection to listen to port 5000 | ||
| .... | ||
| ...." | ||
| tcpdump 'port 5000' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. infinity loop |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| echo "create network bridge between third (192.168.4.100) and second (192.168.4.1) servers | ||
| .... | ||
| ...." | ||
| ip a | ||
| ip link add macvlan1 link eth0 macvlan mode bridge | ||
| ip address add dev macvlan1 192.168.4.100/24 | ||
| ip link set macvlan1 up | ||
| ip a | ||
| echo "create tcp connection the third and second servers | ||
| .... | ||
| ...." | ||
| apk add tcpdump | ||
| tcpdump | ||
| echo "check connection with the second server | ||
| .... | ||
| ...." | ||
| ping 192.168.4.1 | ||
| echo "check the routes for second server | ||
| .... | ||
| ...." | ||
| ip route | ||
| echo "create sub netwoek with first server by routing | ||
| .... | ||
| ...." | ||
| ip route add 192.168.18.0/24 via 192.168.4.1 | ||
| echo "check connection with the first server | ||
| .... | ||
| ...." | ||
| ping 192.168.18.10 | ||
| echo "create tcp connection the third and first servers | ||
| .... | ||
| ...." | ||
| tcpdump | ||
| echo "send requests to the web-server on port 5000 | ||
| .... | ||
| ...." | ||
| curl 'http://192.168.18.10:5000' | ||
| curl -X POST 'http://192.168.18.10:5000' | ||
| curl -X PUT 'http://192.168.18.10:5000' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you run this script, in this raw you just open tcpdump and switch to tcpdump promt. bash script should be written as scrip run at once - so after run this script you should get VM with all apllied settings for task.
So, could you remove from this script all commands, that can broke your run - i think you need remove