Skip to content

Commit

Permalink
ENT-589 Intentctl -> syspurpose
Browse files Browse the repository at this point in the history
  • Loading branch information
cnsnyder committed Jul 16, 2018
1 parent 7aef519 commit b8c7ec0
Show file tree
Hide file tree
Showing 23 changed files with 452 additions and 450 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ INSTALL_DNF_PLUGINS ?= false
DNF_PLUGINS_SRC_DIR := src/plugins

INSTALL_ZYPPER_PLUGINS ?= false
INCLUDE_INTENTCTL ?= 0
INCLUDE_SYSPURPOSE ?= 0

# sets a version that is more or less latest tag plus commit sha
VERSION ?= $(shell git describe | awk ' { sub(/subscription-manager-/,"")};1' )
Expand Down Expand Up @@ -163,7 +163,7 @@ install-conf:
install -d $(DESTDIR)/etc/{cron.daily,logrotate.d,pam.d,bash_completion.d,rhsm}
install -d $(DESTDIR)/etc/rc.d/init.d
install -d $(DESTDIR)/etc/init.d
install -d $(DESTDIR)/etc/rhsm/{facts,intent}
install -d $(DESTDIR)/etc/rhsm/{facts,syspurpose}
install -d $(DESTDIR)/etc/security/console.apps
install -m 644 etc-conf/rhsm.conf $(DESTDIR)/etc/rhsm/
install -T etc-conf/logging.conf $(DESTDIR)/etc/rhsm/logging.conf
Expand Down Expand Up @@ -302,8 +302,8 @@ install-via-setup: install-subpackages-via-setup
else \
rm $(DESTDIR)/$(PREFIX)/bin/subscription-manager-gui; \
fi; \
if [[ "$(INCLUDE_INTENTCTL)" = "1" ]]; then \
mv $(DESTDIR)/$(PREFIX)/bin/intentctl $(DESTDIR)/$(PREFIX)/sbin/; \
if [[ "$(INCLUDE_SYSPURPOSE)" = "1" ]]; then \
mv $(DESTDIR)/$(PREFIX)/bin/syspurpose $(DESTDIR)/$(PREFIX)/sbin/; \
fi;


Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ can be used:
See `cockpit/README.md` for more detailed information on cockpit development.


intentctl
syspurpose
---------
The intentctl utility manages certain user-definable values tracked in
the /etc/rhsm/intent/intent.json file (in json format).
The syspurpose utility manages certain user-definable values tracked in
the /etc/rhsm/syspurpose/syspurpose.json file (in json format).

See ./packages/intentctl/README.md for details on getting started
See ./packages/syspurpose/README.md for details on getting started


Testing
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Getting started developing the intentctl utility
# Getting started developing the syspurpose utility

This subpackage in the rhsm ecosystem uses pipenv to define python requirements and maintain a
virtual environment for development.
Expand All @@ -11,8 +11,8 @@ The recommended workflow is as follows:
1) Run the following to enter the virtual env: `pipenv shell`


From inside this virtual env you can freely install the intentctl tool and test it as you like.
From inside this virtual env you can freely install the syspurpose tool and test it as you like.
Just run `python ./setup.py install` to install and `python ./setup.py test` to run the tests.

The source for this subpackage is located (from checkout root) at ./src/intentctl
The tests for this subpackage is located (from checkout root) at ./test/intentctl
The source for this subpackage is located (from checkout root) at ./src/syspurpose
The tests for this subpackage is located (from checkout root) at ./test/syspurpose
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[nosetests]
where=../../test/intentctl
where=../../test/syspurpose
verbose=1
nocapture=True
8 changes: 4 additions & 4 deletions packages/intentctl/setup.py → packages/syspurpose/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
]

