Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SAE203-Solution_informatique_entreprise
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ROLLAND Valentin
SAE203-Solution_informatique_entreprise
Commits
21090b09
Commit
21090b09
authored
2 months ago
by
ROLLAND Valentin
Browse files
Options
Downloads
Patches
Plain Diff
remodelement add dhcp + ajout des requirements.txt
parent
a1d84959
No related branches found
No related tags found
No related merge requests found
Pipeline
#48894
failed
2 months ago
Stage: build
Stage: test
Stage: dast
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
add-dhcp-client.py
+15
-10
15 additions, 10 deletions
add-dhcp-client.py
requirements.txt
+3
-0
3 additions, 0 deletions
requirements.txt
with
18 additions
and
10 deletions
add-dhcp-client.py
+
15
−
10
View file @
21090b09
...
...
@@ -38,28 +38,33 @@ def add_dhcp_client(mac: str, ip: str):
result
=
cnx
.
run
(
f
"
sudo cat
{
chemin_config_dnsmasq
}
"
,
hide
=
True
)
contenu_dhcp
=
result
.
stdout
.
strip
().
split
(
"
\n
"
)
# Variables pour tracker les conflits
mac_existe
=
False
mac_ancienne_ip
=
None
for
ligne
in
contenu_dhcp
:
ligne
=
ligne
.
split
(
"
,
"
)
ip_config
=
ligne
[
1
]
mac_config
=
ligne
[
0
].
split
(
"
=
"
)
# Vérifie si l'ip n'est pas déja attribuée
if
ip
==
ip_config
:
print
(
"
ERREUR : IP déjà attribuée
"
)
print
(
f
"
ERREUR : IP déjà attribuée
à
{
mac_config
[
1
]
}
"
)
return
# Si on arrive ici, c'est que l'IP n'est pas déjà attribuée
for
ligne
in
contenu_dhcp
:
ligne
=
ligne
.
split
(
"
,
"
)
# Vérifier si la MAC existe déjà
if
mac
==
mac_config
[
1
]:
mac_existe
=
True
mac_ancienne_ip
=
ip_config
ip_config
=
ligne
[
1
]
mac_config
=
ligne
[
0
].
split
(
"
=
"
)
if
mac_existe
:
print
(
f
"
MAC
{
mac
}
déjà attribuée à l
'
IP
{
mac_ancienne_ip
}
"
)
print
(
f
"
Changement de l
'
adresse IP vers :
{
ip
}
"
)
# Vérifie si la mac n'est pas déja attribuée
if
mac
==
mac_config
[
1
]:
print
(
"
\n
MAC déjà attribuée à l
'
adresse IP :
"
,
ip_config
,
"
\n
Changement de l
'
adresse IP par :
"
,
ip
)
# Supprimer l'ancienne entrée
cnx
.
run
(
f
"
sudo sed -i
'
/
{
mac
}
/d
'
{
chemin_config_dnsmasq
}
"
,
hide
=
True
)
cnx
.
run
(
f
"
sudo sed -i
'
/
{
mac
}
/d
'
{
chemin_config_dnsmasq
}
"
,
hide
=
True
)
# On supprime la ligne contenant la MAC
cnx
.
run
(
f
"
echo dhcp-host=
{
mac
}
,
{
ip
}
| sudo tee -a
{
chemin_config_dnsmasq
}
"
,
hide
=
True
)
print
(
f
"
Configuration ajoutée : dhcp-host=
{
mac
}
,
{
ip
}
dans
{
chemin_config_dnsmasq
}
"
)
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
0 → 100644
+
3
−
0
View file @
21090b09
fabric
~=3.2.2
yaml
~=0.2.5
pyyaml
~=6.0.2
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment