update Makefile, pep8, scaling
[osm/osmclient.git] / osmclient / v1 / client.py
1 # Copyright 2017 Sandvine
2 #
3 # All Rights Reserved.
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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
15 # under the License.
16
17 """
18 OSM v1 client API
19 """
20
21 from osmclient.v1 import vnf
22 from osmclient.v1 import vnfd
23 from osmclient.v1 import ns
24 from osmclient.v1 import nsd
25 from osmclient.v1 import vim
26 from osmclient.v1 import package
27 from osmclient.v1 import vca
28 from osmclient.v1 import utils
29 from osmclient.common import http
30
31
32 class Client(object):
33
34 def __init__(
35 self,
36 host=None,
37 so_port=8008,
38 ro_host=None,
39 ro_port=9090,
40 upload_port=8443,
41 **kwargs):
42 self._user = 'admin'
43 self._password = 'admin'
44
45 if len(host.split(':')) > 1:
46 # backwards compatible, port provided as part of host
47 self._host = host.split(':')[0]
48 self._so_port = host.split(':')[1]
49 else:
50 self._host = host
51 self._so_port = so_port
52
53 http_client = http.Http(
54 'https://{}:{}/'.format(
55 self._host,
56 self._so_port))
57 http_client.set_http_header(
58 ['Accept: application/vnd.yand.data+json',
59 'Content-Type: application/json'])
60
61 if ro_host is None:
62 ro_host = host
63 ro_http_client = http.Http('http://{}:{}/'.format(ro_host, ro_port))
64 ro_http_client.set_http_header(
65 ['Accept: application/vnd.yand.data+json',
66 'Content-Type: application/json'])
67
68 upload_client = http.Http(
69 'https://{}:{}/composer/upload?api_server={}{}'.format(
70 self._host,
71 upload_port,
72 'https://localhost&upload_server=https://',
73 self._host))
74
75 self.vnf = vnf.Vnf(http_client, **kwargs)
76 self.vnfd = vnfd.Vnfd(http_client, **kwargs)
77 self.ns = ns.Ns(http=http_client, client=self, **kwargs)
78 self.nsd = nsd.Nsd(http_client, **kwargs)
79 self.vim = vim.Vim(
80 http=http_client,
81 ro_http=ro_http_client,
82 client=self,
83 **kwargs)
84 self.package = package.Package(
85 http=http_client,
86 upload_http=upload_client,
87 client=self,
88 **kwargs)
89 self.vca = vca.Vca(http_client, **kwargs)
90 self.utils = utils.Utils(http_client, **kwargs)