src/dpdk: Enable building of vhost-user in src/dpdk.
[vswitchperf.git] / vnfs / vnf / vnf.py
1 # Copyright 2015 Intel Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """
16 Interface for VNF.
17 """
18
19
20 class IVnf(object):
21
22     """
23     Interface for VNF.
24     """
25
26     def __init__(self, memory, cpus,
27                  monitor_path, shared_path_host,
28                  shared_path_guest, guest_prompt):
29         """
30         Initialization method.
31
32         Purpose of this method is to initialize all
33         common Vnf data, no services should be started by
34         this call (use ``start`` method instead).
35
36         :param memory:   Virtual RAM size in megabytes.
37         :param cpus:     Number of Processors.
38         :param monitor_path: Configure monitor to given path.
39         :param shared_path_host: HOST path to shared location.
40         :param shared_path_guest: GUEST path to shared location.
41         :param guest_prompt: preconfigured command prompt which is used
42                            in execute_and_wait & wait methods
43                            to detect if particular call is finished.
44         """
45         raise NotImplementedError()
46
47     def start(self):
48         """
49         Starts VNF instance.
50         """
51         raise NotImplementedError()
52
53     def stop(self):
54         """
55         Stops VNF instance.
56         """
57         raise NotImplementedError()
58
59     def execute(self, command, delay=30):
60         """
61         execute ``command`` with given ``delay``.
62
63         This method makes asynchronous call to guest system
64         and waits given ``delay`` before returning. Can be
65         used with ``wait`` method to create synchronous call.
66
67         :param command: Command to execute on guest system.
68         :param delay: Delay (in seconds) to wait after sending
69                       command before returning. Please note that
70                       this value can be floating point which
71                       allows to pass milliseconds.
72
73         :returns: None.
74         """
75         raise NotImplementedError()
76
77     def wait(self, guest_prompt, timeout=30):
78         """
79         wait for ``guest_prompt`` on guest system for given ``timeout``.
80
81         This method ends based on two conditions:
82         * ``guest_prompt`` has been detected
83         * ``timeout`` has been reached.
84
85         :param guest_prompt: method end condition. If ``guest_prompt``
86                              won't be detected during given timeout,
87                              method will return False.
88         :param timeout: Time to wait for prompt (in seconds).
89                         Please note that this value can be floating
90                         point which allows to pass milliseconds.
91
92         :returns: True if result_cmd has been detected before
93                   timeout has been reached, False otherwise.
94         """
95         raise NotImplementedError()
96
97     def execute_and_wait(self, command, timeout=30, guest_prompt=None):
98         """
99         execute ``command`` with given ``timeout``.
100
101         This method makes synchronous call to guest system
102         and waits till ``command`` execution is finished
103         (based on ``guest_prompt value) or ''timeout'' has
104         been reached.
105
106         :param command: Command to execute on guest system.
107         :param timeout: Timeout till the end of execution is not
108                         detected.
109         :param guest_prompt: method end condition. If ``guest_prompt``
110                              won't be detected during given timeout,
111                              method will return False. If no argument
112                              or None value will be passed, default
113                              ``guest_prompt`` passed in __init__
114                              method will be used.
115
116         :returns: True if end of execution has been detected
117                   before timeout has been reached, False otherwise.
118         """
119         raise NotImplementedError()