# License for the specific language governing permissions and limitations
# under the License.
+import copy
from io import BytesIO
-import pycurl
import json
import logging
-import copy
+
from osmclient.common import http
from osmclient.common.exceptions import OsmHttpException, NotFound
+import pycurl
class Http(http.Http):
self._http_header = None
self._logger = logging.getLogger('osmclient')
self._default_query_admin = None
- self._all_projects = None;
- self._public = None;
+ self._all_projects = None
+ self._public = None
if 'all_projects' in kwargs:
- self._all_projects=kwargs['all_projects']
+ self._all_projects = kwargs['all_projects']
if 'public' in kwargs:
- self._public=kwargs['public']
+ self._public = kwargs['public']
self._default_query_admin = self._complete_default_query_admin()
def _complete_default_query_admin(self):
- query_string_list=[]
+ query_string_list = []
if self._all_projects:
query_string_list.append("ADMIN")
if self._public is not None:
curl_cmd = self._get_curl_cmd(endpoint, skip_query_admin)
curl_cmd.setopt(pycurl.CUSTOMREQUEST, "DELETE")
curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
- self._logger.info("Request METHOD: {} URL: {}".format("DELETE",self._url + endpoint))
+ self._logger.info("Request METHOD: {} URL: {}".format("DELETE", self._url + endpoint))
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
jsondata = json.dumps(postfields_dict)
if 'password' in postfields_dict:
postfields_dict_copy = copy.deepcopy(postfields_dict)
- postfields_dict_copy['password']='******'
+ postfields_dict_copy['password'] = '******'
jsondata_log = json.dumps(postfields_dict_copy)
else:
jsondata_log = jsondata
formfile[1])))])
elif filename is not None:
with open(filename, 'rb') as stream:
- postdata=stream.read()
+ postdata = stream.read()
self._logger.verbose("Request POSTFIELDS: Binary content")
curl_cmd.setopt(pycurl.POSTFIELDS, postdata)
if put_method:
- self._logger.info("Request METHOD: {} URL: {}".format("PUT",self._url + endpoint))
+ self._logger.info("Request METHOD: {} URL: {}".format("PUT", self._url + endpoint))
elif patch_method:
- self._logger.info("Request METHOD: {} URL: {}".format("PATCH",self._url + endpoint))
+ self._logger.info("Request METHOD: {} URL: {}".format("PATCH", self._url + endpoint))
else:
- self._logger.info("Request METHOD: {} URL: {}".format("POST",self._url + endpoint))
+ self._logger.info("Request METHOD: {} URL: {}".format("POST", self._url + endpoint))
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
skip_query_admin=skip_query_admin)
def patch_cmd(self, endpoint='', postfields_dict=None,
- formfile=None, filename=None,
- skip_query_admin=False):
+ formfile=None, filename=None,
+ skip_query_admin=False):
self._logger.debug("")
return self.send_cmd(endpoint=endpoint,
postfields_dict=postfields_dict,
curl_cmd = self._get_curl_cmd(endpoint, skip_query_admin)
curl_cmd.setopt(pycurl.HTTPGET, 1)
curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
- self._logger.info("Request METHOD: {} URL: {}".format("GET",self._url + endpoint))
+ self._logger.info("Request METHOD: {} URL: {}".format("GET", self._url + endpoint))
curl_cmd.perform()
http_code = curl_cmd.getinfo(pycurl.HTTP_CODE)
self._logger.info("Response HTTPCODE: {}".format(http_code))
def set_query_admin(self, **kwargs):
if 'all_projects' in kwargs:
- self._all_projects=kwargs['all_projects']
+ self._all_projects = kwargs['all_projects']
if 'public' in kwargs:
- self._public=kwargs['public']
+ self._public = kwargs['public']
self._default_query_admin = self._complete_default_query_admin()
--- /dev/null
+##
+# Copyright 2020 ETSI
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+##
+
+# Snap for OSM client
+
+The snapcraft.yaml located in this folder, allows to build a snap of the OSM client
+
+
+# Build the Snap
+
+```bash
+docker run -v ${PWD}:/build -w /build snapcore/snapcraft:stable /bin/bash -c "apt update && snapcraft"
+```
+
+
+## Working on build steps
+
+As the build can take upwards of 4 minutes, it might be easier to enter the docker
+container and perform iterative builds there.
+
+```bash
+docker run -v ${PWD}:/build -w /build snapcore/snapcraft:stable /bin/bash -c /bin/bash
+apt update
+snapcraft
+```
+
+
+## Install
+
+```bash
+$ sudo snap install --devmode osmclient_v7.1.0+git4.a4af86f-dirty_amd64.snap
+osmclient v7.1.0+git4.a4af86f-dirty installed
+$ sudo snap alias osmclient.osm osm
+```
-name: osmclient # you probably want to 'snapcraft register <name>'
-version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
-summary: A python client for osm orchestration
+---
+##
+# Copyright 2020 ETSI
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+##
+name: osmclient
+base: core18
+version: git
+summary: A python client for orchestrating OSM
description: |
- A python client for osm orchestration
+ A python client for orchestrating Open Source Mano (OSM).
-grade: stable # must be 'stable' to release into candidate/stable channels
-confinement: strict # use 'strict' once you have the right plugs and slots
+grade: stable
+
+confinement: strict
+
+environment:
+ LC_ALL: C.UTF-8
+ LANG: C.UTF-8
apps:
- osmclient:
- command: bin/osm
+ osm:
+ command: usr/bin/python3 $SNAP/usr/local/bin/osm
+ plugs:
+ - network
+ - home
+ - ssh-public-keys
+ environment:
+ PATH: $SNAP/usr/bin:$SNAP/bin/:$PATH
+ PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH
+ MAGIC: $SNAP/usr/share/file/magic.mgc
parts:
- osmclient:
+ client:
+ plugin: dump
source: .
- plugin: python
- python-version: python2
- stage:
- - -README.md
+ build-environment:
+ - PATH: "$PATH:$SNAPCRAFT_PART_INSTALL/usr/local/bin"
+ build-packages:
+ - gcc
+ - git
+ stage-packages:
+ - libmagic1
+ - python3
+ - python3-dev
+ - python3-pip
+ - python3-pycurl
+ - python3-setuptools
+ override-build: |
+ $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install wheel
+ $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install pyang
+ $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install pyangbind
+ PATH="$PATH:$SNAPCRAFT_PART_INSTALL/usr/local/bin"
+ BRANCH_OR_TAG=`git symbolic-ref -q --short HEAD || git describe --tags --exact-match 2>/dev/null || echo $BRANCH`
+ git clone https://osm.etsi.org/gerrit/osm/IM.git
+ cd IM/
+ git checkout $BRANCH_OR_TAG
+ $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install .
+ cd ../ && rm -rf IM/
+ $SNAPCRAFT_PART_INSTALL/usr/bin/pip3 install .
+ rm -rf .tox
+ snapcraftctl build