Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ dmypy.json
# Pyre type checker
.pyre/
todo.txt
framework/install_scripts/ssh_keys/id_rsa
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"args": ["-e", "VLAN", "-m", "0"]
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"yaml.schemas": {
"https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json": "file:///home/erfan/Project/COSCO/deploy/playbooks/deploy.yaml"
}
}
9 changes: 6 additions & 3 deletions framework/agent/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ def hostDetailsVirtual(self):
disk = psutil.disk_usage('/')
data = subprocess.run("./scripts/calIPS_clock.sh", shell=True,stdout=subprocess.PIPE)
data = (data.stdout.decode()).splitlines()
bw = ((subprocess.run("sudo ethtool "+self.interface+" | grep Speed",shell=True,stdout=subprocess.PIPE)).stdout.decode()).split()[1][0:4]
# bw = ((subprocess.run("sudo ethtool "+self.interface+" | grep Speed",shell=True,stdout=subprocess.PIPE)).stdout.decode()).split()[1][0:4]
bw = 'Speed: 1000Mb/s'
payload ={
"Total_Memory": int(float(memory.total/(1024*1024))),
"Total_Disk": int(float(disk.total/(1024*1024))),
"Bandwidth": int(bw),
"clock": data[0],
"Bandwidth": int(bw.split()[1][0:4]),
"clock": 10.021380822,
"Ram_read": self.parse_io(data[3]),
"Ram_write": self.parse_io(data[4]),
"Disk_read": self.parse_io(data[1]),
Expand Down Expand Up @@ -92,6 +93,8 @@ def getContainersStat(self):
c_id = container['Id']
c_name = container['Names'][0].replace('/', '')
_, stats = self.containerClient.stats(c_id)
logging.debug('Stats here')
logging.debug(stats)
inspect_data = self.containerClient.dclient1.inspect_container(c_id)['State']
read_bytes = stats['blkio_stats']['io_service_bytes_recursive'][0]['value'] if stats['blkio_stats']['io_service_bytes_recursive'] else 0
write_bytes = stats['blkio_stats']['io_service_bytes_recursive'][1]['value'] if stats['blkio_stats']['io_service_bytes_recursive'] else 0
Expand Down
1 change: 0 additions & 1 deletion framework/agent/dockerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import docker
import requests
import configparser
import docker
import codes
import json
import os
Expand Down
22 changes: 19 additions & 3 deletions framework/config/VLAN_ansible.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
- hosts: all
become: true
vars:
ansible_python_interpreter: /usr/bin/python3
# ansible_python_interpreter: /usr/bin/python3
interface: 'etho'
ipaddr: "{{ ansible_eth0.ipv4.address }}"
# ipaddr: "{{ ansible_eth0.ipv4.address }}"
ipaddr: "{{ ansible_default_ipv4.address }}"
username: 'ansible'

tasks:
Expand All @@ -13,6 +14,7 @@
become: yes
wait_for_connection:
timeout: 200

# Add id_rsa to authorized keys
- name: Setup | authorized key upload
authorized_key: user={{ username }}
Expand Down Expand Up @@ -49,11 +51,19 @@
become: yes
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes

# Add CRIU PPA
- name: Add CRIU PPA
become: yes
ansible.builtin.apt_repository:
repo: ppa:criu/ppa
state: present

# Install apt packages
- name: Install required system packages
become: yes
apt: name={{ item }} state=latest update_cache=yes
loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'criu', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools', 'linux-tools-generic', 'linux-tools-4.15.0-72-generic', 'sysbench', 'ioping']
# loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'criu', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools', 'linux-tools-generic', 'linux-tools-4.15.0-72-generic', 'sysbench', 'ioping']
loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'criu', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools', 'linux-tools-generic', 'linux-tools-generic', 'sysbench', 'ioping']

# Install pip packages
- name: Installing flask_restful
Expand Down Expand Up @@ -230,14 +240,20 @@
- sudo systemctl disable systemd-timesyncd

- name: pull yolo
tags: ["docker"]
docker_image:
name: shreshthtuli/yolo
source: pull

- name: pull pocketsphinx
tags: ["docker"]
docker_image:
name: shreshthtuli/pocketsphinx
source: pull

- name: pull aeneas
tags: ["docker"]
docker_image:
name: shreshthtuli/aeneas
source: pull

44 changes: 22 additions & 22 deletions framework/config/VLAN_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@
"uname" : "ansible",
"servers" : [
{
"ip" : "40.120.48.202",
"ip" : "91.246.44.159",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "52.151.65.50",
"ip" : "91.246.44.165",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "52.151.71.102",
"ip" : "91.246.44.154",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "52.151.70.150",
"ip" : "91.246.44.164",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "51.143.158.189",
"cpu" : 4,
"powermodel": "PMB4ms"
"ip" : "91.246.44.175",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "51.141.235.163",
"cpu" : 4,
"powermodel": "PMB4ms"
"ip" : "91.246.44.171",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "40.88.7.64",
"cpu" : 4,
"powermodel": "PMB4ms"
"ip" : "91.246.44.181",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "40.88.144.160",
"cpu" : 4,
"powermodel": "PMB4ms"
"ip" : "91.246.44.168",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "52.142.12.155",
"cpu" : 8,
"powermodel": "PMB8ms"
"ip" : "91.246.44.211",
"cpu" : 2,
"powermodel": "PMB2s"
},
{
"ip" : "40.88.32.92",
"cpu" : 8,
"powermodel": "PMB8ms"
"ip" : "91.246.44.185",
"cpu" : 2,
"powermodel": "PMB2s"
}
]
}
Expand Down
20 changes: 20 additions & 0 deletions framework/config/docker-proxy-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sudo vim /etc/netplan/50-cloud-init.yaml

