Fix pip requirements to update pyangbind version to 0.8.3.post1
[osm/osmclient.git] / osmclient / cli_commands / netslice_ops.py
1 # Copyright ETSI Contributors and Others.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import click
17 from osmclient.cli_commands import utils
18 from prettytable import PrettyTable
19 import json
20 import logging
21
22 logger = logging.getLogger("osmclient")
23
24
25 def nsi_op_list(ctx, name):
26 logger.debug("")
27 utils.check_client_version(ctx.obj, ctx.command.name)
28 resp = ctx.obj.nsi.list_op(name)
29 table = PrettyTable(["id", "operation", "status"])
30 for op in resp:
31 table.add_row([op["id"], op["lcmOperationType"], op["operationState"]])
32 table.align = "l"
33 print(table)
34
35
36 @click.command(
37 name="nsi-op-list",
38 short_help="shows the history of operations over a Network Slice Instance (NSI)",
39 )
40 @click.argument("name")
41 @click.pass_context
42 def nsi_op_list1(ctx, name):
43 """shows the history of operations over a Network Slice Instance (NSI)
44
45 NAME: name or ID of the Network Slice Instance
46 """
47 logger.debug("")
48 nsi_op_list(ctx, name)
49
50
51 @click.command(
52 name="netslice-instance-op-list",
53 short_help="shows the history of operations over a Network Slice Instance (NSI)",
54 )
55 @click.argument("name")
56 @click.pass_context
57 def nsi_op_list2(ctx, name):
58 """shows the history of operations over a Network Slice Instance (NSI)
59
60 NAME: name or ID of the Network Slice Instance
61 """
62 logger.debug("")
63 nsi_op_list(ctx, name)
64
65
66 def nsi_op_show(ctx, id, filter):
67 logger.debug("")
68 utils.check_client_version(ctx.obj, ctx.command.name)
69 op_info = ctx.obj.nsi.get_op(id)
70
71 table = PrettyTable(["field", "value"])
72 for k, v in list(op_info.items()):
73 if not filter or k in filter:
74 table.add_row([k, json.dumps(v, indent=2)])
75 table.align = "l"
76 print(table)
77
78
79 @click.command(
80 name="nsi-op-show",
81 short_help="shows the info of an operation over a Network Slice Instance(NSI)",
82 )
83 @click.argument("id")
84 @click.option(
85 "--filter",
86 multiple=True,
87 help="restricts the information to the fields in the filter",
88 )
89 @click.pass_context
90 def nsi_op_show1(ctx, id, filter):
91 """shows the info of an operation over a Network Slice Instance(NSI)
92
93 ID: operation identifier
94 """
95 logger.debug("")
96 nsi_op_show(ctx, id, filter)
97
98
99 @click.command(
100 name="netslice-instance-op-show",
101 short_help="shows the info of an operation over a Network Slice Instance(NSI)",
102 )
103 @click.argument("id")
104 @click.option(
105 "--filter",
106 multiple=True,
107 help="restricts the information to the fields in the filter",
108 )
109 @click.pass_context
110 def nsi_op_show2(ctx, id, filter):
111 """shows the info of an operation over a Network Slice Instance(NSI)
112
113 ID: operation identifier
114 """
115 logger.debug("")
116 nsi_op_show(ctx, id, filter)