integrated creation into the standard session.add_node call, currently requires an extra check due to the need for being able to specify an image
This commit is contained in:
parent
0e7464d419
commit
2397cd58ee
6 changed files with 49 additions and 34 deletions
|
@ -79,12 +79,13 @@ class NodeOptions(object):
|
|||
Options for creating and updating nodes within core.
|
||||
"""
|
||||
|
||||
def __init__(self, name=None, model="PC"):
|
||||
def __init__(self, name=None, model="PC", image=None):
|
||||
"""
|
||||
Create a NodeOptions object.
|
||||
|
||||
:param str name: name of node, defaults to node class name postfix with its id
|
||||
:param str model: defines services for default and physical nodes, defaults to "router"
|
||||
:param str image: image to use for docker nodes
|
||||
"""
|
||||
self.name = name
|
||||
self.model = model
|
||||
|
@ -99,6 +100,7 @@ class NodeOptions(object):
|
|||
self.alt = None
|
||||
self.emulation_id = None
|
||||
self.emulation_server = None
|
||||
self.image = image
|
||||
|
||||
def set_position(self, x, y):
|
||||
"""
|
||||
|
|
|
@ -500,7 +500,10 @@ class Session(object):
|
|||
|
||||
# create node
|
||||
logging.info("creating node(%s) id(%s) name(%s) start(%s)", node_class.__name__, _id, name, start)
|
||||
node = self.create_node(cls=node_class, _id=_id, name=name, start=start)
|
||||
if _type == NodeTypes.DOCKER:
|
||||
node = self.create_node(cls=node_class, _id=_id, name=name, start=start, image=node_options.image)
|
||||
else:
|
||||
node = self.create_node(cls=node_class, _id=_id, name=name, start=start)
|
||||
|
||||
# set node attributes
|
||||
node.icon = node_options.icon
|
||||
|
@ -511,7 +514,7 @@ class Session(object):
|
|||
self.set_node_position(node, node_options)
|
||||
|
||||
# add services to default and physical nodes only
|
||||
if _type in [NodeTypes.DEFAULT, NodeTypes.PHYSICAL]:
|
||||
if _type in [NodeTypes.DEFAULT, NodeTypes.PHYSICAL, NodeTypes.DOCKER]:
|
||||
node.type = node_options.model
|
||||
logging.debug("set node type: %s", node.type)
|
||||
self.services.add_services(node, node.type, node_options.services)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue