initial delivery of python-osmclient
authorMike Marchetti <mmarchetti@sandvine.com>
Tue, 18 Apr 2017 15:56:04 +0000 (11:56 -0400)
committerMike Marchetti <mmarchetti@sandvine.com>
Tue, 18 Apr 2017 16:01:30 +0000 (12:01 -0400)
Signed-off-by: Mike Marchetti <mmarchetti@sandvine.com>
python-osmclient/.gitignore [new file with mode: 0644]
python-osmclient/Makefile [new file with mode: 0644]
python-osmclient/README.md [new file with mode: 0644]
python-osmclient/osmclient/__init__.py [new file with mode: 0644]
python-osmclient/osmclient/common/OsmAPI.py [new file with mode: 0644]
python-osmclient/osmclient/common/__init__.py [new file with mode: 0644]
python-osmclient/osmclient/scripts/__init__.py [new file with mode: 0644]
python-osmclient/osmclient/scripts/osm.py [new file with mode: 0755]
python-osmclient/setup.py [new file with mode: 0644]
python-osmclient/stdeb.cfg [new file with mode: 0644]

diff --git a/python-osmclient/.gitignore b/python-osmclient/.gitignore
new file mode 100644 (file)
index 0000000..e09c6a0
--- /dev/null
@@ -0,0 +1,90 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+deb_dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+.hypothesis/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# IPython Notebook
+.ipynb_checkpoints
+
+# pyenv
+.python-version
+
+# celery beat schedule file
+celerybeat-schedule
+
+# dotenv
+.env
+
+# virtualenv
+venv/
+ENV/
+
+# Spyder project settings
+.spyderproject
+
+# Rope project settings
+.ropeproject
diff --git a/python-osmclient/Makefile b/python-osmclient/Makefile
new file mode 100644 (file)
index 0000000..1a2e448
--- /dev/null
@@ -0,0 +1,2 @@
+package:
+       @python setup.py --command-packages=stdeb.command bdist_deb > /dev/null 2>&1
diff --git a/python-osmclient/README.md b/python-osmclient/README.md
new file mode 100644 (file)
index 0000000..8d41f2f
--- /dev/null
@@ -0,0 +1,73 @@
+# python-osmclient
+A python client for osm orchestration
+
+# Installation
+
+## Install dependencies
+```bash
+sudo apt-get install python-dev libcurl4-gnutls-dev python-pip libgnutls-dev python-prettytable   
+sudo pip install pycurl
+```
+
+# Setup
+Set the OSM_HOSTNAME variable to the host of the osm server.
+
+Example
+```bash
+localhost$ export OSM_HOSTNAME=<hostname>:8008
+```
+
+# Examples 
+
+## upload vnfd
+```bash
+localhost$ osm upload-package ubuntu_xenial_vnf.tar.gz
+{'transaction_id': 'ec12af77-1b91-4c84-b233-60f2c2c16d14'}
+localhost$ osm vnfd-list
++--------------------+--------------------+
+| vnfd name          | id                 |
++--------------------+--------------------+
+| ubuntu_xenial_vnfd | ubuntu_xenial_vnfd |
++--------------------+--------------------+
+```
+
+## upload nsd
+```bash
+localhost$ osm upload-package ubuntu_xenial_ns.tar.gz
+{'transaction_id': 'b560c9cb-43e1-49ef-a2da-af7aab24ce9d'}
+localhost$ osm nsd-list
++-------------------+-------------------+
+| nsd name          | id                |
++-------------------+-------------------+
+| ubuntu_xenial_nsd | ubuntu_xenial_nsd |
++-------------------+-------------------+
+```
+## vim-list
+
+```bash
+localhost$ osm vim-list
++-------------+-----------------+--------------------------------------+
+| ro-account  | datacenter name | uuid                                 |
++-------------+-----------------+--------------------------------------+
+| osmopenmano | openstack-site  | 2ea04690-0e4a-11e7-89bc-00163e59ff0c |
++-------------+-----------------+--------------------------------------+
+```
+
+
+## instantiate ns
+```bash
+localhost$ osm ns-create ubuntu_xenial_nsd testns openstack-site
+{'success': ''}
+localhost$ osm ns-list
++------------------+--------------------------------------+-------------------+--------------------+---------------+
+| ns instance name | id                                   | catalog name      | operational status | config status |
++------------------+--------------------------------------+-------------------+--------------------+---------------+
+| testns           | 6b0d2906-13d4-11e7-aa01-b8ac6f7d0c77 | ubuntu_xenial_nsd | running            | configured    |
++------------------+--------------------------------------+-------------------+--------------------+---------------+
+```
+
+# Bash Completion
+python-osmclient uses [click](http://click.pocoo.org/5/).  You can setup bash completion by putting this in your .bashrc:
+    
+    eval "$(_OSM_COMPLETE=source osm)"
+
diff --git a/python-osmclient/osmclient/__init__.py b/python-osmclient/osmclient/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/python-osmclient/osmclient/common/OsmAPI.py b/python-osmclient/osmclient/common/OsmAPI.py
new file mode 100644 (file)
index 0000000..f85e872
--- /dev/null
@@ -0,0 +1,436 @@
+from io import BytesIO 
+import pycurl
+import json
+import pprint
+import uuid
+from prettytable import PrettyTable
+import time
+
+class OsmAPI():
+    def __init__(self,host,upload_port=8443):
+        if host is None:
+            raise Exception('missing host specifier')
+         
+        self._user='admin'
+        self._password='admin'
+        self._host=host
+        self._upload_port=upload_port
+        self._url = 'https://{}/'.format(self._host)
+        self._upload_url = 'https://{}:{}/'.format(self._host.split(':')[0],self._upload_port)
+
+    def get_curl_cmd(self,url):
+        curl_cmd = pycurl.Curl()
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.URL, self._url + url )
+        curl_cmd.setopt(pycurl.SSL_VERIFYPEER,0)
+        curl_cmd.setopt(pycurl.SSL_VERIFYHOST,0)
+        curl_cmd.setopt(pycurl.USERPWD, '{}:{}'.format(self._user,self._password))
+        curl_cmd.setopt(pycurl.HTTPHEADER, ['Accept: application/vnd.yand.data+json','Content-Type": "application/vnd.yang.data+json'])
+        return curl_cmd
+
+    def get_curl_upload_cmd(self,filename):
+        curl_cmd = pycurl.Curl()
+        curl_cmd.setopt(pycurl.HTTPPOST,[(('package',(pycurl.FORM_FILE,filename)))])
+        curl_cmd.setopt(pycurl.URL, self._upload_url + 'composer/upload?api_server=https://localhost&upload_server=https://' + self._host.split(':')[0])
+        curl_cmd.setopt(pycurl.SSL_VERIFYPEER,0)
+        curl_cmd.setopt(pycurl.SSL_VERIFYHOST,0)
+        curl_cmd.setopt(pycurl.USERPWD, '{}:{}'.format(self._user,self._password))
+        return curl_cmd
+
+    def get_ns_opdata(self,id):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/operational/ns-instance-opdata/nsr/{}?deep'.format(id))
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        if data.getvalue():
+           return json.loads(data.getvalue().decode())
+        return None 
+
+    def get_ns_catalog(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/running/nsd-catalog/nsd')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        if data.getvalue():
+          resp = json.loads(data.getvalue().decode())
+          return resp
+        return {'nsd:nsd': []}
+
+    def get_config_agents(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/config/config-agent')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        if data.getvalue():
+          resp = json.loads(data.getvalue().decode())
+          if 'rw-config-agent:config-agent' in resp:
+            return resp['rw-config-agent:config-agent']['account']
+        return list()
+
+    def delete_config_agent(self,name):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/config/config-agent/account/'+name)
+        curl_cmd.setopt(pycurl.CUSTOMREQUEST, "DELETE")
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def add_config_agent(self,name,account_type,server,user,secret):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/config/config-agent')
+        curl_cmd.setopt(pycurl.POST,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+
+        postdata={}
+        postdata['account'] = list()
+
+        account={}
+        account['name'] = name
+        account['account-type'] = account_type
+        account['juju'] = {}
+        account['juju']['user'] = user 
+        account['juju']['secret'] = secret
+        account['juju']['ip-address'] = server
+        postdata['account'].append(account)
+
+        jsondata=json.dumps(postdata)
+        curl_cmd.setopt(pycurl.POSTFIELDS,jsondata)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def get_ns_instance_list(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/running/ns-instance-config')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        return resp['nsr:ns-instance-config']
+
+    def get_vnf_catalog(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/running/vnfd-catalog/vnfd')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        if data.getvalue():
+          resp = json.loads(data.getvalue().decode())
+          return resp
+        return {'vnfd:vnfd': []}
+
+    def get_vcs_info(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/operational/vcs/info')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        if data.getvalue():
+          resp = json.loads(data.getvalue().decode())
+          return resp['rw-base:info']['components']['component_info']
+        return list()
+
+    def get_vnfr_catalog(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('v1/api/operational/vnfr-catalog/vnfr')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        if data.getvalue():
+          resp = json.loads(data.getvalue().decode())
+          return resp
+        return None 
+
+    def get_vnf(self,vnf_name):
+        vnfs=self.get_vnfr_catalog()
+        for vnf in vnfs['vnfr:vnfr']:
+            if vnf_name == vnf['name']:
+                return vnf
+        return None
+
+    def get_vnf_monitoring(self,vnf_name):
+        vnf=self.get_vnf(vnf_name)
+        if vnf is not None:
+            if 'monitoring-param' in vnf:
+                return vnf['monitoring-param'] 
+        return None
+
+    def get_ns_monitoring(self,ns_name):
+        ns=self.get_ns(ns_name)
+        if ns is None:
+            raise Exception('cannot find ns {}'.format(ns_name)) 
+
+        vnfs=self.get_vnfr_catalog()
+        if vnfs is None:
+            return None
+        mon_list={}
+        for vnf in vnfs['vnfr:vnfr']:
+            if ns['id'] == vnf['nsr-id-ref']:
+                if 'monitoring-param' in vnf:
+                    mon_list[vnf['name']] = vnf['monitoring-param']
+
+        return mon_list 
+
+    def list_key_pair(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('v1/api/config/key-pair?deep')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        if 'nsr:key-pair' in resp:
+            return resp['nsr:key-pair']
+        return list()
+
+    def list_ns_catalog(self):
+        resp = self.get_ns_catalog()
+        table=PrettyTable(['nsd name','id'])
+        for ns in resp['nsd:nsd']:
+            table.add_row([ns['name'],ns['id']])
+        table.align='l'
+        print(table)
+
+    def list_ns_instance(self):
+        resp = self.get_ns_instance_list()
+        table=PrettyTable(['ns instance name','id','catalog name','operational status','config status'])
+        if 'nsr' in resp:
+            for ns in resp['nsr']:
+                nsopdata=self.get_ns_opdata(ns['id'])
+                nsr=nsopdata['nsr:nsr']
+                table.add_row([nsr['name-ref'],nsr['ns-instance-config-ref'],nsr['nsd-name-ref'],nsr['operational-status'],nsr['config-status']])
+        table.align='l'
+        print(table)
+
+    def get_nsd(self,name):
+        resp = self.get_ns_catalog()
+        for ns in resp['nsd:nsd']:
+           if name == ns['name']:
+               return ns
+        return None 
+
+    def get_vnfd(self,name):
+        resp = self.get_vnf_catalog()
+        for vnf in resp['vnfd:vnfd']:
+           if name == vnf['name']:
+               return vnf 
+        return None 
+
+    def get_ns(self,name):
+        resp=self.get_ns_instance_list()
+        for ns in resp['nsr']:
+           if name == ns['name']:
+               return ns
+        return None 
+    
+    def instantiate_ns(self,nsd_name,nsr_name,account,vim_network_prefix=None,ssh_keys=None,description='default description',admin_status='ENABLED'):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/config/ns-instance-config/nsr')
+        curl_cmd.setopt(pycurl.POST,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+
+        postdata={}
+        postdata['nsr'] = list()
+        nsr={}
+        nsr['id']=str(uuid.uuid1())
+
+        nsd=self.get_nsd(nsd_name)
+        if nsd is None:
+            raise Exception('cannot find nsd {}'.format(nsd_name)) 
+        
+        datacenter=self.get_datacenter(account)
+        if datacenter is None:
+            raise Exception('cannot find datacenter account {}'.format(account)) 
+
+        nsr['nsd']=nsd
+        nsr['name']=nsr_name
+        nsr['short-name']=nsr_name
+        nsr['description']=description
+        nsr['admin-status']=admin_status
+        nsr['om-datacenter']=datacenter['uuid']
+
+        if ssh_keys is not None:
+            # ssh_keys is comma separate list
+            ssh_keys_format=[]
+            for key in ssh_keys.split(','):
+                ssh_keys_format.append({'key-pair-ref':key})
+
+            nsr['ssh-authorized-key']=ssh_keys_format
+
+        if vim_network_prefix is not None:
+            for index,vld in enumerate(nsr['nsd']['vld']):
+                network_name = vld['name']
+                nsr['nsd']['vld'][index]['vim-network-name'] = '{}-{}'.format(vim_network_prefix,network_name)
+
+        postdata['nsr'].append(nsr)
+        jsondata=json.dumps(postdata)
+        curl_cmd.setopt(pycurl.POSTFIELDS,jsondata)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def delete_nsd(self,nsd_name):
+        nsd=self.get_nsd(nsd_name)
+        if nsd is None:
+            raise Exception('cannot find nsd {}'.format(nsd_name)) 
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/running/nsd-catalog/nsd/'+nsd['id'])
+        curl_cmd.setopt(pycurl.CUSTOMREQUEST, "DELETE")
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def delete_vnfd(self,vnfd_name):
+        vnfd=self.get_vnfd(vnfd_name)
+        if vnfd is None:
+            raise Exception('cannot find vnfd {}'.format(vnfd_name)) 
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/running/vnfd-catalog/vnfd/'+vnfd['id'])
+        curl_cmd.setopt(pycurl.CUSTOMREQUEST, "DELETE")
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def terminate_ns(self,ns_name):
+        ns=self.get_ns(ns_name)
+        if ns is None:
+            raise Exception('cannot find ns {}'.format(ns_name)) 
+  
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/config/ns-instance-config/nsr/'+ns['id'])
+        curl_cmd.setopt(pycurl.CUSTOMREQUEST, "DELETE")
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def upload_package(self,filename):
+        data = BytesIO()
+        curl_cmd=self.get_curl_upload_cmd(filename)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+      
+    def add_vim_account(self,name,user_name,secret,auth_url,tenant,mgmt_network,float_ip_pool,account_type='openstack'):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('api/config/cloud')
+        curl_cmd.setopt(pycurl.POST,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        vim_account={}
+        vim_account['account']={}
+
+        vim_account['account']['name'] = name
+        vim_account['account']['account-type'] = account_type
+        vim_account['account'][account_type] = {}
+        vim_account['account'][account_type]['key'] = user_name
+        vim_account['account'][account_type]['secret'] = secret
+        vim_account['account'][account_type]['auth_url'] = auth_url
+        vim_account['account'][account_type]['tenant'] = tenant
+        vim_account['account'][account_type]['mgmt-network'] = mgmt_network
+        vim_account['account'][account_type]['floating-ip-pool'] = float_ip_pool
+
+        jsondata=json.dumps(vim_account)
+        curl_cmd.setopt(pycurl.POSTFIELDS,jsondata)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        pprint.pprint(resp)
+
+    def list_vim_accounts(self):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('v1/api/operational/datacenters')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        datacenters=resp['rw-launchpad:datacenters']
+        if 'ro-accounts' in datacenters:
+            return datacenters['ro-accounts']
+        return list()
+
+    def get_datacenter(self,name):
+        data = BytesIO()
+        curl_cmd=self.get_curl_cmd('v1/api/operational/datacenters')
+        curl_cmd.setopt(pycurl.HTTPGET,1)
+        curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write)
+        curl_cmd.perform() 
+        curl_cmd.close()
+        resp = json.loads(data.getvalue().decode())
+        datacenters=resp['rw-launchpad:datacenters']
+        if 'ro-accounts' in datacenters:
+            for roaccount in datacenters['ro-accounts']:
+                if not 'datacenters' in roaccount:
+                    continue
+                for datacenter in roaccount['datacenters']:
+                    if datacenter['name'] == name:
+                        return datacenter
+        return None
+
+    def show_ns(self,ns_name):
+        resp = self.get_ns_instance_list()
+        table=PrettyTable(['attribute','value'])
+
+        if 'nsr' in resp:
+            for ns in resp['nsr']:
+                if ns_name == ns['name']:
+                    # dump ns config
+                    for k,v in ns.items():
+                        table.add_row([k,json.dumps(v,indent=2)])
+
+                    nsopdata=self.get_ns_opdata(ns['id'])
+                    nsr_optdata=nsopdata['nsr:nsr']
+                    for k,v in nsr_optdata.items():
+                        table.add_row([k,json.dumps(v,indent=2)])
+        table.align='l'
+        print(table)
+
+    def show_ns_scaling(self,ns_name):
+        resp = self.get_ns_instance_list()
+
+        table=PrettyTable(['instance-id','operational status','create-time','vnfr ids'])
+
+        if 'nsr' in resp:
+            for ns in resp['nsr']:
+                if ns_name == ns['name']:
+                    nsopdata=self.get_ns_opdata(ns['id'])
+                    scaling_records=nsopdata['nsr:nsr']['scaling-group-record']
+                    for record in scaling_records:
+                        if 'instance' in record:
+                            instances=record['instance'] 
+                            for inst in instances:
+                                table.add_row([inst['instance-id'],inst['op-status'],time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(inst['create-time'])),inst['vnfrs']])
+        table.align='l'
+        print(table)
+
+    def list_vnfr(self):
+        return self.get_vnfr_catalog()
+
+    def list_vnf_catalog(self):
+        resp = self.get_vnf_catalog()
+        table=PrettyTable(['vnfd name','id'])
+        for ns in resp['vnfd:vnfd']:
+            table.add_row([ns['name'],ns['id']])
+        table.align='l'
+        print(table)
diff --git a/python-osmclient/osmclient/common/__init__.py b/python-osmclient/osmclient/common/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/python-osmclient/osmclient/scripts/__init__.py b/python-osmclient/osmclient/scripts/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/python-osmclient/osmclient/scripts/osm.py b/python-osmclient/osmclient/scripts/osm.py
new file mode 100755 (executable)
index 0000000..d74580c
--- /dev/null
@@ -0,0 +1,191 @@
+import click
+from osmclient.common import OsmAPI
+from prettytable import PrettyTable
+import pprint
+import textwrap
+
+@click.group()
+@click.option('--hostname',default=None,envvar='OSM_HOSTNAME',help='hostname of server.  Also can set OSM_HOSTNAME in environment')
+@click.pass_context
+def cli(ctx,hostname):
+    if hostname is None:
+        print("either hostname option or OSM_HOSTNAME environment variable needs to be specified") 
+        exit(1)
+    ctx.obj=OsmAPI.OsmAPI(hostname)
+
+@cli.command(name='ns-list')
+@click.pass_context
+def ns_list(ctx):
+    ctx.obj.list_ns_instance()
+
+@cli.command(name='nsd-list')
+@click.pass_context
+def nsd_list(ctx):
+    ctx.obj.list_ns_catalog()
+
+@cli.command(name='vnfd-list')
+@click.pass_context
+def vnfd_list(ctx):
+    ctx.obj.list_vnf_catalog()
+
+@cli.command(name='vnf-list')
+@click.pass_context
+def vnf_list(ctx):
+    resp=ctx.obj.list_vnfr()
+    table=PrettyTable(['vnf name','id','operational status','config Status','mgmt interface','nsr id'])
+    if resp is not None:
+        for vnfr in resp['vnfr:vnfr']:
+            if not 'mgmt-interface' in vnfr:
+                vnfr['mgmt-interface'] = {}
+                vnfr['mgmt-interface']['ip-address'] = None
+            table.add_row([vnfr['name'],vnfr['id'],vnfr['operational-status'],vnfr['config-status'],vnfr['mgmt-interface']['ip-address'],vnfr['nsr-id-ref']])
+        table.align='l'
+    print(table)
+
+@cli.command(name='vnf-monitoring-show')
+@click.argument('vnf_name')
+@click.pass_context
+def vnf_monitoring_show(ctx,vnf_name):
+    resp=ctx.obj.get_vnf_monitoring(vnf_name)
+    table=PrettyTable(['vnf name','monitoring name','value','units'])
+    if resp is not None:
+        for monitor in resp:
+            table.add_row([vnf_name,monitor['name'],monitor['value-integer'],monitor['units']])
+    table.align='l'
+    print(table)
+
+@cli.command(name='ns-monitoring-show')
+@click.argument('ns_name')
+@click.pass_context
+def ns_monitoring_show(ctx,ns_name):
+    resp=ctx.obj.get_ns_monitoring(ns_name)
+    table=PrettyTable(['vnf name','monitoring name','value','units'])
+    if resp is not None:
+        for key,val in resp.items():
+            for monitor in val:
+                table.add_row([key,monitor['name'],monitor['value-integer'],monitor['units']])
+    table.align='l'
+    print(table)
+
+@cli.command(name='ns-create')
+@click.argument('nsd_name')
+@click.argument('ns_name')
+@click.argument('vim_account')
+@click.option('--admin_status',default='ENABLED',help='administration status')
+@click.option('--ssh_keys',default=None,help='comma separated list of keys to inject to vnfs')
+@click.option('--vim_network_prefix',default=None,help='vim network name prefix')
+@click.pass_context
+def ns_create(ctx,nsd_name,ns_name,vim_account,admin_status,ssh_keys,vim_network_prefix):
+    ctx.obj.instantiate_ns(nsd_name,ns_name,vim_network_prefix=vim_network_prefix,ssh_keys=ssh_keys,account=vim_account)
+
+@cli.command(name='ns-delete')
+@click.argument('ns_name')
+@click.pass_context
+def ns_delete(ctx,ns_name):
+    ctx.obj.terminate_ns(ns_name)
+
+'''
+@cli.command(name='keypair-list')
+@click.pass_context
+def keypair_list(ctx):
+    resp=ctx.obj.list_key_pair()
+    table=PrettyTable(['key Name','key'])
+    for kp in resp:
+        table.add_row([kp['name'],kp['key']])
+    table.align='l'
+    print(table)
+'''
+
+@cli.command(name='upload-package')
+@click.argument('filename')
+@click.pass_context
+def upload_package(ctx,filename):
+    ctx.obj.upload_package(filename)
+
+@cli.command(name='ns-show')
+@click.argument('ns_name')
+@click.pass_context
+def ns_show(ctx,ns_name):
+    ctx.obj.show_ns(ns_name)
+
+@cli.command(name='ns-scaling-show')
+@click.argument('ns_name')
+@click.pass_context
+def show_ns_scaling(ctx,ns_name):
+    ctx.obj.show_ns_scaling(ns_name)
+
+@cli.command(name='nsd-delete')
+@click.argument('nsd_name')
+@click.pass_context
+def nsd_delete(ctx,nsd_name):
+    ctx.obj.delete_nsd(nsd_name)
+
+@cli.command(name='vnfd-delete')
+@click.argument('vnfd_name')
+@click.pass_context
+def nsd_delete(ctx,vnfd_name):
+    ctx.obj.delete_vnfd(vnfd_name)
+
+@cli.command(name='config-agent-list')
+@click.pass_context
+def config_agent_list(ctx):
+    table=PrettyTable(['name','account-type','details'])
+    for account in ctx.obj.get_config_agents():
+      table.add_row([account['name'],account['account-type'],account['juju']])
+    table.align='l'
+    print(table)
+
+@cli.command(name='config-agent-delete')
+@click.argument('name')
+@click.pass_context
+def config_agent_delete(ctx,name):
+    ctx.obj.delete_config_agent(name)
+
+@cli.command(name='config-agent-add')
+@click.argument('name')
+@click.argument('account_type')
+@click.argument('server')
+@click.argument('user')
+@click.argument('secret')
+@click.pass_context
+def config_agent_add(ctx,name,account_type,server,user,secret):
+    ctx.obj.add_config_agent(name,account_type,server,user,secret)
+
+'''
+@cli.command(name='vim-create')
+@click.argument('name')
+@click.argument('user')
+@click.argument('password')
+@click.argument('auth_url')
+@click.argument('tenant')
+@click.argument('mgmt_network')
+@click.argument('floating_ip_pool')
+@click.option('--account_type',default='openstack')
+@click.pass_context
+def vim_create(ctx,name,user,password,auth_url,tenant,mgmt_network,floating_ip_pool,account_type):
+    ctx.obj.add_vim_account(name,user,password,auth_url,tenant,mgmt_network,floating_ip_pool,account_type)
+'''
+
+@cli.command(name='vim-list')
+@click.pass_context
+def vim_list(ctx):
+    resp=ctx.obj.list_vim_accounts()
+    table=PrettyTable(['ro-account','datacenter name','uuid'])
+    for roaccount in resp:
+        for datacenter in roaccount['datacenters']:
+            table.add_row([roaccount['name'],datacenter['name'],datacenter['uuid']])
+    table.align='l'
+    print(table)
+
+@cli.command(name='vcs-list')
+@click.pass_context
+def vcs_list(ctx):
+    resp=ctx.obj.get_vcs_info()
+    table=PrettyTable(['component name','state'])
+    for component in resp:
+        table.add_row([component['component_name'],component['state']])
+    table.align='l'
+    print(table)
+
+if __name__ == '__main__':
+    cli()
diff --git a/python-osmclient/setup.py b/python-osmclient/setup.py
new file mode 100644 (file)
index 0000000..13b1771
--- /dev/null
@@ -0,0 +1,17 @@
+from setuptools import setup,find_packages
+
+setup(
+    name='osmclient',
+    version='0.1',
+    author='Mike Marchetti',
+    author_email='mmarchetti@sandvine.com',
+    packages=find_packages(),
+    include_package_data=True,
+    install_requires=[
+        'Click','prettytable'
+    ],
+    entry_points='''
+        [console_scripts]
+        osm=osmclient.scripts.osm:cli
+        ''',
+)
diff --git a/python-osmclient/stdeb.cfg b/python-osmclient/stdeb.cfg
new file mode 100644 (file)
index 0000000..eadf0fa
--- /dev/null
@@ -0,0 +1,2 @@
+[DEFAULT]
+Depends: python-setuptools, python-pycurl, python-click, python-prettytable