aboutsummaryrefslogtreecommitdiffstats
path: root/vicn/resource/node.py
diff options
context:
space:
mode:
Diffstat (limited to 'vicn/resource/node.py')
-rw-r--r--vicn/resource/node.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/vicn/resource/node.py b/vicn/resource/node.py
new file mode 100644
index 00000000..bfb2f9ec
--- /dev/null
+++ b/vicn/resource/node.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2017 Cisco and/or its affiliates.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import logging
+import os
+
+from netmodel.model.type import Double, String, Self
+from vicn.core.address_mgr import AddressManager
+from vicn.core.attribute import Attribute
+from vicn.core.resource import Resource
+
+log = logging.getLogger(__name__)
+
+DEFAULT_USERNAME = 'root'
+DEFAULT_SSH_PRIVATE_KEY = os.path.join(os.path.dirname(__file__),
+ '..', '..', 'config', 'ssh_client_cert', 'ssh_client_key')
+DEFAULT_SSH_PUBLIC_KEY = os.path.join(os.path.dirname(__file__),
+ '..', '..', 'config', 'ssh_client_cert', 'ssh_client_key.pub')
+
+class Node(Resource):
+ """
+ Resource: Node
+ """
+
+ x = Attribute(Double, description = 'X coordinate',
+ default = 0.0)
+ y = Attribute(Double, description = 'Y coordinate',
+ default = 0.0)
+ category = Attribute(String)
+ os = Attribute(String, description = 'OS',
+ default = 'ubuntu',
+ choices = ['debian', 'ubuntu'])
+ dist = Attribute(String, description = 'Distribution name',
+ default = 'xenial',
+ choices = ['trusty', 'xenial', 'sid'])
+ arch = Attribute(String, description = 'Architecture',
+ default = 'amd64',
+ choices = ['amd64'])
+ node_with_kernel = Attribute(Self,
+ description = 'Node on which the kernel sits',
+ ro = True)
+
+ #---------------------------------------------------------------------------
+ # Constructor and Accessors
+ #---------------------------------------------------------------------------
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self._host_interface = None
+
+ #---------------------------------------------------------------------------
+ # Public API
+ #---------------------------------------------------------------------------
+
+ @property
+ def host_interface(self):
+ """
+ We assume that any unmanaged interface associated to the host is the
+ main host interface. It should thus be declared in the JSON topology.
+ We might later perform some kind of auto discovery.
+
+ This unmanaged interface is only required to get the device_name:
+ - to create Veth (need a parent)
+ - to ssh a node, get its ip address (eg for the repo)
+ - to avoid loops in type specification
+
+ It is used for all nodes to provide network connectivity.
+ """
+
+ for interface in self.interfaces:
+ if not interface.managed or interface.owner is not None:
+ return interface
+
+ raise Exception('Cannot find host interface for node {}: {}'.format(
+ self, self.interfaces))
+
+ def execute(self, command, output = False, as_root = False):
+ raise NotImplementedError