addresses:
- 8.8.8.8

sudo netplan apply

sudo mkdir /etc/systemd/system/docker.service.d
sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://[username]:[password]@[proxy_address]:3832"
Environment="HTTPS_PROXY=http://[username]:[password`]@[proxy_address]:3832"

sudo systemctl daemon-reload
sudo systemctl restart docker

docker pull shreshthtuli/yolo
docker pull shreshthtuli/pocketsphinx
docker pull shreshthtuli/aeneas
20 changes: 10 additions & 10 deletions framework/config/hosts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[agents]
51.145.102.71 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
20.49.186.194 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
51.11.145.199 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
51.11.145.24 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
51.132.237.3 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
51.11.148.95 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
104.211.28.29 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
40.114.36.185 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
52.249.252.28 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
40.121.43.239 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.159 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.165 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.154 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.164 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.175 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.171 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.181 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.168 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.211 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
91.246.44.185 ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible
32 changes: 32 additions & 0 deletions framework/config/server_setup/server_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

password=123ansible

# Call the Python script and store the output (IP addresses)
ips=$(python servers_json.py)

# Loop over each IP address
for ip in $ips
do
echo "Starting process for server with IP: $ip"

# Connect to the server as 'ubuntu', create the 'ansible' user with sudo access
ssh -o StrictHostKeyChecking=no ubuntu@$ip "
sudo useradd -m ansible
echo 'ansible:${password}' | sudo chpasswd
sudo bash -c 'echo \"ansible ALL=(ALL:ALL) ALL\" >> /etc/sudoers'
"

echo "User creation completed for server with IP: $ip"

# Test the connection with new 'ansible' user
sshpass -p $password ssh -o StrictHostKeyChecking=no -q ansible@$ip exit

if [ $? -eq 0 ]; then
echo "Successfully connected to server with IP: $ip using 'ansible' user"
else
echo "Failed to connect to server with IP: $ip using 'ansible' user"
fi

echo "Completed process for server with IP: $ip"
done
13 changes: 13 additions & 0 deletions framework/config/server_setup/servers_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json

def get_ips_from_json(file):
with open(file, 'r') as f:
data = json.load(f)
servers = data["vlan"]["servers"]
ips = [server["ip"] for server in servers]
return ips

