1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/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.expanduser(os.path.join(
'~', '.vicn', 'ssh_client_cert', 'ssh_client_key'))
DEFAULT_SSH_PUBLIC_KEY = os.path.expanduser(os.path.join(
'~', '.vicn', 'ssh_client_cert', 'ssh_client_key.pub'))
OS = String.restrict(choices=('debian', 'ubuntu'))
Distribution = String.restrict(choices=('trusty', 'xenial', 'sid'))
Architecture = String.restrict(choices=('amd64'))
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)
scale = Attribute(Double, default = 1)
os = Attribute(OS, description = 'OS',
default = 'ubuntu')
dist = Attribute(Distribution, description = 'Distribution name',
default = 'xenial')
arch = Attribute(Architecture, description = 'Architecture',
default = '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._management_interface = None
#---------------------------------------------------------------------------
# Public API
#---------------------------------------------------------------------------
@property
def management_interface(self):
if not self._management_interface:
raise Exception("No management interface has been defined")
return self._management_interface
def execute(self, command, output = False, as_root = False):
raise NotImplementedError
|