ACCUEIL
SISR
CONTEXTES
Stages
- Lycée S. Valadon
-
Epreuves CCF
- Lycée S. Valadon
Epreuves BTS SIO 2011 :
Harmonisation CCF
Portefeuille de compétences professionnelles (Portfolio)
- Lycée S. Valadon
Epreuves BTS SIO 2011 :
# apt install curl jq
jq . : permet d'afficher proprement le fichier
Liens :
# curl -k -d "username=couderchon.jonathan@Valadon&password=****" \ https://10.187.36.13:8006/api2/json/access/ticket \ | jq --raw-output '.data.ticket' > TICKET
{"data": {"CSRFPreventionToken":"60B103E8:LTeodfGIXmqdZiNuFcOPDYLZErw", "username":"couderchon.jonathan@Valadon", "ticket":"PVE:couderchon.jonathan@Valadon:60B103E8::Parf/e7K+h54HnDNlmGeyoyXAnTV2Nr29T++5WKepaUAhcOTA7cpMHmINrjtyL02u85u2HQYuulPYOZbe4VGCAWB9G+izBoZxT5mmkig9uZXrol6n2PWsP/QwthTkuv/NybtUUzWb2OEAP6K2tBO/znRMTjl1LrLZHjaiR9L9wORFW3DcgMEXOGYppVhwxO0ddf5NxaE3/oAE3LuM3KelJjzVfTP9BNyJO96FMvzZHEk2gOvOzIEetQ81ZnUJp1bSc/3D+b02ZfZ5Uxa+ehmXkFmP308vxM9o25k6kEeeQacRHuUc6oI77Ghea3wWQoYuXTveq7LwdaD7vGo1+Be3Q==", "cap":{"dc":{},"access":{},"vms":{"VM.Config.Network":1,"VM.Clone":1,"VM.PowerMgmt":1,"VM.Migrate":1,"Permissions.Modify":1,"VM.Config.CPU":1,"VM.Config.Options":1,"VM.Snapshot.Rollback":1,"VM.Monitor":1,"VM.Audit":1,"VM.Config.Memory":1,"VM.Snapshot":1,"VM.Allocate":1,"VM.Config.Disk":1,"VM.Backup":1,"VM.Config.CDROM":1,"VM.Config.HWType":1,"VM.Console":1},"nodes":{},"storage":{"Datastore.AllocateSpace":1,"Datastore.Allocate":1,"Datastore.AllocateTemplate":1,"Datastore.Audit":1,"Permissions.Modify":1}} } }
# script de connexion a l'API Proxmox # paramètre 1 : nom_utilisateur@pam -> authentification Linux # : nom_utilisateur@Valadon -> authentification sur AD du lycee # parametre 2 : mot de passe curl -k -d "username=$1&password=$2" \ https://10.187.36.13:8006/api2/json/access/ticket > authentification echo $(<authentification) |jq --raw-output '.data.ticket' > TICKET echo $(<authentification) |jq --raw-output '.data.CSRFPreventionToken' > CSRFP
./connexion.sh : permet utiliser le script si dessus
# curl https://10.187.36.13:8006/api2/json/pools -k -b "PVEAuthCookie=$(<TICKET)" | jq .
{ "data": [ { "comment": "Stagiaire lycée Turgot", "poolid": "SN2020" }, { "poolid": "SIO2020_2" } ] }
{"data":[{ "maxdisk":8589934592, "status":"stopped", "netout":0, "lock":"", "name":"TacheVVM", "diskwrite":0, "uptime":0, "diskread":0, "vmid":"168", "swap":0, "cpus":1, "template":"", "maxmem":536870912, "disk":0, "type":"lxc", "mem":0, "netin":0, "maxswap":536870912, "cpu":0 }, {"template":"", "maxmem":536870912, "cpus":2, "swap":108994560, "pid":"11236", "diskread":15084810240, "vmid":"159", "uptime":4925691, "mem":81248256, "netin":61475211, "cpu":0.000262962067156847, "maxswap":536870912, "type":"lxc", "disk":"1600507904", "lock":"", "maxdisk":"8388009984", "status":"running", "netout":1983458, "diskwrite":81899520, "name":"surucuGLPI"}, {"disk":0,"type":"lxc","maxswap":536870912,"cpu":0,"mem":0,"netin":0,"uptime":0,"diskread":0,"vmid":"466","cpus":1,"swap":0,"template":"","maxmem":536870912,"name":"Drengal","diskwrite":0,"netout":0,"maxdisk":8589934592,"status":"stopped","lock":""},{"diskwrite":0,"name":"Faurie","lock":"","status":"stopped","maxdisk":8589934592,"netout":0,"mem":0,"netin":0,"cpu":0,"maxswap":536870912,"type":"lxc","disk":0,"template":"","maxmem":536870912,"cpus":1,"swap":0,"diskread":0,"vmid":"188","uptime":0},{"maxswap":536870912,"cpu":0,"netin":0,"mem":0,"type":"lxc","disk":0,"template":"","maxmem":536870912,"cpus":1,"swap":0,"diskread":0,"vmid":"173","uptime":0,"diskwrite":0,"name":"LilianJGLPI","lock":"","netout":0,"status":"stopped","maxdisk":8589934592},{"name":"Devoyon.gatien","diskwrite":0,"netout":0,"maxdisk":8589934592,"status":"stopped","lock":"","disk":0,"maxswap":536870912,"cpu":0,"mem":0,"netin":0,"type":"lxc","cpus":1,"swap":0,"diskread":0,"vmid":"167","uptime":0,"template":"","maxmem":536870912},{"disk":0,"mem":0,"netin":0,"maxswap":536870912,"cpu":0,"type":"lxc","swap":0,"cpus":1,"uptime":0,"diskread":0,"vmid":"42069","template":"","maxmem":536870912,"name":"JMVM","diskwrite":0,"maxdisk":8589934592,"status":"stopped","netout":0,"lock":""},{"swap":0,"cpus":1,"diskread":0,"uptime":0,"vmid":"191","template":"","maxmem":536870912,"disk":0,"mem":0,"netin":0,"cpu":0,"maxswap":536870912,"type":"lxc","status":"stopped","maxdisk":8589934592,"netout":0,"lock":"","name":"SURUCUDebian","diskwrite":0},{"status":"stopped","maxdisk":8589934592,"netout":0,"lock":"","name":"LilianJ","diskwrite":0,"cpus":1,"swap":0,"vmid":"400","diskread":0,"uptime":0,"template":"","maxmem":536870912,"disk":0,"netin":0,"mem":0,"cpu":0,"maxswap":536870912,"type":"lxc"},{"disk":0,"type":"lxc","mem":0,"netin":0,"cpu":0,"maxswap":536870912,"vmid":"161","diskread":0,"uptime":0,"swap":0,"cpus":1,"template":"","maxmem":536870912,"name":"test","diskwrite":0,"maxdisk":8589934592,"status":"stopped","netout":0,"lock":""},{"name":"LilianPPE","diskwrite":8425267200,"maxdisk":"8388009984","status":"running","netout":69471294,"lock":"","disk":"2659475456","type":"lxc","mem":544997376,"netin":1189497455,"cpu":0,"maxswap":1073741824,"diskread":31337537536,"pid":"550","uptime":5365133,"vmid":"244","cpus":1,"swap":469598208,"maxmem":1073741824,"template":""},{"diskread":0,"uptime":0,"vmid":"6969","swap":0,"cpus":1,"template":"","maxmem":536870912,"disk":0,"type":"lxc","maxswap":536870912,"cpu":0,"netin":0,"mem":0,"netout":0,"status":"stopped","maxdisk":8589934592,"lock":"","name":"HoutinVM","diskwrite":0},{"disk":0,"type":"lxc","maxswap":536870912,"cpu":0,"netin":0,"mem":0,"diskread":0,"vmid":"151","uptime":0,"cpus":1,"swap":0,"maxmem":536870912,"template":"","name":"root","diskwrite":0,"netout":0,"status":"stopped","maxdisk":8589934592,"lock":""},{"diskwrite":0,"name":"AdameGLPI","lock":"","netout":0,"maxdisk":8589934592,"status":"stopped","cpu":0,"maxswap":536870912,"netin":0,"mem":0,"type":"lxc","disk":0,"maxmem":536870912,"template":"","swap":0,"cpus":1,"uptime":0,"diskread":0,"vmid":"266"},{"name":"POTHINdebian","diskwrite":0,"netout":0,"status":"stopped","maxdisk":8589934592,"lock":"","disk":0,"maxswap":536870912,"cpu":0,"netin":0,"mem":0,"type":"lxc","cpus":1,"swap":0,"vmid":"176","diskread":0,"uptime":0,"template":"","maxmem":536870912},{"diskwrite":0,"name":"MenuTeddy","lock":"","status":"stopped","maxdisk":8589934592,"netout":0,"type":"lxc","netin":0,"mem":0,"maxswap":536870912,"cpu":0,"disk":0,"maxmem":536870912,"template":"","diskread":0,"uptime":0,"vmid":"170","swap":0,"cpus":1},{"diskwrite":290816,"name":"cjdebian","lock":"","netout":36104,"maxdisk":"8388009984","status":"running","maxswap":536870912,"cpu":0.0162928554752884,"netin":601694,"mem":96292864,"type":"lxc","disk":"1156427776","maxmem":536870912,"template":"","swap":8192,"cpus":1,"diskread":85889024,"pid":"10578","vmid":"269","uptime":2562}]}root@cjdebian:~#
# jq ".data[0].name,.data[0].vmid" listeTemp
Résultat de la commande :
"HoutinVM" "6969"
# jq ".data[].name,.data[].vmid" listeTemp
Résultat :
"HoutinVM" "root" "AdameGLPI" "POTHINdebian" "MenuTeddy" "cjdebian" "TacheVVM" "surucuGLPI" "Drengal" "Faurie" "LilianJGLPI" "Devoyon.gatien" "JMVM" "SURUCUDebian" "LilianJ" "test" "LilianPPE" "6969" "151" "266" "176" "170" "269" "168" "159" "466" "188" "173" "167" "42069" "191" "400" "161" "244"
# jq "[.data[].name,.data[].vmid"] listeTemp
Résultat :
[ "HoutinVM", "root", "AdameGLPI", "POTHINdebian", "MenuTeddy", "cjdebian", "TacheVVM", "surucuGLPI", "Drengal", "Faurie", "LilianJGLPI", "Devoyon.gatien", "JMVM", "SURUCUDebian", "LilianJ", "test", "LilianPPE", "6969", "151", "266", "176", "170", "269", "168", "159", "466", "188", "173", "167", "42069", "191", "400", "161", "244" ]
curl https://10.187.36.13:8006/api2/json/nodes/siohyp2/lxc -k -b "PVEAuthCookie=$(<TICKET)" > listeTemp echo $(<listeTemp) | jq --raw-output '.data[0].vmid'
echo $(<listeTemp) | jq --raw-output '"https://10.187.36.13:8006/api2/json/nodes/siohyp2/lxc/"+.data[].vmid+"/config"' | xargs curl -k -b "PVEAuthCookie=$(<TICKET)" | jq .data.net0
./listeVLAN.sh : permet utiliser le script si dessus
"name=eth0,bridge=vmbr352,firewall=1,hwaddr=66:31:83:40:0F:38,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=F2:E1:88:02:F1:6A,ip=dhcp,type=veth" "name=GoutenegreDebain,bridge=vmbr352,hwaddr=06:2A:99:68:52:BC,ip=dhcp,type=veth "name=eth0,bridge=vmbr352,firewall=1,hwaddr=1A:07:EC:78:B0:13,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=9A:80:4F:3E:AB:63,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=52:75:90:11:E2:E2,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=82:BC:15:14:F3:C3,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=1E:00:24:9C:AC:B9,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=96:78:BA:73:D7:23,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=82:A7:92:CC:F4:FE,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=AA:65:D8:8A:6D:8E,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=36:FD:DF:1E:8D:47,ip=dhcp,type=veth" "name=eth0,bridge=vmbr301,firewall=1,hwaddr=9A:03:2E:2D:C5:9C,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=AE:C9:58:83:B9:E2,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,gw=10.187.37.254,hwaddr=A6:BC:1B:AE:E6:E1,ip=10.187.37 eth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=FE:1A:C2:BB:AA:13,ip=dhcp,type=veth" "name=eth0,bridge=vmbr352,firewall=1,hwaddr=32:AF:71:5A:F7:99,ip=dhcp,type=veth"
echo $(<listeTemp) | jq --raw-output '"https://10.187.36.13:8006/api2/json/nodes/siohyp2/lx$ | xargs curl -k -b "PVEAuthCookie=$(<TICKET)" \ | jq '"nomVM="+.data.hostname+"-"+.data.net0'\ | sed "s/,hwaddr=/%/" | cut -d'%' -f1 \ | sed "s/,gw=/%/" | cut -d'%' -f1 \ | sed "s/,firewall/%/" | cut -d'%' -f1 > temp \
./vmidVLAN.sh : permet utiliser le script si dessus
"nomVM=POTHINdebian-name=eth0,bridge=vmbr352 "nomVM=AdameGLPI-name=eth0,bridge=vmbr352 "nomVM=root-name=GoutenegreDebain,bridge=vmbr352 "nomVM=HoutinVM-name=eth0,bridge=vmbr352 "nomVM=cjdebian-name=eth0,bridge=vmbr352 "nomVM=MenuTeddy-name=eth0,bridge=vmbr352 "nomVM=SURUCUDebian-name=eth0,bridge=vmbr352 "nomVM=JMVM-name=eth0,bridge=vmbr352 "nomVM=Devoyon.gatien-name=eth0,bridge=vmbr352 "nomVM=LilianJGLPI-name=eth0,bridge=vmbr352 "nomVM=Faurie-name=eth0,bridge=vmbr352 "nomVM=Drengal-name=eth0,bridge=vmbr352 "nomVM=surucuGLPI-name=eth0,bridge=vmbr301 "nomVM=TacheVVM-name=eth0,bridge=vmbr352 "nomVM=LilianPPE-name=eth0,bridge=vmbr352 "nomVM=test-name=eth0,bridge=vmbr352 "nomVM=LilianJ-name=eth0,bridge=vmbr352
# ls -l
# chmod +x nomscript.sh
# ./nomscript.sh
# sed : change une chaine de caractère par un caractère # cut : supprime un caractère / une chaine de caratère
liens :
—-