setup(
name="intentctl",
name="syspurpose",
version="1.22.1",
url="http://www.candlepinproject.org",
description="Manage Red Hat System Intent",
license="GPLv2",
author="Chris Snyder",
author_email="[email protected]",
packages=find_packages('../../src', include=["intentctl"]),
packages=find_packages('../../src', include=["syspurpose"]),
package_dir={
"intentctl": "../../src/intentctl"
"syspurpose": "../../src/syspurpose"
},
tests_require=test_require,
test_suite='nose.collector',
entry_points={
"console_scripts": [
"intentctl = intentctl.main:main"
"syspurpose = syspurpose.main:main"
]
}
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def add_icons(self):
author="Adrian Likins",
author_email="[email protected]",
cmdclass=cmdclass,
packages=find_packages('src', exclude=['subscription_manager.gui.firstboot.*', '*.ga_impls', '*.ga_impls.*', '*.plugin.ostree', '*.services.examples', 'intentctl*']),
packages=find_packages('src', exclude=['subscription_manager.gui.firstboot.*', '*.ga_impls', '*.ga_impls.*', '*.plugin.ostree', '*.services.examples', 'syspurpose*']),
package_dir={'': 'src'},
package_data={
'subscription_manager.gui': ['data/glade/*.glade', 'data/ui/*.ui', 'data/icons/*.svg'],
Expand Down
8 changes: 4 additions & 4 deletions src/subscription_manager/managercli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
from subscription_manager.printing_utils import columnize, format_name, \
none_wrap_columnize_callback, echo_columnize_callback, highlight_by_filter_string_columnize_cb
from subscription_manager.utils import generate_correlation_id
from subscription_manager.intentstore_interface import save_sla_to_intent_metadata
from subscription_manager.syspurposelib import save_sla_to_syspurpose_metadata

from subscription_manager.i18n import ungettext, ugettext as _

Expand Down Expand Up @@ -868,7 +868,7 @@ def _set_service_level(self, service_level):
if 'serviceLevel' not in consumer:
system_exit(os.EX_UNAVAILABLE, _("Error: The service-level command is not supported by the server."))
self.cp.updateConsumer(self.identity.uuid, service_level=service_level)
save_sla_to_intent_metadata(service_level)
save_sla_to_syspurpose_metadata(service_level)

def _validate_options(self):

Expand Down Expand Up @@ -1176,7 +1176,7 @@ def _do_command(self):
log.exception("Auto-attach failed")
raise
else:
save_sla_to_intent_metadata(self.options.service_level)
save_sla_to_syspurpose_metadata(self.options.service_level)
if self.options.service_level is not None:
print(_("Service level set to: %s") % self.options.service_level)

Expand Down Expand Up @@ -1601,7 +1601,7 @@ def _do_command(self):
"complete your request."))

attach_service.attach_auto(self.options.service_level)
save_sla_to_intent_metadata(self.options.service_level)
save_sla_to_syspurpose_metadata(self.options.service_level)
if self.options.service_level is not None:
print(_("Service level set to: %s") % self.options.service_level)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@
#

"""
This module is an interface to intentctl's IntentStore class from subscription-manager.
It contains methods for accessing/manipulating the local intent.json metadata file through IntentStore.
This module is an interface to syspurpose's SyspurposeStore class from subscription-manager.
It contains methods for accessing/manipulating the local syspurpose.json metadata file through SyspurposeStore.
"""

import logging
log = logging.getLogger(__name__)

try:
from intentctl.intentfiles import IntentStore, USER_INTENT
from syspurpose.files import SyspurposeStore, USER_SYSPURPOSE
except ImportError:
log.error("Could not import from module intentctl.")
log.error("Could not import from module syspurpose.")


def save_sla_to_intent_metadata(service_level):
def save_sla_to_syspurpose_metadata(service_level):
"""
Saves the provided service-level value to the local Intent Metadata (intent.json) file.
If the service level provided is null or empty, the sla value to the local intent file is set to null.
Saves the provided service-level value to the local Syspurpose Metadata (syspurpose.json) file.
If the service level provided is null or empty, the sla value to the local syspurpose file is set to null.
:param service_level: The service-level value to be saved in the intent file.
:param service_level: The service-level value to be saved in the syspurpose file.
:type service_level: str
"""

if 'IntentStore' in globals():
store = IntentStore.read(USER_INTENT)
if 'SyspurposeStore' in globals():
store = SyspurposeStore.read(USER_SYSPURPOSE)

# if empty, set it to null
if service_level is None or service_level == "":
service_level = None

store.set("service_level_agreement", service_level)
store.write()
log.info("Intent SLA value successfully saved locally.")
log.info("Syspurpose SLA value successfully saved locally.")
else:
log.error("IntentStore could not be imported. Intent SLA value not saved locally.")
log.error("SyspurposeStore could not be imported. Syspurpose SLA value not saved locally.")
File renamed without changes.
65 changes: 33 additions & 32 deletions src/intentctl/cli.py → src/syspurpose/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,81 +16,81 @@
# in this software or its documentation.

import argparse
from intentctl.intentfiles import IntentStore, USER_INTENT
from intentctl.utils import in_container
from syspurpose.files import SyspurposeStore, USER_SYSPURPOSE
from syspurpose.utils import in_container
import json


def add_command(args, intentstore):
def add_command(args, syspurposestore):
"""
Uses the intentstore to add one or more values to a particular property.
Uses the syspurposestore to add one or more values to a particular property.
:param args: The parsed args from argparse, expected attributes are:
prop_name: the string name of the property to add to
values: A list of the values to add to the given property (could be anything json-serializable)
:param intentstore: An IntentStore object to manipulate
:param syspurposestore: An SyspurposeStore object to manipulate
:return: None
"""
for value in args.values:
intentstore.add(args.prop_name, value)
syspurposestore.add(args.prop_name, value)
print("Added {} to {}".format(args.values, args.prop_name))


def remove_command(args, intentstore):
def remove_command(args, syspurposestore):
"""
Uses the intentstore to remove one or more values from a particular property.
Uses the syspurposestore to remove one or more values from a particular property.
:param args: The parsed args from argparse, expected attributes are:
prop_name: the string name of the property to add to
values: A list of the values to remove from the given property (could be anything json-serializable)
:param intentstore: An IntentStore object to manipulate
:param syspurposestore: An SyspurposeStore object to manipulate
:return: None
"""
for value in args.values:
intentstore.remove(args.prop_name, value)
syspurposestore.remove(args.prop_name, value)
print("Removed {} from {}".format(args.values, args.prop_name))


def set_command(args, intentstore):
def set_command(args, syspurposestore):
"""
Uses the intentstore to set the prop_name to value.
Uses the syspurposestore to set the prop_name to value.
:param args: The parsed args from argparse, expected attributes are:
prop_name: the string name of the property to set
value: An object to set the property to (could be anything json-serializable)
:param intentstore: An IntentStore object to manipulate
:param syspurposestore: An SyspurposeStore object to manipulate
:return: None
"""
intentstore.set(args.prop_name, args.value)
syspurposestore.set(args.prop_name, args.value)
print("{} set to {}".format(args.prop_name, args.value))


def unset_command(args, intentstore):
def unset_command(args, syspurposestore):
"""
Uses the intentstore to unset (clear entirely) the prop_name.
Uses the syspurposestore to unset (clear entirely) the prop_name.
:param args: The parsed args from argparse, expected attributes are:
prop_name: the string name of the property to unset (clear)
:param intentstore: An IntentStore object to manipulate
:param syspurposestore: An SyspurposeStore object to manipulate
:return: None
"""
intentstore.unset(args.prop_name)
syspurposestore.unset(args.prop_name)
print("{} unset.".format(args.prop_name))


def show_contents(args, intentstore):
def show_contents(args, syspurposestore):
"""
:param args:
:param intentstore:
:param syspurposestore:
:return:
"""

contents = intentstore.contents
contents = syspurposestore.contents
print(json.dumps(contents, indent=2))


def setup_arg_parser():
"""
Sets up argument parsing for the intentctl tool.
Sets up argument parsing for the syspurpose tool.
:return: An argparse.ArgumentParser ready to use to parse_args
"""
parser = argparse.ArgumentParser(prog="intentctl", description="System Intent Management Tool")
parser = argparse.ArgumentParser(prog="syspurpose", description="System Syspurpose Management Tool")
parser.set_defaults(func=None, requires_write=False)

subparsers = parser.add_subparsers(help="sub-command help")
Expand Down Expand Up @@ -172,7 +172,7 @@ def setup_arg_parser():
# Targeted commands
# Offerings ##########
add_offering_parser = subparsers.add_parser("add-offerings",
help="Add one or more offerings to the system intent.",
help="Add one or more offerings to the system syspurpose.",
parents=[add_options])
# TODO: Set prop_name from schema file
add_offering_parser.set_defaults(prop_name="offering_name")
Expand Down Expand Up @@ -210,33 +210,34 @@ def setup_arg_parser():
parents=[unset_options])
unset_usage_parser.set_defaults(prop_name="usage_type")

# Pretty Print Json contents of default intent file
# Pretty Print Json contents of default syspurpose file
show_parser = subparsers.add_parser("show",
help="Show the current system intent")
help="Show the current system syspurpose")
show_parser.set_defaults(func=show_contents, requires_write=False)

return parser


def main():
"""
Run the cli (Do the intentctl tool thing!!)
Run the cli (Do the syspurpose tool thing!!)
:return: 0
"""
parser = setup_arg_parser()
args = parser.parse_args()

# Intent is not intended to be used in containers for the time being (could change later).
# Syspurpose is not intended to be used in containers for the time being (could change later).
if in_container():
print("WARNING: Setting intent in containers has no effect. Please run intentctl on the host.\n")
print("WARNING: Setting syspurpose in containers has no effect."
"Please run syspurpose on the host.\n")

intentstore = IntentStore.read(USER_INTENT)
syspurposestore = SyspurposeStore.read(USER_SYSPURPOSE)

if args.func is not None:
args.func(args, intentstore)
args.func(args, syspurposestore)
else:
parser.print_usage()

if args.requires_write:
intentstore.write()
syspurposestore.write()
return 0
Loading

0 comments on commit b8c7ec0

Please sign in to comment.