if __name__ == "__main__":
ips = get_ips_from_json('/home/erfan/Project/COSCO/framework/config/VLAN_config.json')
for ip in ips:
print(ip)
2 changes: 1 addition & 1 deletion framework/datacenter/Datacenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def generateHosts(self):
for i, data in enumerate(outputHostsData):
IP = self.hosts[i]
logging.error("Host details collected from: {}".format(IP))
print(color.BOLD+IP+color.ENDC, data)
print(color.BOLD+IP+color.ENDC, data)
IPS = (instructions * config[self.env.lower()]['servers'][i]['cpu'])/(float(data['clock']) * 1000000) if self.env_type == 'Virtual' else data['MIPS']
Power = eval(powermodels[i]+"()")
Ram = RAM(data['Total_Memory'], data['Ram_read'], data['Ram_write'])
Expand Down
27 changes: 19 additions & 8 deletions framework/datacenter/Datacenter_Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,36 @@ def run_cmd_pwd(cmd, password):
os.system("bash -c \"echo "+password+" | sudo -S "+cmd+" &> /dev/null\"")

def run_cmd(cmd):
os.system("bash -c \""+cmd+"\"")
venv_path = '/home/erfan/Project/env'
os.system(f"bash -c 'source {venv_path}/bin/activate | {cmd}'")


def run_cmd_pwd_venv(cmd, password):
venv_path = '/home/erfan/Project/env'
os.system(f"bash -c 'source {venv_path}/bin/activate && echo {password} | sudo -S {cmd}'")
# os.system(f"bash -c 'source {venv_path}/bin/activate && echo {password} | sudo -S {cmd} &> /dev/null'")


def setupVLANEnvironment(cfg, mode):
with open(cfg, "r") as f:
config = json.load(f)
HOST_IPS = [server['ip'] for server in config['vlan']['servers']]
if mode in [0, 1]:
MAIN_DIR = os.getcwd().replace('\\', '/').replace('C:', '/mnt/c')
password = getpass(color.BOLD+'Please enter linux password:'+color.ENDC)
run_cmd_pwd("rm /etc/ansible/hosts", password)
run_cmd_pwd("cp framework/install_scripts/ssh_keys/id_rsa ~/id_rsa", password)
run_cmd_pwd("cp framework/install_scripts/ssh_keys/id_rsa.pub ~/id_rsa.pub", password)
# password = getpass(color.BOLD+'Please enter linux password:'+color.ENDC)
password = "451379"
run_cmd_pwd_venv("rm /etc/ansible/hosts", password)
run_cmd_pwd_venv("cp framework/install_scripts/ssh_keys/id_rsa ~/id_rsa", password)
run_cmd_pwd_venv("cp framework/install_scripts/ssh_keys/id_rsa.pub ~/id_rsa.pub", password)
with open("framework/config/hosts", "w") as f:
f.write("[agents]\n")
for ip in HOST_IPS:
f.write(ip+" ansible_ssh_private_key_file=~/id_rsa ansible_ssh_user=ansible\n")
run_cmd_pwd("cp framework/config/hosts /etc/ansible/hosts", password)
run_cmd_pwd("cp framework/config/ansible.cfg /etc/ansible/ansible.cfg", password)
run_cmd("ansible-playbook framework/config/VLAN_ansible.yml")
# run_cmd_pwd_venv("cp framework/config/hosts /etc/ansible/hosts", password)
# run_cmd_pwd_venv("cp framework/config/ansible.cfg /etc/ansible/ansible.cfg", password)
# run_cmd("ansible-playbook -i framework/config/hosts framework/config/VLAN_ansible.yml -v", password)
run_cmd("ansible-playbook -i framework/config/hosts framework/config/VLAN_ansible.yml -v")
# run_cmd("ansible-playbook -i framework/config/hosts framework/config/VLAN_ansible.yml -v --tags docker")
uname = "ansible"
for ip in HOST_IPS:
res = os.system("ssh -o StrictHostKeyChecking=no -i framework/install_scripts/ssh_keys/id_rsa "+uname+"@"+ip+" /home/ansible/agent/scripts/delete.sh > /dev/null 2>&1")
Expand Down
38 changes: 0 additions & 38 deletions framework/install_scripts/ssh_keys/id_rsa

This file was deleted.

2 changes: 1 addition & 1 deletion framework/install_scripts/ssh_keys/id_rsa.pub
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDKyFiJIC33YGNuoDRD8Gr2fwoPlwCPTGnCnnjZviTZXmaTqhDh9MJCElPxh7/lbI4DJf+ePl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