Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
2f347271
Commit
2f347271
authored
Sep 03, 2024
by
Hejing Li
Browse files
turn some imports only for typechecking
parent
8583746a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
22 deletions
+24
-22
experiments/simbricks/orchestration/system/host/app.py
experiments/simbricks/orchestration/system/host/app.py
+4
-3
experiments/simbricks/orchestration/system/host/base.py
experiments/simbricks/orchestration/system/host/base.py
+12
-13
experiments/simbricks/orchestration/system/host/disk_images.py
...iments/simbricks/orchestration/system/host/disk_images.py
+8
-6
No files found.
experiments/simbricks/orchestration/system/host/app.py
View file @
2f347271
...
@@ -23,19 +23,20 @@
...
@@ -23,19 +23,20 @@
import
typing
as
tp
import
typing
as
tp
import
abc
import
abc
import
io
import
io
from
simbricks.orchestration.system.host
import
base
from
simbricks.orchestration.experiment
import
experiment_environment
as
expenv
from
simbricks.orchestration.experiment
import
experiment_environment
as
expenv
if
tp
.
TYPE_CHECKING
:
from
simbricks.orchestration.system.host
import
base
class
Application
(
abc
.
ABC
):
class
Application
(
abc
.
ABC
):
def
__init__
(
self
,
h
:
base
.
Host
)
->
None
:
def
__init__
(
self
,
h
:
'
Host
'
)
->
None
:
self
.
host
=
h
self
.
host
=
h
# Note AK: Maybe we can factor most of the duplicate calls with the host out
# Note AK: Maybe we can factor most of the duplicate calls with the host out
# into a separate module.
# into a separate module.
class
BaseLinuxApplication
(
abc
.
ABC
):
class
BaseLinuxApplication
(
abc
.
ABC
):
def
__init__
(
self
,
h
:
base
.
LinuxHost
)
->
None
:
def
__init__
(
self
,
h
:
'
LinuxHost
'
)
->
None
:
self
.
host
=
h
self
.
host
=
h
self
.
start_delay
:
float
|
None
=
None
self
.
start_delay
:
float
|
None
=
None
self
.
end_delay
:
float
|
None
=
None
self
.
end_delay
:
float
|
None
=
None
...
...
experiments/simbricks/orchestration/system/host/base.py
View file @
2f347271
...
@@ -24,19 +24,18 @@ import typing as tp
...
@@ -24,19 +24,18 @@ import typing as tp
import
io
import
io
from
os
import
path
from
os
import
path
from
simbricks.orchestration.experiment
import
experiment_environment
as
expenv
from
simbricks.orchestration.experiment
import
experiment_environment
as
expenv
from
simbricks.orchestration.system
import
base
from
simbricks.orchestration.system
import
base
as
base
from
simbricks.orchestration.system
import
eth
if
tp
.
TYPE_CHECKING
:
from
simbricks.orchestration.system
import
mem
from
simbricks.orchestration.system
import
(
eth
,
mem
,
pcie
)
from
simbricks.orchestration.system
import
pcie
from
simbricks.orchestration.system.host
import
disk_images
from
simbricks.orchestration.system.host
import
disk_images
from
simbricks.orchestration.system.host
import
app
from
simbricks.orchestration.system.host
import
app
class
Host
(
base
.
Component
):
class
Host
(
base
.
Component
):
def
__init__
(
self
,
s
:
base
.
System
):
def
__init__
(
self
,
s
:
base
.
System
):
super
().
__init__
(
s
)
super
().
__init__
(
s
)
self
.
ifs
:
list
[
base
.
Interface
]
=
[]
self
.
ifs
:
list
[
base
.
Interface
]
=
[]
self
.
applications
:
list
[
app
.
Application
]
self
.
applications
:
list
[
'
Application
'
]
def
interfaces
(
self
)
->
list
[
base
.
Interface
]:
def
interfaces
(
self
)
->
list
[
base
.
Interface
]:
return
self
.
pcie_ifs
+
self
.
eth_ifs
+
self
.
mem_ifs
return
self
.
pcie_ifs
+
self
.
eth_ifs
+
self
.
mem_ifs
...
@@ -44,7 +43,7 @@ class Host(base.Component):
...
@@ -44,7 +43,7 @@ class Host(base.Component):
def
add_if
(
self
,
i
:
base
.
Interface
)
->
None
:
def
add_if
(
self
,
i
:
base
.
Interface
)
->
None
:
self
.
ifs
.
append
(
i
)
self
.
ifs
.
append
(
i
)
def
add_app
(
self
,
a
:
app
.
Application
)
->
None
:
def
add_app
(
self
,
a
:
'
Application
'
)
->
None
:
self
.
applications
.
append
(
a
)
self
.
applications
.
append
(
a
)
...
@@ -54,26 +53,26 @@ class FullSystemHost(Host):
...
@@ -54,26 +53,26 @@ class FullSystemHost(Host):
self
.
memory
=
512
self
.
memory
=
512
self
.
cores
=
1
self
.
cores
=
1
self
.
cpu_freq
=
'3GHz'
self
.
cpu_freq
=
'3GHz'
self
.
disks
:
list
[
disk_images
.
DiskImage
]
=
[]
self
.
disks
:
list
[
'
DiskImage
'
]
=
[]
def
add_disk
(
self
,
disk
:
disk_images
.
DiskImage
)
->
None
:
def
add_disk
(
self
,
disk
:
'
DiskImage
'
)
->
None
:
self
.
disks
.
append
(
disk
)
self
.
disks
.
append
(
disk
)
class
BaseLinuxHost
(
FullSystemHost
):
class
BaseLinuxHost
(
FullSystemHost
):
def
__init__
(
self
,
s
:
base
.
System
)
->
None
:
def
__init__
(
self
,
s
:
base
.
System
)
->
None
:
super
().
__init__
(
s
)
super
().
__init__
(
s
)
self
.
applications
:
list
[
app
.
BaseLinuxApplication
]
=
[]
self
.
applications
:
list
[
'
BaseLinuxApplication
'
]
=
[]
self
.
load_modules
=
[]
self
.
load_modules
=
[]
self
.
kcmd_append
=
''
self
.
kcmd_append
=
''
def
add_app
(
self
,
a
:
app
.
BaseLinuxApplication
)
->
None
:
def
add_app
(
self
,
a
:
'
BaseLinuxApplication
'
)
->
None
:
self
.
applications
.
append
(
a
)
self
.
applications
.
append
(
a
)
def
_concat_app_cmds
(
def
_concat_app_cmds
(
self
,
self
,
env
:
expenv
.
ExpEnv
,
env
:
expenv
.
ExpEnv
,
mapper
:
tp
.
Callable
[[
app
.
BaseLinuxApplication
,
expenv
.
ExpEnv
],
mapper
:
tp
.
Callable
[[
'
BaseLinuxApplication
'
,
expenv
.
ExpEnv
],
list
[
str
]]
list
[
str
]]
)
->
list
[
str
]:
)
->
list
[
str
]:
"""
"""
...
...
experiments/simbricks/orchestration/system/host/disk_images.py
View file @
2f347271
...
@@ -24,12 +24,14 @@ import abc
...
@@ -24,12 +24,14 @@ import abc
import
io
import
io
import
os.path
import
os.path
import
tarfile
import
tarfile
from
simbricks.orchestration.system.host
import
base
import
typing
as
tp
from
simbricks.orchestration.experiment
import
experiment_environment
as
expenv
from
simbricks.orchestration.experiment
import
experiment_environment
as
expenv
if
tp
.
TYPE_CHECKING
:
from
simbricks.orchestration.system.host
import
base
class
DiskImage
(
abc
.
ABC
):
class
DiskImage
(
abc
.
ABC
):
def
__init__
(
self
,
h
:
base
.
Host
)
->
None
:
def
__init__
(
self
,
h
:
'
Host
'
)
->
None
:
self
.
host
=
h
self
.
host
=
h
@
abc
.
abstractmethod
@
abc
.
abstractmethod
...
@@ -43,7 +45,7 @@ class DiskImage(abc.ABC):
...
@@ -43,7 +45,7 @@ class DiskImage(abc.ABC):
# Disk image where user just provides a path
# Disk image where user just provides a path
class
ExternalDiskImage
(
DiskImage
):
class
ExternalDiskImage
(
DiskImage
):
def
__init__
(
self
,
h
:
base
.
FullSystemHost
,
path
:
str
)
->
None
:
def
__init__
(
self
,
h
:
'
FullSystemHost
'
,
path
:
str
)
->
None
:
super
().
__init__
(
h
)
super
().
__init__
(
h
)
self
.
path
=
path
self
.
path
=
path
self
.
formats
=
[
"raw"
,
"qcow2"
]
self
.
formats
=
[
"raw"
,
"qcow2"
]
...
@@ -58,7 +60,7 @@ class ExternalDiskImage(DiskImage):
...
@@ -58,7 +60,7 @@ class ExternalDiskImage(DiskImage):
# Disk images shipped with simbricks
# Disk images shipped with simbricks
class
DistroDiskImage
(
DiskImage
):
class
DistroDiskImage
(
DiskImage
):
def
__init__
(
self
,
h
:
base
.
FullSystemHost
,
name
:
str
)
->
None
:
def
__init__
(
self
,
h
:
'
FullSystemHost
'
,
name
:
str
)
->
None
:
super
().
__init__
(
h
)
super
().
__init__
(
h
)
self
.
name
=
name
self
.
name
=
name
self
.
formats
=
[
"raw"
,
"qcow2"
]
self
.
formats
=
[
"raw"
,
"qcow2"
]
...
@@ -80,7 +82,7 @@ class DistroDiskImage(DiskImage):
...
@@ -80,7 +82,7 @@ class DistroDiskImage(DiskImage):
# Builds the Tar with the commands to run etc.
# Builds the Tar with the commands to run etc.
class
LinuxConfigDiskImage
(
DiskImage
):
class
LinuxConfigDiskImage
(
DiskImage
):
def
__init__
(
self
,
h
:
base
.
LinuxHost
)
->
None
:
def
__init__
(
self
,
h
:
'
LinuxHost
'
)
->
None
:
super
().
__init__
(
h
)
super
().
__init__
(
h
)
self
.
host
:
base
.
LinuxHost
self
.
host
:
base
.
LinuxHost
...
@@ -117,7 +119,7 @@ class LinuxConfigDiskImage(DiskImage):
...
@@ -117,7 +119,7 @@ class LinuxConfigDiskImage(DiskImage):
# Could of course also have a version that generates the packer config from
# Could of course also have a version that generates the packer config from
# python
# python
class
PackerDiskImage
(
DiskImage
):
class
PackerDiskImage
(
DiskImage
):
def
__init__
(
self
,
h
:
base
.
FullSystemHost
,
packer_config_path
:
str
)
->
None
:
def
__init__
(
self
,
h
:
'
FullSystemHost
'
,
packer_config_path
:
str
)
->
None
:
super
().
__init__
(
h
)
super
().
__init__
(
h
)
self
.
config_path
=
packer_config_path
self
.
config_path
=
packer_config_path
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment