Browse Source

StarlingX open source release updates

Signed-off-by: Dean Troyer <dtroyer@gmail.com>
changes/86/573986/1
Dean Troyer 3 years ago
parent
commit
17c909ec83
524 changed files with 107907 additions and 0 deletions
  1. +8
    -0
      CONTRIBUTORS.wrs
  2. +202
    -0
      LICENSE
  3. +5
    -0
      README.rst
  4. +5
    -0
      mwa-solon.map
  5. +4
    -0
      service-mgmt-api/centos/build_srpm.data
  6. +81
    -0
      service-mgmt-api/centos/sm-api.spec
  7. +202
    -0
      service-mgmt-api/sm-api/LICENSE
  8. +114
    -0
      service-mgmt-api/sm-api/scripts/sm-api
  9. +14
    -0
      service-mgmt-api/sm-api/scripts/sm-api.conf
  10. +15
    -0
      service-mgmt-api/sm-api/scripts/sm-api.service
  11. +10
    -0
      service-mgmt-api/sm-api/scripts/sm_api.ini
  12. +31
    -0
      service-mgmt-api/sm-api/setup.py
  13. +10
    -0
      service-mgmt-api/sm-api/sm_api/__init__.py
  14. +27
    -0
      service-mgmt-api/sm-api/sm_api/api/__init__.py
  15. +76
    -0
      service-mgmt-api/sm-api/sm_api/api/acl.py
  16. +5
    -0
      service-mgmt-api/sm-api/sm_api/api/api.ini
  17. +67
    -0
      service-mgmt-api/sm-api/sm_api/api/api.py
  18. +109
    -0
      service-mgmt-api/sm-api/sm_api/api/app.py
  19. +17
    -0
      service-mgmt-api/sm-api/sm_api/api/config.py
  20. +5
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/__init__.py
  21. +65
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/root.py
  22. +101
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/__init__.py
  23. +55
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/base.py
  24. +55
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/collection.py
  25. +30
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/link.py
  26. +144
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/nodes.py
  27. +164
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/service_groups.py
  28. +447
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/servicenode.py
  29. +144
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/services.py
  30. +162
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/sm_sda.py
  31. +160
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/smc_api.py
  32. +98
    -0
      service-mgmt-api/sm-api/sm_api/api/controllers/v1/utils.py
  33. +98
    -0
      service-mgmt-api/sm-api/sm_api/api/hooks.py
  34. +19
    -0
      service-mgmt-api/sm-api/sm_api/api/middleware/__init__.py
  35. +34
    -0
      service-mgmt-api/sm-api/sm_api/api/middleware/auth_token.py
  36. +95
    -0
      service-mgmt-api/sm-api/sm_api/api/middleware/parsable_error.py
  37. +30
    -0
      service-mgmt-api/sm-api/sm_api/cmd/__init__.py
  38. +82
    -0
      service-mgmt-api/sm-api/sm_api/cmd/api.py
  39. +5
    -0
      service-mgmt-api/sm-api/sm_api/common/__init__.py
  40. +34
    -0
      service-mgmt-api/sm-api/sm_api/common/config.py
  41. +45
    -0
      service-mgmt-api/sm-api/sm_api/common/context.py
  42. +401
    -0
      service-mgmt-api/sm-api/sm_api/common/exception.py
  43. +77
    -0
      service-mgmt-api/sm-api/sm_api/common/log.py
  44. +135
    -0
      service-mgmt-api/sm-api/sm_api/common/policy.py
  45. +59
    -0
      service-mgmt-api/sm-api/sm_api/common/safe_utils.py
  46. +70
    -0
      service-mgmt-api/sm-api/sm_api/common/service.py
  47. +678
    -0
      service-mgmt-api/sm-api/sm_api/common/utils.py
  48. +10
    -0
      service-mgmt-api/sm-api/sm_api/db/__init__.py
  49. +175
    -0
      service-mgmt-api/sm-api/sm_api/db/api.py
  50. +49
    -0
      service-mgmt-api/sm-api/sm_api/db/migration.py
  51. +0
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/__init__.py
  52. +267
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/api.py
  53. +0
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/migrate_repo/__init__.py
  54. +26
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/migrate_repo/manage.py
  55. +20
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/migrate_repo/migrate.cfg
  56. +74
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/migrate_repo/versions/001_init.py
  57. +0
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/migrate_repo/versions/__init__.py
  58. +116
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/migration.py
  59. +154
    -0
      service-mgmt-api/sm-api/sm_api/db/sqlalchemy/models.py
  60. +56
    -0
      service-mgmt-api/sm-api/sm_api/objects/__init__.py
  61. +504
    -0
      service-mgmt-api/sm-api/sm_api/objects/base.py
  62. +72
    -0
      service-mgmt-api/sm-api/sm_api/objects/smo_node.py
  63. +81
    -0
      service-mgmt-api/sm-api/sm_api/objects/smo_sda.py
  64. +72
    -0
      service-mgmt-api/sm-api/sm_api/objects/smo_sdm.py
  65. +77
    -0
      service-mgmt-api/sm-api/sm_api/objects/smo_service.py
  66. +80
    -0
      service-mgmt-api/sm-api/sm_api/objects/smo_servicegroup.py
  67. +129
    -0
      service-mgmt-api/sm-api/sm_api/objects/utils.py
  68. +0
    -0
      service-mgmt-api/sm-api/sm_api/openstack/__init__.py
  69. +0
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/__init__.py
  70. +67
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/cliutils.py
  71. +258
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/config/generator.py
  72. +86
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/context.py
  73. +20
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/__init__.py
  74. +110
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/api.py
  75. +58
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/exception.py
  76. +20
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/__init__.py
  77. +109
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/models.py
  78. +700
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/session.py
  79. +150
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/utils.py
  80. +93
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/eventlet_backdoor.py
  81. +55
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/excutils.py
  82. +114
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/fileutils.py
  83. +0
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/fixture/__init__.py
  84. +55
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/fixture/mockpatch.py
  85. +41
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/fixture/moxstubout.py
  86. +54
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/gettextutils.py
  87. +71
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/importutils.py
  88. +173
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/jsonutils.py
  89. +52
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/local.py
  90. +282
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/lockutils.py
  91. +562
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/log.py
  92. +35
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/log_handler.py
  93. +151
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/loopingcall.py
  94. +73
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/network_utils.py
  95. +18
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/notifier/__init__.py
  96. +186
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/notifier/api.py
  97. +39
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/notifier/log_notifier.py
  98. +23
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/notifier/no_op_notifier.py
  99. +50
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/notifier/rpc_notifier.py
  100. +56
    -0
      service-mgmt-api/sm-api/sm_api/openstack/common/notifier/rpc_notifier2.py

+ 8
- 0
CONTRIBUTORS.wrs View File

@ -0,0 +1,8 @@
The following contributors from Wind River have developed the seed code in this
repository. We look forward to community collaboration and contributions for
additional features, enhancements and refactoring.
Contributors:
=============
Bin Qian <Bin.Qian@windriver.com>
Eric Macdonald <Eric.MacDonald@windriver.com>

+ 202
- 0
LICENSE View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

+ 5
- 0
README.rst View File

@ -0,0 +1,5 @@
======
stx-ha
======
SterlingX Service Management

+ 5
- 0
mwa-solon.map View File

@ -0,0 +1,5 @@
cgcs/recipes-svcmgmt/service-mgmt-api|service-mgmt-api
cgcs/recipes-svcmgmt/service-mgmt-client|service-mgmt-client
cgcs/recipes-svcmgmt/service-mgmt-tools|service-mgmt-tools
cgcs/recipes-svcmgmt/service-mgmt|service-mgmt
cgcs/middleware/mtce/recipes-common/cgts-mtce-common/cgts-mtce-common-1.0/pmon|pmon

+ 4
- 0
service-mgmt-api/centos/build_srpm.data View File

@ -0,0 +1,4 @@
SRC_DIR=sm-api
TAR_NAME=sm-api
VERSION=1.0
TIS_PATCH_VER=2

+ 81
- 0
service-mgmt-api/centos/sm-api.spec View File

@ -0,0 +1,81 @@
Summary: Service Management API
Name: sm-api
Version: 1.0
Release: %{tis_patch_ver}%{?_tis_dist}
License: Apache-2.0
Group: base
Packager: Wind River <info@windriver.com>
URL: unknown
Source0: %{name}-%{version}.tar.gz
%define debug_package %{nil}
BuildRequires: python
BuildRequires: python-setuptools
BuildRequires: util-linux
# BuildRequires systemd is to get %_unitdir I think
BuildRequires: systemd
BuildRequires: systemd-devel
Requires: python-libs
# Needed for /etc/init.d, can be removed when we go fully systemd
Requires: chkconfig
# Needed for /etc/pmon.d
Requires: cgts-mtce-common-pmon
%prep
%setup -q
%build
%{__python2} setup.py build
%install
%global _buildsubdir %{_builddir}/%{name}-%{version}
%{__python2} setup.py install -O1 --skip-build --root %{buildroot}
install -d %{buildroot}/etc/sm
install -d %{buildroot}/etc/init.d
install -d %{buildroot}/etc/pmon.d
install -d %{buildroot}%{_unitdir}
install -m 644 %{_buildsubdir}/scripts/sm_api.ini %{buildroot}/etc/sm
install -m 755 %{_buildsubdir}/scripts/sm-api %{buildroot}/etc/init.d
install -m 644 %{_buildsubdir}/scripts/sm-api.service %{buildroot}%{_unitdir}
install -m 644 %{_buildsubdir}/scripts/sm-api.conf %{buildroot}/etc/pmon.d
%description
Service Management API
#%package -n sm-api-py-src-tar
#Summary: Service Management API
#Group: base
#%description -n sm-api-py-src-tar
#Service Management API
#%post -n sm-api-py-src-tar
## sm-api-py-src-tar - postinst
# if [ -f $D/usr/src/sm-api-1.0.tar.bz2 ] ; then
# ( cd $D/ && tar -xf $D/usr/src/sm-api-1.0.tar.bz2 )
# fi
%post
/usr/bin/systemctl enable sm-api.service >/dev/null 2>&1
%files
%defattr(-,root,root,-)
%dir "/usr/lib/python2.7/site-packages/sm_api"
/usr/lib/python2.7/site-packages/sm_api/*
%dir "/usr/lib/python2.7/site-packages/sm_api-1.0.0-py2.7.egg-info"
/usr/lib/python2.7/site-packages/sm_api-1.0.0-py2.7.egg-info/*
"/usr/bin/sm-api"
%dir "/etc/sm"
"/etc/init.d/sm-api"
"/etc/pmon.d/sm-api.conf"
"/etc/sm/sm_api.ini"
%{_unitdir}/*
#%files -n sm-api-py-src-tar
#%defattr(-,-,-,-)
#"/usr/src/sm-api-1.0.tar.bz2"

+ 202
- 0
service-mgmt-api/sm-api/LICENSE View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

+ 114
- 0
service-mgmt-api/sm-api/scripts/sm-api View File

@ -0,0 +1,114 @@
#! /bin/sh
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# chkconfig: - 60 60
# processname: sm-api
# description: Service Management API
#
### BEGIN INIT INFO
# Description: sm-api...
#
# Short-Description: Service Management API.
# Provides: sm-api
# Required-Start: $network
# Should-Start: $syslog
# Required-Stop: $network
# Default-Start: 3 5
# Default-Stop: 0 6
### END INIT INFO
. /etc/init.d/functions
# Linux Standard Base (LSB) Error Codes
RETVAL=0
LSB_GENERIC_ERROR=1
LSB_INVALID_ARGS=2
LSB_UNSUPPORTED_FEATURE=3
LSB_NOT_INSTALLED=5
LSB_NOT_RUNNING=7
SM_API_NAME="sm-api"
SM_API="/usr/bin/${SM_API_NAME}"
daemon_pidfile="/var/run/${SM_API_NAME}.pid"
if [ ! -e "${SM_API}" ] ; then
logger "${SM_API} is missing"
exit ${LSB_NOT_INSTALLED}
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
export PATH
case "$1" in
start)
echo -n "Starting ${SM_API_NAME}: "
if [ -n "`pidof ${SM_API_NAME}`" ] ; then
echo -n "is already running "
RETVAL=0
else
/bin/sh -c "${SM_API} --debug --verbose --use-syslog --syslog-log-facility local1"' >> /dev/null 2>&1 & echo $!' > ${daemon_pidfile}
RETVAL=$?
fi
if [ ${RETVAL} -eq 0 ] ; then
pid=`pidof ${SM_API_NAME}`
echo "OK"
logger "${SM_API} (${pid})"
else
echo "FAIL"
RETVAL=${LSB_GENERIC_ERROR}
fi
;;
stop)
echo " "
echo -n "Stopping ${SM_API_NAME}: "
if [ -e ${daemon_pidfile} ] ; then
pid=`cat ${daemon_pidfile}`
kill -TERM $pid
rm -f ${daemon_pidfile}
rm -f /var/lock/subsys/${SM_API_NAME}
echo "OK"
else
echo "FAIL"
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
if [ -e ${daemon_pidfile} ] ; then
pid=`cat ${daemon_pidfile}`
ps -p $pid | grep -v "PID TTY" >> /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "${SM_API_NAME} is running"
RETVAL=0
else
echo "${SM_API_NAME} is NOT running"
RETVAL=1
fi
else
echo "${SM_API_NAME} is running; no pidfile"
RETVAL=1
fi
;;
condrestart)
[ -f /var/lock/subsys/${SM_API_NAME} ] && $0 restart
;;
*)
echo "usage: $0 { start | stop | status | restart | condrestart | status }"
;;
esac
exit ${RETVAL}

+ 14
- 0
service-mgmt-api/sm-api/scripts/sm-api.conf View File

@ -0,0 +1,14 @@
;
; Copyright (c) 2014 Wind River Systems, Inc.
;
; SPDX-License-Identifier: Apache-2.0
;
[process]
process = sm-api
pidfile = /var/run/sm-api.pid
script = /etc/init.d/sm-api
style = lsb ; ocf or lsb
severity = major ; minor, major, critical
restarts = 3 ; restarts before error assertion
interval = 5 ; number of seconds to wait between restarts
debounce = 20 ; number of seconds to wait before degrade clear

+ 15
- 0
service-mgmt-api/sm-api/scripts/sm-api.service View File

@ -0,0 +1,15 @@
[Unit]
Description=Service Management API Unit
After=network-online.target syslog-ng.service config.service sm.service
Before=sm-eru.service pmon.service
[Service]
Type=forking
RemainAfterExit=yes
User=root
ExecStart=/etc/init.d/sm-api start
ExecStop=/etc/init.d/sm-api stop
PIDFile=/var/run/sm-api.pid
[Install]
WantedBy=multi-user.target

+ 10
- 0
service-mgmt-api/sm-api/scripts/sm_api.ini View File

@ -0,0 +1,10 @@
;
; Copyright (c) 2014 Wind River Systems, Inc.
;
; SPDX-License-Identifier: Apache-2.0
;
[logging]
use_syslog=
[database]
database=/etc/sm/sm.database.v1

+ 31
- 0
service-mgmt-api/sm-api/setup.py View File

@ -0,0 +1,31 @@
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import setuptools
setuptools.setup(
name='sm_api',
description='Service Management API',
version='1.0.0',
license='Apache-2.0',
packages=['sm_api', 'sm_api.common', 'sm_api.db', 'sm_api.objects',
'sm_api.api', 'sm_api.api.controllers', 'sm_api.api.middleware',
'sm_api.api.controllers.v1', 'sm_api.cmd',
'sm_api.db.sqlalchemy',
'sm_api.db.sqlalchemy.migrate_repo',
'sm_api.db.sqlalchemy.migrate_repo.versions',
'sm_api.openstack', 'sm_api.openstack.common',
'sm_api.openstack.common.db',
'sm_api.openstack.common.db.sqlalchemy',
'sm_api.openstack.common.rootwrap',
'sm_api.openstack.common.rpc',
'sm_api.openstack.common.notifier',
'sm_api.openstack.common.config',
'sm_api.openstack.common.fixture'],
entry_points={
'console_scripts': [
'sm-api = sm_api.cmd.api:main'
]}
)

+ 10
- 0
service-mgmt-api/sm-api/sm_api/__init__.py View File

@ -0,0 +1,10 @@
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#

+ 27
- 0
service-mgmt-api/sm-api/sm_api/api/__init__.py View File

@ -0,0 +1,27 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from oslo_config import cfg
API_SERVICE_OPTS = [
cfg.StrOpt('sm_api_bind_ip',
default='0.0.0.0',
help='IP for the Service Management API server to bind to',
),
cfg.IntOpt('sm_api_port',
default=7777,
help='The port for the Service Management API server',
),
cfg.IntOpt('api_limit_max',
default=1000,
help='the maximum number of items returned in a single '
'response from a collection resource'),
]
CONF = cfg.CONF
opt_group = cfg.OptGroup(name='api',
title='Options for the sm-api service')
CONF.register_group(opt_group)
CONF.register_opts(API_SERVICE_OPTS)

+ 76
- 0
service-mgmt-api/sm-api/sm_api/api/acl.py View File

@ -0,0 +1,76 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 New Dream Network, LLC (DreamHost)
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
#
# 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.
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
"""Access Control Lists (ACL's) control access the API server."""
from keystonemiddleware import auth_token as keystone_auth_token
from oslo_config import cfg
from pecan import hooks
from webob import exc
from sm_api.api.middleware import auth_token
from sm_api.common import policy
OPT_GROUP_NAME = 'keystone_authtoken'
def register_opts(conf):
"""Register keystoneclient middleware options
:param conf: SmApi settings.
"""
#conf.register_opts(keystone_auth_token._OPTS, group=OPT_GROUP_NAME)
keystone_auth_token.CONF = conf
register_opts(cfg.CONF)
def install(app, conf, public_routes):
"""Install ACL check on application.
:param app: A WSGI applicatin.
:param conf: Settings. Must include OPT_GROUP_NAME section.
:param public_routes: The list of the routes which will be allowed to
access without authentication.
:return: The same WSGI application with ACL installed.
"""
keystone_config = dict(conf.get(OPT_GROUP_NAME))
return auth_token.AuthTokenMiddleware(app,
conf=keystone_config,
public_api_routes=public_routes)
class AdminAuthHook(hooks.PecanHook):
"""Verify that the user has admin rights.
Checks whether the request context is an admin context and
rejects the request otherwise.
"""
def before(self, state):
ctx = state.request.context
if not policy.check_is_admin(ctx) and not ctx.is_public_api:
raise exc.HTTPForbidden()

+ 5
- 0
service-mgmt-api/sm-api/sm_api/api/api.ini View File

@ -0,0 +1,5 @@
[logging]
use_syslog=
[database]
database=/tmp/sm.database.v1

+ 67
- 0
service-mgmt-api/sm-api/sm_api/api/api.py View File

@ -0,0 +1,67 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import os
import sys
import argparse
import ConfigParser
import eventlet
from wsgiref import simple_server
from sm_api.common import config
from sm_api.common import log
from sm_api import app
os.environ['EVENTLET_NO_GREENDNS'] = 'yes'
eventlet.monkey_patch(os=False)
def get_handler_cls():
cls = simple_server.WSGIRequestHandler
# old-style class doesn't support super
class MyHandler(cls, object):
def address_string(self):
# In the future, we could provide a config option to allow reverse DNS lookup
return self.client_address[0]
return MyHandler
def main():
try:
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', required=True,
help='configuration file')
args = parser.parse_args()
config.load(args.config)
if not config.CONF:
print "Error: configuration not available."
sys.exit(-1)
log.configure(config.CONF)
wsgi = simple_server.make_server('0.0.0.0', 7777, app.Application(),
handler_class=get_handler_cls())
wsgi.serve_forever()
except ConfigParser.NoOptionError as e:
print e
sys.exit(-2)
except ConfigParser.NoSectionError as e:
print e
sys.exit(-3)
except KeyboardInterrupt:
sys.exit()
except Exception as e:
print e
sys.exit(-4)
main()

+ 109
- 0
service-mgmt-api/sm-api/sm_api/api/app.py View File

@ -0,0 +1,109 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
"""
Application
"""
from oslo_config import cfg
import pecan
from sm_api.api import config
from sm_api.api import hooks
from sm_api.api import acl
from sm_api.api import middleware
auth_opts = [
cfg.StrOpt('auth_strategy',
default='noauth',
help='Method to use for auth: noauth or keystone.'),
]
CONF = cfg.CONF
CONF.register_opts(auth_opts)
def get_pecan_config():
filename = config.__file__.replace('.pyc', '.py')
return pecan.configuration.conf_from_file(filename)
def create_app():
pecan_conf = get_pecan_config()
app_hooks = [hooks.ConfigHook(),
hooks.DatabaseHook()]
pecan.configuration.set_config(dict(pecan_conf), overwrite=True)
app = pecan.make_app(
pecan_conf.app.root,
static_root=pecan_conf.app.static_root,
debug=False,
force_canonical=getattr(pecan_conf.app, 'force_canonical', True),
hooks=app_hooks
)
return app
def setup_app(pecan_config=None, extra_hooks=None):
app_hooks = [hooks.ConfigHook(),
hooks.DatabaseHook(),
hooks.ContextHook(pecan_config.app.acl_public_routes),
]
# hooks.RPCHook()
if extra_hooks:
app_hooks.extend(extra_hooks)
if not pecan_config:
pecan_config = get_pecan_config()
if pecan_config.app.enable_acl:
app_hooks.append(acl.AdminAuthHook())
pecan.configuration.set_config(dict(pecan_config), overwrite=True)
app = pecan.make_app(
pecan_config.app.root,
static_root=pecan_config.app.static_root,
debug=CONF.debug,
force_canonical=getattr(pecan_config.app, 'force_canonical', True),
hooks=app_hooks,
wrap_app=middleware.ParsableErrorMiddleware,
)
if pecan_config.app.enable_acl:
return acl.install(app, cfg.CONF, pecan_config.app.acl_public_routes)
return app
class Application(object):
def __init__(self):
self.v1 = create_app()
@classmethod
def unsupported_version(cls, start_response):
start_response('404 Not Found', [])
return []
def __call__(self, environ, start_response):
if environ['PATH_INFO'].startswith("/v1/"):
return self.v1(environ, start_response)
return Application.unsupported_version(start_response)
class VersionSelectorApplication(object):
def __init__(self):
pc = get_pecan_config()
pc.app.enable_acl = (CONF.auth_strategy == 'keystone')
self.v1 = setup_app(pecan_config=pc)
def __call__(self, environ, start_response):
return self.v1(environ, start_response)

+ 17
- 0
service-mgmt-api/sm-api/sm_api/api/config.py View File

@ -0,0 +1,17 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Server Configuration
server = {'host': '0.0.0.0', 'port': '7777'}
# Pecan Application Configurations
app = {'root': 'sm_api.api.controllers.root.RootController',
'modules': ['sm_api'],
'static_root': '',
'debug': False,
'enable_acl': False,
'acl_public_routes': ['/', '/v1']
}

+ 5
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/__init__.py View File

@ -0,0 +1,5 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#

+ 65
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/root.py View File

@ -0,0 +1,65 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import pecan
from pecan import rest
from wsme import types as wsme_types
from wsmeext import pecan as wsme_pecan
from sm_api.api.controllers import v1
from sm_api.api.controllers.v1 import base
from sm_api.api.controllers.v1 import link
class Version(base.APIBase):
"""An API version representation."""
id = wsme_types.text
"The ID of the version, also acts as the release number"
links = [link.Link]
"A Link that point to a specific version of the API"
@classmethod
def convert(cls, id):
version = Version()
version.id = id
version.links = [link.Link.make_link('self', pecan.request.host_url,
id, '', bookmark=True)]
return version
class Root(base.APIBase):
name = wsme_types.text
"The name of the API"
description = wsme_types.text
"Some information about this API"
version = [Version]
"Links to all the versions available in this API"
default_version = Version
"A link to the default version of the API"
@classmethod
def convert(cls):
root = Root()
root.name = "System Management API"
root.description = "System Management API from Wind River"
root.version = [Version.convert("v1")]
root.default_version = Version.convert("v1")
return root
class RootController(rest.RestController):
v1 = v1.Controller()
@wsme_pecan.wsexpose(Root)
def get(self):
return Root.convert()

+ 101
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/__init__.py View File

@ -0,0 +1,101 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import pecan
from pecan import rest
from wsme import types as wsme_types
import wsmeext.pecan as wsme_pecan
from sm_api.api.controllers.v1 import link
from sm_api.api.controllers.v1 import service_groups
from sm_api.api.controllers.v1 import services
from sm_api.api.controllers.v1 import servicenode
from sm_api.api.controllers.v1 import sm_sda
from sm_api.api.controllers.v1 import nodes
class Version1(wsme_types.Base):
""" Version-1 of the API.
"""
id = wsme_types.text
"The ID of the version, also acts as the release number"
links = [link.Link]
"Links that point to a specific URL for this version and documentation"
service_group = [link.Link]
"Links to the SM service-group resource"
servicenode = [link.Link]
"Links to the SM service node resource"
sm_sda = [link.Link]
"Links to the SM service domain assignments resource "
@classmethod
def convert(cls):
v1 = Version1()
v1.id = "v1"
v1.links = [link.Link.make_link('self', pecan.request.host_url,
'v1', '', bookmark=True)]
v1.service_groups = [link.Link.make_link('self',
pecan.request.host_url,
'service_groups', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'service_groups', '',
bookmark=True)]
v1.services = [link.Link.make_link('self',
pecan.request.host_url,
'services', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'services', '',
bookmark=True)]
v1.servicenode = [link.Link.make_link('self',
pecan.request.host_url,
'servicenode', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'servicenode', '',
bookmark=True)]
v1.sm_sda = [link.Link.make_link('self',
pecan.request.host_url,
'sm_sda', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'sm_sda', '',
bookmark=True)]
v1.nodes = [link.Link.make_link('self',
pecan.request.host_url,
'nodes', ''),
link.Link.make_link('bookmark',
pecan.request.host_url,
'nodes', '',
bookmark=True)]
return v1
class Controller(rest.RestController):
"""Version 1 API controller root."""
service_groups = service_groups.ServiceGroupController()
services = services.ServicesController()
servicenode = servicenode.ServiceNodeController()
sm_sda = sm_sda.SmSdaController()
nodes = nodes.NodesController()
@wsme_pecan.wsexpose(Version1)
def get(self):
return Version1.convert()
__all__ = Controller

+ 55
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/base.py View File

@ -0,0 +1,55 @@
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
import datetime
import wsme
from wsme import types as wsme_types
class APIBase(wsme_types.Base):
# created_at = datetime.datetime
# "The time in UTC at which the object is created"
# updated_at = datetime.datetime
# "The time in UTC at which the object is updated"
def as_dict(self):
"""Render this object as a dict of its fields."""
return dict((k, getattr(self, k))
for k in self.fields
if hasattr(self, k) and
getattr(self, k) != wsme.Unset)
def unset_fields_except(self, except_list=None):
"""Unset fields so they don't appear in the message body.
:param except_list: A list of fields that won't be touched.
"""
if except_list is None:
except_list = []
for k in self.as_dict():
if k not in except_list:
setattr(self, k, wsme.Unset)
@classmethod
def from_rpc_object(cls, m, fields=None):
"""Convert a RPC object to an API object."""
obj_dict = m.as_dict()
# Unset non-required fields so they do not appear
# in the message body
obj_dict.update(dict((k, wsme.Unset)
for k in obj_dict.keys()
if fields and k not in fields))
return cls(**obj_dict)

+ 55
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/collection.py View File

@ -0,0 +1,55 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
import pecan
from wsme import types as wtypes
from sm_api.api.controllers.v1 import base
from sm_api.api.controllers.v1 import link
class Collection(base.APIBase):
next = wtypes.text
"A link to retrieve the next subset of the collection"
@property
def collection(self):
return getattr(self, self._type)
def has_next(self, limit):
"""Return whether collection has more items."""
return len(self.collection) and len(self.collection) == limit
def get_next(self, limit, url=None, **kwargs):
"""Return a link to the next subset of the collection."""
if not self.has_next(limit):
return wtypes.Unset
resource_url = url or self._type
q_args = ''.join(['%s=%s&' % (key, kwargs[key]) for key in kwargs])
next_args = '?%(args)slimit=%(limit)d&marker=%(marker)s' % {
'args': q_args, 'limit': limit,
'marker': self.collection[-1].uuid}
return link.Link.make_link('next', pecan.request.host_url,
resource_url, next_args).href

+ 30
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/link.py View File

@ -0,0 +1,30 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from wsme import types as wsme_types
class Link(wsme_types.Base):
""" Representation of a link.
"""
href = wsme_types.text
"The url of a link."
rel = wsme_types.text
"The name of a link."
type = wsme_types.text
"The type of document or link."
@classmethod
def make_link(cls, rel_name, url, resource, resource_args,
bookmark=False, type=wsme_types.Unset):
template = '%s/%s' if bookmark else '%s/v1/%s'
template += '%s' if resource_args.startswith('?') else '/%s'
return Link(href=template % (url, resource, resource_args),
rel=rel_name, type=type)

+ 144
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/nodes.py View File

@ -0,0 +1,144 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import json
import wsme
from wsme import types as wsme_types
import wsmeext.pecan as wsme_pecan
import pecan
from pecan import rest
from sm_api.api.controllers.v1 import base
from sm_api.api.controllers.v1 import collection
from sm_api.api.controllers.v1 import link
from sm_api.api.controllers.v1 import utils
from sm_api.common import log
from sm_api import objects
LOG = log.get_logger(__name__)
class NodesCommand(wsme_types.Base):
path = wsme_types.text
value = wsme_types.text
op = wsme_types.text
class NodesCommandResult(wsme_types.Base):
# Host Information
hostname = wsme_types.text
state = wsme_types.text
# Command
path = wsme_types.text
value = wsme_types.text
op = wsme_types.text
# Result
error_code = wsme_types.text
error_details = wsme_types.text
class Nodes(base.APIBase):
id = int
name = wsme_types.text
administrative_state = wsme_types.text
operational_state = wsme_types.text
availability_status = wsme_types.text
ready_state = wsme_types.text
links = [link.Link]
"A list containing a self link and associated nodes links"
def __init__(self, **kwargs):
self.fields = objects.sm_node.fields.keys()
for k in self.fields:
setattr(self, k, kwargs.get(k))
@classmethod
def convert_with_links(cls, rpc_nodes, expand=True):
minimum_fields = ['id', 'name', 'administrative_state',
'operational_state', 'availability_status',
'ready_state']
fields = minimum_fields if not expand else None
nodes = Nodes.from_rpc_object(
rpc_nodes, fields)
return nodes
class NodesCollection(collection.Collection):
"""API representation of a collection of nodes."""
nodes = [Nodes]
"A list containing nodes objects"
def __init__(self, **kwargs):
self._type = 'nodes'
@classmethod
def convert_with_links(cls, nodes, limit, url=None,
expand=False, **kwargs):
collection = NodesCollection()
collection.nodes = [
Nodes.convert_with_links(ch, expand)
for ch in nodes]
url = url or None
collection.next = collection.get_next(limit, url=url, **kwargs)
return collection
# class Nodess(wsme_types.Base):
# nodes = wsme_types.text
class NodesController(rest.RestController):
def _get_nodes(self, marker, limit, sort_key, sort_dir):
limit = utils.validate_limit(limit)
sort_dir = utils.validate_sort_dir(sort_dir)
marker_obj = None
if marker:
marker_obj = objects.sm_node.get_by_uuid(
pecan.request.context, marker)
nodes = pecan.request.dbapi.sm_node_get_list(limit,
marker_obj,
sort_key=sort_key,
sort_dir=sort_dir)
return nodes
@wsme_pecan.wsexpose(Nodes, unicode)
def get_one(self, uuid):
rpc_sg = objects.sm_node.get_by_uuid(pecan.request.context, uuid)
return Nodes.convert_with_links(rpc_sg)
@wsme_pecan.wsexpose(NodesCollection, unicode, int,
unicode, unicode)
def get_all(self, marker=None, limit=None,
sort_key='name', sort_dir='asc'):
"""Retrieve list of nodes."""
nodes = self._get_nodes(marker,
limit,
sort_key,
sort_dir)
return NodesCollection.convert_with_links(nodes, limit,
sort_key=sort_key,
sort_dir=sort_dir)
@wsme_pecan.wsexpose(NodesCommandResult, unicode,
body=NodesCommand)
def put(self, hostname, command):
raise NotImplementedError()
@wsme_pecan.wsexpose(NodesCommandResult, unicode,
body=NodesCommand)
def patch(self, hostname, command):
raise NotImplementedError()

+ 164
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/service_groups.py View File

@ -0,0 +1,164 @@
#
# Copyright (c) 2014 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import json
import wsme
from wsme import types as wsme_types
import wsmeext.pecan as wsme_pecan
import pecan
from pecan import rest
from sm_api.api.controllers.v1 import base
from sm_api.api.controllers.v1 import collection
from sm_api.api.controllers.v1 import link
from sm_api.api.controllers.v1 import utils
from sm_api.common import log
from sm_api import objects
LOG = log.get_logger(__name__)
class ServiceGroupCommand(wsme_types.Base):
path = wsme_types.text
value = wsme_types.text
op = wsme_types.text
class ServiceGroupCommandResult(wsme_types.Base):
# Host Information
hostname = wsme_types.text
state = wsme_types.text
# Command
path = wsme_types.text
value = wsme_types.text
op = wsme_types.text
# Result
error_code = wsme_types.text
error_details = wsme_types.text
class ServiceGroup(base.APIBase):
name = wsme_types.text
state = wsme_types.text
status = wsme_types.text
# JKUNG new
uuid = wsme_types.text
"The UUID of the service_groups"
id = int
links = [link.Link]
"A list containing a self link and associated service_groups links"
def __init__(self, **kwargs):
self.fields = objects.service_groups.fields.keys()
for k in self.fields:
setattr(self, k, kwargs.get(k))
@classmethod
def convert_with_links(cls, rpc_service_groups, expand=True):
minimum_fields = ['id', 'name', 'state', 'status']
fields = minimum_fields if not expand else None
service_groups = ServiceGroup.from_rpc_object(
rpc_service_groups, fields)
return service_groups
class ServiceGroupCollection(collection.Collection):
"""API representation of a collection of service_groups."""
service_groups = [ServiceGroup]
"A list containing service_groups objects"
def __init__(self, **kwargs):
self._type = 'service_groups'
@classmethod
def convert_with_links(cls, service_groups, limit, url=None,
expand=False, **kwargs):
collection = ServiceGroupCollection()
collection.service_groups = [
ServiceGroup.convert_with_links(ch, expand)
for ch in service_groups]
url = url or None
collection.next = collection.get_next(limit, url=url, **kwargs)
return collection
class ServiceGroups(wsme_types.Base):
service_groups = wsme_types.text
class ServiceGroupController(rest.RestController):
def _get_service_groups(self, marker, limit, sort_key, sort_dir):
limit = utils.validate_limit(limit)
sort_dir = utils.validate_sort_dir(sort_dir)
marker_obj = None
if marker:
marker_obj = objects.service_groups.get_by_uuid(
pecan.request.context, marker)
service_groups = pecan.request.dbapi.iservicegroup_get_list(limit,
marker_obj,
sort_key=sort_key,
sort_dir=sort_dir)
return service_groups
@wsme_pecan.wsexpose(ServiceGroup, unicode)
def get_one(self, uuid):
rpc_sg = objects.service_groups.get_by_uuid(pecan.request.context, uuid)
return ServiceGroup.convert_with_links(rpc_sg)
@wsme_pecan.wsexpose(ServiceGroupCollection, unicode, int,
unicode, unicode)
def get_all(self, marker=None, limit=None,
sort_key='name', sort_dir='asc'):
"""Retrieve list of servicegroups."""
service_groups = self._get_service_groups(marker,
limit,
sort_key,
sort_dir)
return ServiceGroupCollection.convert_with_links(service_groups, limit,
sort_key=sort_key,
sort_dir=sort_dir)
# cursor = pecan.request.database.cursor()
# cursor.execute("SELECT name, state from service_groups")
# data = cursor.fetchall()
# if data is not None:
# service_groups = []
# for row in data:
# service_groups.append({'name': row[0], 'state': row[1]})
# return ServiceGroups(service_groups=json.dumps(service_groups))
#return wsme.api.Response(ServiceGroups(service_groups=json.dumps([])),
# status_code=404)
@wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode,
body=ServiceGroupCommand)
def put(self, hostname, command):
raise NotImplementedError()
@wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode,
body=ServiceGroupCommand)
def patch(self, hostname, command):
raise NotImplementedError()

+ 447
- 0
service-mgmt-api/sm-api/sm_api/api/controllers/v1/servicenode.py View File

@ -0,0 +1,447 @@
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Red Hat, Inc.
# All Rights Reserved.
#
# 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.
#
# Copyright (c) 2013-2014 Wind River Systems, Inc.
#
import pecan
from pecan import rest
import wsme
from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan
from sm_api.api.controllers.v1 import base
from sm_api.api.controllers.v1 import smc_api
from sm_api.openstack.common import log
LOG = log.getLogger(__name__)
ERR_CODE_SUCCESS = "0"
ERR_CODE_HOST_NOT_FOUND = "-1000"
ERR_CODE_ACTION_FAILED = "-1001"
ERR_CODE_NO_HOST_TO_SWACT_TO = "-1002"
SM_NODE_STATE_UNKNOWN = "unknown"
SM_NODE_ADMIN_LOCKED = "locked"
SM_NODE_ADMIN_UNLOCKED = "unlocked"
SM_NODE_OPER_ENABLED = "enabled"
SM_NODE_OPER_DISABLED = "disabled"
SM_NODE_AVAIL_AVAILABLE = "available"
SM_NODE_AVAIL_DEGRADED = "degraded"
SM_NODE_AVAIL_FAILED = "failed"
# sm_types.c
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_NIL = "nil"
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_UNKNOWN = "unknown"
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_NONE = "none"
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_N = "N"
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_N_PLUS_M = "N + M"
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_N_TO_1 = "N to 1"
SM_SERVICE_DOMAIN_MEMBER_REDUNDANCY_MODEL_N_TO_N = "N to N"
# sm_types.c
SM_SERVICE_GROUP_STATE_NIL =