Commit 84cb17db authored by amjangde's avatar amjangde

init

parents
*.iso
__pycache__
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href="http://192.168.122.113:1080/.bash_history">.bash_history</a></li>
<li><a href="http://192.168.122.113:1080/.bash_logout">.bash_logout</a></li>
<li><a href="http://192.168.122.113:1080/.bashrc">.bashrc</a></li>
<li><a href="http://192.168.122.113:1080/.cache/">.cache/</a></li>
<li><a href="http://192.168.122.113:1080/.gnupg/">.gnupg/</a></li>
<li><a href="http://192.168.122.113:1080/.local/">.local/</a></li>
<li><a href="http://192.168.122.113:1080/.profile">.profile</a></li>
<li><a href="http://192.168.122.113:1080/.selected_editor">.selected_editor</a></li>
<li><a href="http://192.168.122.113:1080/.sudo_as_admin_successful">.sudo_as_admin_successful</a></li>
</ul>
<hr>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href="http://192.168.122.113:1080/.bash_history">.bash_history</a></li>
<li><a href="http://192.168.122.113:1080/.bash_logout">.bash_logout</a></li>
<li><a href="http://192.168.122.113:1080/.bashrc">.bashrc</a></li>
<li><a href="http://192.168.122.113:1080/.cache/">.cache/</a></li>
<li><a href="http://192.168.122.113:1080/.gnupg/">.gnupg/</a></li>
<li><a href="http://192.168.122.113:1080/.local/">.local/</a></li>
<li><a href="http://192.168.122.113:1080/.profile">.profile</a></li>
<li><a href="http://192.168.122.113:1080/.selected_editor">.selected_editor</a></li>
<li><a href="http://192.168.122.113:1080/.sudo_as_admin_successful">.sudo_as_admin_successful</a></li>
</ul>
<hr>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href="http://192.168.122.111:1080/.bash_history">.bash_history</a></li>
<li><a href="http://192.168.122.111:1080/.bash_logout">.bash_logout</a></li>
<li><a href="http://192.168.122.111:1080/.bashrc">.bashrc</a></li>
<li><a href="http://192.168.122.111:1080/.cache/">.cache/</a></li>
<li><a href="http://192.168.122.111:1080/.gnupg/">.gnupg/</a></li>
<li><a href="http://192.168.122.111:1080/.profile">.profile</a></li>
<li><a href="http://192.168.122.111:1080/.ssh/">.ssh/</a></li>
</ul>
<hr>
</body>
</html>
#!/usr/bin/env python3
import socket
HOST = '127.0.0.1' # The server's hostname or IP address
PORT = 65432 # The port used by the server
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.sendall(b'Hello, world')
data = s.recv(1024)
print('Received', repr(data))
\ No newline at end of file
#!/bin/sh
while true
do
wget 192.168.122.111:1080
done
\ No newline at end of file
import threading
import os
def func():
for i in range(10000):
os.system('wget --tries=inf --timestamping --convert-links --page-requisites --no-parent 192.168.122.113:1080')
if __name__ == "__main__":
t1 = threading.Thread(target=func)
t2 = threading.Thread(target=func)
t3 = threading.Thread(target=func)
t4 = threading.Thread(target=func)
t1.start()
t2.start()
t3.start()
t4.start()
t1.join()
t2.join()
t3.join()
t4.join()
print("Done!")
\ No newline at end of file
#!/usr/bin/env python3
import socket
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
\ No newline at end of file
--2020-03-14 18:35:21-- http://192.168.122.111:1080/
Connecting to 192.168.122.111:1080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 590 [text/html]
Saving to: ‘192.168.122.111:1080/index.html’
0K 100% 52.2M=0s
Last-modified header missing -- time-stamps turned off.
2020-03-14 18:35:21 (52.2 MB/s) - ‘192.168.122.111:1080/index.html’ saved [590/590]
FINISHED --2020-03-14 18:35:21--
Total wall clock time: 0.04s
Downloaded: 1 files, 590 in 0s (52.2 MB/s)
Converting links in 192.168.122.111:1080/index.html... 0-7
Converted links in 1 files in 0.001 seconds.
--2020-03-14 18:35:21-- http://192.168.122.111:1080/
Connecting to 192.168.122.111:1080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 590 [text/html]
Saving to: ‘192.168.122.111:1080/index.html’
0K 100% 61.0M=0s
Last-modified header missing -- time-stamps turned off.
2020-03-14 18:35:21 (61.0 MB/s) - ‘192.168.122.111:1080/index.html’ saved [590/590]
FINISHED --2020-03-14 18:35:21--
Total wall clock time: 0.03s
Downloaded: 1 files, 590 in 0s (61.0 MB/s)
Converting links in 192.168.122.111:1080/index.html... 0-7
Converted links in 1 files in 0 seconds.
import sys
import libvirt
import time
import spawnvm
# domName = 'server1'
conn = libvirt.open('qemu:///system')
if conn == None:
print('Failed to open connection to qemu:///system', file=sys.stderr)
exit(1)
doms = conn.listAllDomains()
active_doms = conn.listAllDomains(1)
inactive_doms = conn.listAllDomains(2)
# print(inactive_doms[0].name())
if(len(active_doms) == 0):
doms[0].create()
active_doms = conn.listAllDomains(1)
# dom = conn.lookupByName('server2')
# if dom == None:
# print('Failed to find the domain '+domName, file=sys.stderr)
# exit(1)
THRESHOLD = 20
dom = active_doms[0]
cpu_time = {}
curr_cpu_time = {}
count_up = {}
count_down = {}
for dom in active_doms:
state = dom.getCPUStats(True)
dom_name = dom.name()
cpu_time[dom_name] = state[0]['cpu_time'] / 1000000.
count_up[dom_name] = 0
count_down[dom_name] = 0
# cpu_stats = dom.getCPUStats(True)
# cpu_time = cpu_stats[0]['cpu_time']/1000000.
while True:
active_doms = conn.listAllDomains(1)
inactive_doms = conn.listAllDomains(2)
for dom in inactive_doms:
try:
del count_up[dom.name()]
except:
pass
try:
del count_down[dom.name()]
except:
pass
try:
del cpu_time[dom.name()]
except:
pass
for dom in active_doms:
state = dom.getCPUStats(True)
dom_name = dom.name()
curr_cpu_time = state[0]['cpu_time'] / 1000000.
if dom_name not in cpu_time.keys():
cpu_time[dom_name] = curr_cpu_time
if dom_name not in count_up.keys():
count_up[dom_name] = 0
if dom_name not in count_down.keys():
count_down[dom_name] = 0
if ((curr_cpu_time - cpu_time[dom_name]) > 100):
if(count_up[dom_name] <= THRESHOLD):
count_up[dom_name] = count_up[dom_name] + 1
print (dom_name + " count_up : " + str(count_up[dom_name]))
else :
count_up[dom_name] = 0
if (count_up[dom_name] == THRESHOLD):
print ("spawning vm")
spawnvm.spawn(conn)
elif((curr_cpu_time - cpu_time[dom_name]) < 50):
if(count_down[dom_name] <= THRESHOLD):
count_down[dom_name] = count_down[dom_name] + 1
print (dom_name + " count_down : " + str(count_down[dom_name]))
else:
count_down[dom_name] = 0
if (count_down[dom_name] == THRESHOLD):
if(len(active_doms) > 1):
spawnvm.shutdown(conn,dom)
cpu_time[dom_name] = curr_cpu_time
# cpu_stats = dom.getCPUStats(True)
# for (i, cpu) in enumerate(cpu_stats):
# curr_cpu_time = cpu['cpu_time'] / 1000000.
# print('CPU '+str(i)+' Time Diff: '+str(curr_cpu_time - cpu_time))
time.sleep(1)
conn.close()
exit(0)
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href=".bash_history">.bash_history</a></li>
<li><a href=".bash_logout">.bash_logout</a></li>
<li><a href=".bashrc">.bashrc</a></li>
<li><a href=".cache/">.cache/</a></li>
<li><a href=".gnupg/">.gnupg/</a></li>
<li><a href=".local/">.local/</a></li>
<li><a href=".profile">.profile</a></li>
<li><a href=".selected_editor">.selected_editor</a></li>
<li><a href=".sudo_as_admin_successful">.sudo_as_admin_successful</a></li>
</ul>
<hr>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href=".bash_history">.bash_history</a></li>
<li><a href=".bash_logout">.bash_logout</a></li>
<li><a href=".bashrc">.bashrc</a></li>
<li><a href=".cache/">.cache/</a></li>
<li><a href=".gnupg/">.gnupg/</a></li>
<li><a href=".local/">.local/</a></li>
<li><a href=".profile">.profile</a></li>
<li><a href=".selected_editor">.selected_editor</a></li>
<li><a href=".sudo_as_admin_successful">.sudo_as_admin_successful</a></li>
</ul>
<hr>
</body>
</html>
#!/usr/bin/env python
"""
Simple HTTP URL redirector
Shreyas Cholia 10/01/2015
usage: redirect.py [-h] [--port PORT] [--ip IP] redirect_url
HTTP redirect server
positional arguments:
redirect_url
optional arguments:
-h, --help show this help message and exit
--port PORT, -p PORT port to listen on
--ip IP, -i IP host interface to listen on
"""
import SimpleHTTPServer
import SocketServer
import sys
import argparse
def redirect_handler_factory(url):
"""
Returns a request handler class that redirects to supplied `url`
"""
class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(301)
self.send_header('Location', url)
self.end_headers()
return RedirectHandler
def main():
parser = argparse.ArgumentParser(description='HTTP redirect server')
parser.add_argument('--port', '-p', action="store", type=int, default=80, help='port to listen on')
parser.add_argument('--ip', '-i', action="store", default="", help='host interface to listen on')
parser.add_argument('redirect_url', action="store")
myargs = parser.parse_args()
redirect_url = myargs.redirect_url
port = myargs.port
host = myargs.ip
redirectHandler = redirect_handler_factory(redirect_url)
handler = SocketServer.TCPServer((host, port), redirectHandler)
print("serving at port %s" % port)
handler.handle_request()
if __name__ == "__main__":
main()
\ No newline at end of file
import libvirt
#connect to hypervisor running on localhost
def spawn (conn):
# conn = libvirt.open('qemu:///system')
inactive_doms = conn.listAllDomains(2)
if(len(inactive_doms) == 0):
print ("No VM to Spawn!")
else:
dom0 = inactive_doms[0]
try:
dom0.create()
print("spawning " + dom0.name())
except:
print("Already running")
def shutdown (conn, dom):
# conn = libvirt.open('qemu:///system')
# dom0 = conn.lookupByName(dom_name)
try:
print("Shutting down " + dom.name())
dom.shutdown()
except:
print("Not running")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment