0a1e44a46ca47caf3103bf68881dfb748f2676d4
1 # Copyright 2018 Telefonica
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
21 from osmclient
.common
import utils
22 from osmclient
.common
.exceptions
import NotFound
27 def __init__(self
, http
=None, client
=None):
30 self
._apiName
= '/nslcm'
31 self
._apiVersion
= '/v1'
32 self
._apiResource
= '/vnfrs'
33 self
._apiBase
= '{}{}{}'.format(self
._apiName
,
34 self
._apiVersion
, self
._apiResource
)
36 def list(self
, ns
=None):
37 """Returns a list of VNF instances
41 ns_instance
= self
._client
.ns
.get(ns
)
42 filter_string
= '?nsr-id-ref={}'.format(ns_instance
['_id'])
43 resp
= self
._http
.get_cmd('{}{}'.format(self
._apiBase
,filter_string
))
49 """Returns a VNF instance based on name or id
51 if utils
.validate_uuid4(name
):
52 for vnf
in self
.list():
56 for vnf
in self
.list():
57 if name
== vnf
['name']:
59 raise NotFound("vnf {} not found".format(name
))
61 def get_individual(self
, name
):
63 if not utils
.validate_uuid4(name
):
64 for vnf
in self
.list():
65 if name
== vnf
['name']:
68 resp
= self
._http
.get_cmd('{}/{}'.format(self
._apiBase
, vnf_id
))
71 raise NotFound("vnf {} not found".format(name
))