SDN Accounts refactoring
[osm/SO.git] / rwlaunchpad / plugins / rwvns / vala / rwsdn_sim / rwsdn_sim.py
1
2 #
3 # Copyright 2016 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 import collections
19 import itertools
20 import logging
21 import os
22 import uuid
23 import time
24
25 import ipaddress
26
27 import gi
28 gi.require_version('RwTypes', '1.0')
29 gi.require_version('RwcalYang', '1.0')
30 gi.require_version('RwSdn', '1.0')
31 from gi.repository import (
32 GObject,
33 RwSdn, # Vala package
34 RwTypes,
35 RwsdnalYang,
36 #IetfL2TopologyYang as l2Tl,
37 RwTopologyYang as RwTl,
38 )
39
40 import rw_status
41 import rwlogger
42
43 from rift.topmgr.sdnsim import SdnSim
44
45
46 logger = logging.getLogger('rwsdn.sdnsim')
47
48
49 class UnknownAccountError(Exception):
50 pass
51
52
53 class MissingFileError(Exception):
54 pass
55
56
57 rwstatus = rw_status.rwstatus_from_exc_map({
58 IndexError: RwTypes.RwStatus.NOTFOUND,
59 KeyError: RwTypes.RwStatus.NOTFOUND,
60 UnknownAccountError: RwTypes.RwStatus.NOTFOUND,
61 MissingFileError: RwTypes.RwStatus.NOTFOUND,
62 })
63
64
65 class SdnSimPlugin(GObject.Object, RwSdn.Topology):
66
67 def __init__(self):
68 GObject.Object.__init__(self)
69 self.sdnsim = SdnSim()
70
71
72 @rwstatus
73 def do_init(self, rwlog_ctx):
74 if not any(isinstance(h, rwlogger.RwLogger) for h in logger.handlers):
75 logger.addHandler(
76 rwlogger.RwLogger(
77 subcategory="sdnsim",
78 log_hdl=rwlog_ctx,
79 )
80 )
81
82 @rwstatus(ret_on_failure=[None])
83 def do_validate_sdn_creds(self, account):
84 """
85 Validates the sdn account credentials for the specified account.
86 Performs an access to the resources using Keystone API. If creds
87 are not valid, returns an error code & reason string
88
89 @param account - a SDN account
90
91 Returns:
92 Validation Code and Details String
93 """
94 status = RwsdnalYang.SdnConnectionStatus()
95 print("SDN Successfully connected")
96 status.status = "success"
97 status.details = "Connection was successful"
98 #logger.debug('Done with validate SDN creds: %s', type(status))
99 return status
100
101
102 @rwstatus(ret_on_failure=[None])
103 def do_get_network_list(self, account):
104 """
105 Returns the list of discovered networks
106
107 @param account - a SDN account
108
109 """
110 logger.debug('Get network list: ')
111 nwtop = self.sdnsim.get_network_list( account)
112 logger.debug('Done with get network list: %s', type(nwtop))
113 return nwtop