Code Coverage

Cobertura Coverage Report > osmclient.cli_commands >

subscriptions.py

Trend

Classes100%
 
Lines51%
   
Conditionals100%
 

File Coverage summary

NameClassesLinesConditionals
subscriptions.py
100%
1/1
51%
30/59
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
subscriptions.py
51%
30/59
N/A

Source

osmclient/cli_commands/subscriptions.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 1 import click
17 1 from osmclient.common.exceptions import ClientException
18 1 from osmclient.cli_commands import utils
19 1 from prettytable import PrettyTable
20 1 import json
21 1 import logging
22
23 1 logger = logging.getLogger("osmclient")
24
25
26 1 @click.command(
27     name="subscription-create",
28     short_help="creates a new subscription to a specific event",
29 )
30 1 @click.option(
31     "--event_type",
32     # type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
33     type=click.Choice(["ns"], case_sensitive=False),
34     help="event type to be subscribed (for the moment, only ns is supported)",
35 )
36 1 @click.option("--event", default=None, help="specific yaml configuration for the event")
37 1 @click.option(
38     "--event_file", default=None, help="specific yaml configuration file for the event"
39 )
40 1 @click.pass_context
41 1 def subscription_create(ctx, event_type, event, event_file):
42     """creates a new subscription to a specific event"""
43 0     logger.debug("")
44 0     utils.check_client_version(ctx.obj, ctx.command.name)
45 0     if event_file:
46 0         if event:
47 0             raise ClientException(
48                 '"--event" option is incompatible with "--event_file" option'
49             )
50 0         with open(event_file, "r") as cf:
51 0             event = cf.read()
52 0     ctx.obj.subscription.create(event_type, event)
53
54
55 1 @click.command(name="subscription-delete", short_help="deletes a subscription")
56 1 @click.option(
57     "--event_type",
58     # type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
59     type=click.Choice(["ns"], case_sensitive=False),
60     help="event type to be subscribed (for the moment, only ns is supported)",
61 )
62 1 @click.argument("subscription_id")
63 1 @click.option(
64     "--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
65 )
66 1 @click.pass_context
67 1 def subscription_delete(ctx, event_type, subscription_id, force):
68     """deletes a subscription
69
70     SUBSCRIPTION_ID: ID of the subscription to be deleted
71     """
72 0     logger.debug("")
73 0     utils.check_client_version(ctx.obj, ctx.command.name)
74 0     ctx.obj.subscription.delete(event_type, subscription_id, force)
75
76
77 1 @click.command(name="subscription-list", short_help="list all subscriptions")
78 1 @click.option(
79     "--event_type",
80     # type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
81     type=click.Choice(["ns"], case_sensitive=False),
82     help="event type to be subscribed (for the moment, only ns is supported)",
83 )
84 1 @click.option(
85     "--filter",
86     default=None,
87     multiple=True,
88     help="restricts the list to the subscriptions matching the filter",
89 )
90 1 @click.pass_context
91 1 def subscription_list(ctx, event_type, filter):
92     """list all subscriptions"""
93 0     logger.debug("")
94 0     utils.check_client_version(ctx.obj, ctx.command.name)
95 0     if filter:
96 0         filter = "&".join(filter)
97 0     resp = ctx.obj.subscription.list(event_type, filter)
98 0     table = PrettyTable(["id", "filter", "CallbackUri"])
99 0     for sub in resp:
100 0         table.add_row(
101             [
102                 sub["_id"],
103                 utils.wrap_text(text=json.dumps(sub["filter"], indent=2), width=70),
104                 sub["CallbackUri"],
105             ]
106         )
107 0     table.align = "l"
108 0     print(table)
109
110
111 1 @click.command(
112     name="subscription-show", short_help="shows the details of a subscription"
113 )
114 1 @click.argument("subscription_id")
115 1 @click.option(
116     "--event_type",
117     # type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
118     type=click.Choice(["ns"], case_sensitive=False),
119     help="event type to be subscribed (for the moment, only ns is supported)",
120 )
121 1 @click.option(
122     "--filter",
123     multiple=True,
124     help="restricts the information to the fields in the filter",
125 )
126 1 @click.pass_context
127 1 def subscription_show(ctx, event_type, subscription_id, filter):
128     """shows the details of a subscription
129
130     SUBSCRIPTION_ID: ID of the subscription
131     """
132 0     logger.debug("")
133 0     resp = ctx.obj.subscription.get(subscription_id)
134 0     table = PrettyTable(["key", "attribute"])
135 0     for k, v in list(resp.items()):
136 0         if not filter or k in filter:
137 0             table.add_row([k, utils.wrap_text(text=json.dumps(v, indent=2), width=100)])
138 0     table.align = "l"
139 0     print(table)