1 # Copyright ETSI Contributors and Others.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
17 from osmclient
.common
.exceptions
import ClientException
18 from osmclient
.cli_commands
import utils
19 from prettytable
import PrettyTable
23 logger
= logging
.getLogger("osmclient")
27 name
="subscription-create",
28 short_help
="creates a new subscription to a specific event",
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)",
36 @click.option("--event", default
=None, help="specific yaml configuration for the event")
38 "--event_file", default
=None, help="specific yaml configuration file for the event"
41 def subscription_create(ctx
, event_type
, event
, event_file
):
42 """creates a new subscription to a specific event"""
44 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
47 raise ClientException(
48 '"--event" option is incompatible with "--event_file" option'
50 with
open(event_file
, "r") as cf
:
52 ctx
.obj
.subscription
.create(event_type
, event
)
55 @click.command(name
="subscription-delete", short_help
="deletes a subscription")
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)",
62 @click.argument("subscription_id")
64 "--force", is_flag
=True, help="forces the deletion bypassing pre-conditions"
67 def subscription_delete(ctx
, event_type
, subscription_id
, force
):
68 """deletes a subscription
70 SUBSCRIPTION_ID: ID of the subscription to be deleted
73 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
74 ctx
.obj
.subscription
.delete(event_type
, subscription_id
, force
)
77 @click.command(name
="subscription-list", short_help
="list all subscriptions")
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)",
88 help="restricts the list to the subscriptions matching the filter",
91 def subscription_list(ctx
, event_type
, filter):
92 """list all subscriptions"""
94 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
96 filter = "&".join(filter)
97 resp
= ctx
.obj
.subscription
.list(event_type
, filter)
98 table
= PrettyTable(["id", "filter", "CallbackUri"])
103 utils
.wrap_text(text
=json
.dumps(sub
["filter"], indent
=2), width
=70),
112 name
="subscription-show", short_help
="shows the details of a subscription"
114 @click.argument("subscription_id")
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)",
124 help="restricts the information to the fields in the filter",
127 def subscription_show(ctx
, event_type
, subscription_id
, filter):
128 """shows the details of a subscription
130 SUBSCRIPTION_ID: ID of the subscription
133 resp
= ctx
.obj
.subscription
.get(subscription_id
)
134 table
= PrettyTable(["key", "attribute"])
135 for k
, v
in list(resp
.items()):
136 if not filter or k
in filter:
137 table
.add_row([k
, utils
.wrap_text(text
=json
.dumps(v
, indent
=2), width
=100)])