3939import requests
4040from rich .console import Console
4141from rich .panel import Panel
42- from rich .progress import Progress , SpinnerColumn , TextColumn , BarColumn , TimeElapsedColumn , TimeRemainingColumn
42+ from rich .progress import (
43+ Progress ,
44+ SpinnerColumn ,
45+ TextColumn ,
46+ BarColumn ,
47+ TimeElapsedColumn ,
48+ TimeRemainingColumn ,
49+ )
4350from rich .rule import Rule
4451from rich import box
4552
@@ -60,7 +67,7 @@ def check_infrahub_ready(max_retries: int = 30, sleep_time: int = 2) -> bool:
6067 style = "magenta" ,
6168 complete_style = "bright_green" ,
6269 finished_style = "bold bright_green" ,
63- pulse_style = "bright_magenta"
70+ pulse_style = "bright_magenta" ,
6471 ),
6572 TextColumn ("[bold bright_cyan]{task.percentage:>3.0f}%" ),
6673 TextColumn ("•" , style = "dim" ),
@@ -83,37 +90,41 @@ def check_infrahub_ready(max_retries: int = 30, sleep_time: int = 2) -> bool:
8390 time .sleep (sleep_time )
8491
8592 console .print ()
86- console .print (Panel (
87- "[red]✗ ERROR: Infrahub is not responding[/red]\n \n "
88- "[dim]Please ensure Infrahub is running with:[/dim]\n "
89- " [bold]uv run invoke start[/bold]\n \n "
90- "[dim]Check container status with:[/dim]\n "
91- " [bold]docker ps[/bold]" ,
92- title = "Connection Error" ,
93- border_style = "red" ,
94- box = box .SIMPLE
95- ))
93+ console .print (
94+ Panel (
95+ "[red]✗ ERROR: Infrahub is not responding[/red]\n \n "
96+ "[dim]Please ensure Infrahub is running with:[/dim]\n "
97+ " [bold]uv run invoke start[/bold]\n \n "
98+ "[dim]Check container status with:[/dim]\n "
99+ " [bold]docker ps[/bold]" ,
100+ title = "Connection Error" ,
101+ border_style = "red" ,
102+ box = box .SIMPLE ,
103+ )
104+ )
96105 return False
97106
98107
99- def run_command (command : str , description : str , step : str , color : str = "cyan" , icon : str = "" ) -> bool :
108+ def run_command (
109+ command : str , description : str , step : str , color : str = "cyan" , icon : str = ""
110+ ) -> bool :
100111 """Run a shell command and display output."""
101112 icon_display = f"{ icon } " if icon else ""
102- console .print (f"\n [bold { color } on black]{ step } [/bold { color } on black] { icon_display } [bold white]{ description } [/bold white]" )
113+ console .print (
114+ f"\n [bold { color } on black]{ step } [/bold { color } on black] { icon_display } [bold white]{ description } [/bold white]"
115+ )
103116
104117 try :
105- subprocess .run (
106- command ,
107- shell = True ,
108- check = True ,
109- capture_output = False ,
110- text = True
111- )
118+ subprocess .run (command , shell = True , check = True , capture_output = False , text = True )
112119 # Use the step's color for the completion message with a colored background box and matching icon
113- console .print (f"[bold bright_green on black]✓[/bold bright_green on black] { icon_display } [bold { color } ]{ description } completed[/bold { color } ]" )
120+ console .print (
121+ f"[bold bright_green on black]✓[/bold bright_green on black] { icon_display } [bold { color } ]{ description } completed[/bold { color } ]"
122+ )
114123 return True
115124 except subprocess .CalledProcessError as e :
116- console .print (f"[bold red]✗[/bold red] { icon_display } [red]Failed: { description } [/red]" )
125+ console .print (
126+ f"[bold red]✗[/bold red] { icon_display } [red]Failed: { description } [/red]"
127+ )
117128 console .print (f"[dim]Error: { e } [/dim]" )
118129 return False
119130
@@ -128,7 +139,7 @@ def wait_for_repository_sync(seconds: int = 120) -> None:
128139 style = "yellow" ,
129140 complete_style = "bright_green" ,
130141 finished_style = "bold bright_green" ,
131- pulse_style = "bright_yellow"
142+ pulse_style = "bright_yellow" ,
132143 ),
133144 TextColumn ("[bold bright_cyan]{task.percentage:>3.0f}%" ),
134145 TextColumn ("•" , style = "dim" ),
@@ -143,25 +154,29 @@ def wait_for_repository_sync(seconds: int = 120) -> None:
143154 time .sleep (1 )
144155 progress .update (task , advance = 1 )
145156
146- console .print ("[bold bright_green on black]✓[/bold bright_green on black] 🔄 [bold bright_yellow]Repository sync complete[/bold bright_yellow]\n " )
157+ console .print (
158+ "[bold bright_green on black]✓[/bold bright_green on black] 🔄 [bold bright_yellow]Repository sync complete[/bold bright_yellow]\n "
159+ )
147160
148161
149162def main (branch : str = "main" ) -> int :
150163 """Main bootstrap function."""
151164 console .print ()
152- console .print (Panel (
153- f"[bold bright_blue]🚀 Infrahub Demo Bootstrap[/bold bright_blue]\n "
154- f"[bright_cyan]Branch:[/bright_cyan] [bold yellow]{ branch } [/bold yellow]\n \n "
155- "[dim]This will load:[/dim]\n "
156- " [blue]•[/blue] Schemas\n "
157- " [magenta]•[/magenta] Menu definitions\n "
158- " [yellow]•[/yellow] Bootstrap data\n "
159- " [green]•[/green] Security data\n "
160- " [bright_magenta]•[/bright_magenta] Demo repository" ,
161- border_style = "bright_blue" ,
162- box = box .SIMPLE ,
163- title = "[bold bright_blue]Bootstrap Process[/bold bright_blue]"
164- ))
165+ console .print (
166+ Panel (
167+ f"[bold bright_blue]🚀 Infrahub Demo Bootstrap[/bold bright_blue]\n "
168+ f"[bright_cyan]Branch:[/bright_cyan] [bold yellow]{ branch } [/bold yellow]\n \n "
169+ "[dim]This will load:[/dim]\n "
170+ " [blue]•[/blue] Schemas\n "
171+ " [magenta]•[/magenta] Menu definitions\n "
172+ " [yellow]•[/yellow] Bootstrap data\n "
173+ " [green]•[/green] Security data\n "
174+ " [bright_magenta]•[/bright_magenta] Demo repository" ,
175+ border_style = "bright_blue" ,
176+ box = box .SIMPLE ,
177+ title = "[bold bright_blue]Bootstrap Process[/bold bright_blue]" ,
178+ )
179+ )
165180
166181 # Check if Infrahub is ready
167182 if not check_infrahub_ready ():
@@ -173,35 +188,35 @@ def main(branch: str = "main") -> int:
173188 "description" : "Loading schemas" ,
174189 "command" : f"uv run infrahubctl schema load schemas --branch { branch } " ,
175190 "color" : "blue" ,
176- "icon" : "📋"
191+ "icon" : "📋" ,
177192 },
178193 {
179194 "step" : "[2/7]" ,
180195 "description" : "Loading menu definitions" ,
181196 "command" : f"uv run infrahubctl menu load menu --branch { branch } " ,
182197 "color" : "magenta" ,
183- "icon" : "📑"
198+ "icon" : "📑" ,
184199 },
185200 {
186201 "step" : "[3/7]" ,
187202 "description" : "Loading bootstrap data (locations, platforms, roles, etc.)" ,
188203 "command" : f"uv run infrahubctl object load objects/bootstrap/ --branch { branch } " ,
189204 "color" : "yellow" ,
190- "icon" : "📦"
205+ "icon" : "📦" ,
191206 },
192207 {
193208 "step" : "[4/7]" ,
194209 "description" : "Loading security data (zones, policies, rules)" ,
195210 "command" : f"uv run infrahubctl object load objects/security/ --branch { branch } " ,
196211 "color" : "green" ,
197- "icon" : "🔒"
212+ "icon" : "🔒" ,
198213 },
199214 {
200215 "step" : "[5/7]" ,
201216 "description" : "Populating security relationships" ,
202217 "command" : "uv run python scripts/populate_security_relationships.py" ,
203218 "color" : "cyan" ,
204- "icon" : "🔗"
219+ "icon" : "🔗" ,
205220 },
206221 ]
207222
@@ -212,7 +227,7 @@ def main(branch: str = "main") -> int:
212227 step_info ["description" ],
213228 step_info ["step" ],
214229 step_info ["color" ],
215- step_info ["icon" ]
230+ step_info ["icon" ],
216231 ):
217232 console .print ("\n [bold red]✗ Bootstrap failed![/bold red]" )
218233 return 1
@@ -222,21 +237,32 @@ def main(branch: str = "main") -> int:
222237 console .print (Rule (style = f"dim { step_info ['color' ]} " ))
223238
224239 # Add repository (may already exist)
225- console .print ("\n [bold bright_magenta on black][6/7][/bold bright_magenta on black] 📚 [bold white]Adding demo repository[/bold white]" )
240+ console .print (
241+ "\n [bold bright_magenta on black][6/7][/bold bright_magenta on black] 📚 [bold white]Adding demo repository[/bold white]"
242+ )
226243 result = subprocess .run (
227244 "uv run infrahubctl repository add DEMO https://github.com/opsmill/infrahub-demo.git --ref main --read-only --ref main" ,
228245 shell = True ,
229246 capture_output = True ,
230- text = True
247+ text = True ,
231248 )
232249
233250 if result .returncode == 0 :
234- console .print ("[bold bright_green on black]✓[/bold bright_green on black] 📚 [bold bright_magenta]Repository added[/bold bright_magenta]" )
251+ console .print (
252+ "[bold bright_green on black]✓[/bold bright_green on black] 📚 [bold bright_magenta]Repository added[/bold bright_magenta]"
253+ )
235254 else :
236- if "already exists" in result .stderr .lower () or "already exists" in result .stdout .lower ():
237- console .print ("[bold yellow on black]⚠[/bold yellow on black] 📚 [bold bright_magenta]Repository already exists, skipping...[/bold bright_magenta]" )
255+ if (
256+ "already exists" in result .stderr .lower ()
257+ or "already exists" in result .stdout .lower ()
258+ ):
259+ console .print (
260+ "[bold yellow on black]⚠[/bold yellow on black] 📚 [bold bright_magenta]Repository already exists, skipping...[/bold bright_magenta]"
261+ )
238262 else :
239- console .print ("[bold red]✗[/bold red] 📚 [red]Failed to add repository[/red]" )
263+ console .print (
264+ "[bold red]✗[/bold red] 📚 [red]Failed to add repository[/red]"
265+ )
240266 console .print (f"[dim]{ result .stderr } [/dim]" )
241267
242268 console .print (Rule (style = "dim bright_magenta" ))
@@ -254,24 +280,26 @@ def main(branch: str = "main") -> int:
254280 "Event actions loading" ,
255281 "" ,
256282 "bright_cyan" ,
257- "⚡"
283+ "⚡" ,
258284 )
259285
260286 console .print (Rule (style = "dim bright_cyan" ))
261287
262288 # Display completion message
263289 console .print ()
264- console .print (Panel (
265- f"[bold bright_green]🎉 Bootstrap Complete![/bold bright_green]\n \n "
266- f"[dim]All data has been loaded into Infrahub[/dim]\n "
267- f"[bright_cyan]Branch:[/bright_cyan] [bold yellow]{ branch } [/bold yellow]\n \n "
268- "[bold bright_magenta]Next steps:[/bold bright_magenta]\n "
269- " [green]•[/green] Demo a DC design: [bold bright_cyan]uv run invoke demo-dc-arista[/bold bright_cyan]\n "
270- " [green]•[/green] Create a Proposed Change" ,
271- title = "[bold bright_green]✓ Success[/bold bright_green]" ,
272- border_style = "bright_green" ,
273- box = box .SIMPLE
274- ))
290+ console .print (
291+ Panel (
292+ f"[bold bright_green]🎉 Bootstrap Complete![/bold bright_green]\n \n "
293+ f"[dim]All data has been loaded into Infrahub[/dim]\n "
294+ f"[bright_cyan]Branch:[/bright_cyan] [bold yellow]{ branch } [/bold yellow]\n \n "
295+ "[bold bright_magenta]Next steps:[/bold bright_magenta]\n "
296+ " [green]•[/green] Demo a DC design: [bold bright_cyan]uv run invoke demo-dc-arista[/bold bright_cyan]\n "
297+ " [green]•[/green] Create a Proposed Change" ,
298+ title = "[bold bright_green]✓ Success[/bold bright_green]" ,
299+ border_style = "bright_green" ,
300+ box = box .SIMPLE ,
301+ )
302+ )
275303
276304 return 0
277305
@@ -285,7 +313,7 @@ def main(branch: str = "main") -> int:
285313 "-b" ,
286314 type = str ,
287315 default = "main" ,
288- help = "Branch to load data into (default: main)"
316+ help = "Branch to load data into (default: main)" ,
289317 )
290318 args = parser .parse_args ()
291319
0 commit comments