-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to manage a Copr project
- Loading branch information
Showing
10 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
A copr-cli wrapper and support functions for Copr | ||
""" | ||
from subprocess import check_output, CalledProcessError | ||
|
||
class CoprCliCommandError(Exception): | ||
"""Raised when copr-cli command fails""" | ||
def __init__(self, message, command): | ||
self.message = message | ||
self.command = command | ||
super(CoprCliCommandError, self).__init__(message) #pylint: disable-all | ||
|
||
def copr_cli(command, executable=None): | ||
""" | ||
Run a copr-cli command | ||
""" | ||
if executable is None: | ||
executable = 'copr-cli' | ||
|
||
try: | ||
return check_output([executable] + command, universal_newlines=True) | ||
except CalledProcessError as error: | ||
raise CoprCliCommandError(error.output, error.cmd) | ||
|
||
def full_name(user, project): | ||
""" | ||
Returns a full Copr name: user/project | ||
""" | ||
return "%s/%s" %(user, project) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Manage a chroot in a Copr project | ||
""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Manage a chroot in a Copr project | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
user=dict(type='str', required=True), | ||
project=dict(type='str', required=True), | ||
chroot=dict(type='str', required=True), | ||
external_repos=dict(type='list', required=False, default=[]), | ||
buildroot_packages=dict(type='list', required=False, default=[]), | ||
modules=dict(type='list', required=False, default=[]), | ||
) | ||
) | ||
|
||
user = module.params['user'] | ||
project = module.params['project'] | ||
chroot = module.params['chroot'] | ||
external_repos = module.params['external_repos'] | ||
buildroot_packages = module.params['buildroot_packages'] | ||
modules = module.params['modules'] | ||
|
||
command = [ | ||
'edit-chroot', | ||
"%s/%s" % (full_name(user, project), chroot) | ||
] | ||
|
||
if external_repos: | ||
command.extend(['--repos', ' '.join(external_repos)]) | ||
|
||
if buildroot_packages: | ||
command.extend(['--packages', ' '.join(buildroot_packages)]) | ||
|
||
if modules: | ||
command.extend(['--modules', ','.join(modules)]) | ||
|
||
try: | ||
output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr chroot edit failed', command=' '.join(error.command), output=error.message) | ||
|
||
module.exit_json(changed=True, output=output) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
""" | ||
Create a Project in Copr | ||
""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.copr import copr_cli, CoprCliCommandError, full_name # pylint:disable=import-error,no-name-in-module | ||
|
||
|
||
def main(): | ||
""" | ||
Create a Project in Copr | ||
""" | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
user=dict(type='str', required=True), | ||
project=dict(type='str', required=True), | ||
chroots=dict(type='list', required=True), | ||
description=dict(type='str', required=False), | ||
unlisted_on_homepage=dict(type='bool', required=False, default=True), | ||
delete_after_days=dict(type='str', required=False, default=None), | ||
) | ||
) | ||
|
||
user = module.params['user'] | ||
project = module.params['project'] | ||
chroots = module.params['chroots'] | ||
description = module.params['description'] | ||
unlisted_on_homepage = module.params['unlisted_on_homepage'] | ||
delete_after_days = module.params['delete_after_days'] | ||
|
||
if not description: | ||
description = project | ||
|
||
command = [ | ||
'create', | ||
full_name(user, project), | ||
'--description', | ||
"%s" % description | ||
] | ||
|
||
for chroot in chroots: | ||
command.extend(['--chroot', chroot]) | ||
|
||
if unlisted_on_homepage: | ||
command.extend(['--unlisted-on-hp', 'on']) | ||
|
||
if delete_after_days: | ||
command.extend(['--delete-after-days', delete_after_days]) | ||
|
||
try: | ||
output = copr_cli(command) | ||
except CoprCliCommandError as error: | ||
module.fail_json(msg='Copr project creation failed', command=' '.join(error.command), output=error.message) | ||
|
||
module.exit_json(changed=True, output=output) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: Configure Copr projects | ||
hosts: | ||
- copr_projects | ||
- packages | ||
serial: 1 | ||
gather_facts: false | ||
roles: | ||
- role: copr_project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
help: | | ||
This action configures Copr projects | ||
variables: | ||
copr_project_user: | ||
parameter: --user | ||
help: Copr user to use instead of the default value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: 'Create Copr project' | ||
copr_project: | ||
user: "{{ copr_project_user }}" | ||
project: "{{ copr_project_name }}" | ||
chroots: "{{ copr_project_chroots | map(attribute='name') }}" | ||
description: "{{ copr_project_description | default(omit) }}" | ||
delete_after_days: "{{ copr_project_delete_after_days | default(omit) }}" | ||
unlisted_on_homepage: "{{ copr_project_unlisted_on_homepage | default(omit) }}" | ||
register: create_output | ||
|
||
- name: Configure chroots | ||
copr_chroot: | ||
user: "{{ copr_project_user }}" | ||
project: "{{ copr_project_name }}" | ||
chroot: "{{ chroot.name }}" | ||
external_repos: "{{ chroot.external_repos | default(omit) }}" | ||
buildroot_packages: "{{ chroot.buildroot_packages | default(omit) }}" | ||
modules: "{{ chroot.modules | default(omit) }}" | ||
loop: "{{ copr_project_chroots }}" | ||
loop_control: | ||
loop_var: chroot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
usage: obal copr-project [-h] [-v] [-e EXTRA_VARS] [--user COPR_PROJECT_USER] | ||
target [target ...] | ||
|
||
This action configures Copr projects | ||
|
||
positional arguments: | ||
target the target to execute the action against | ||
|
||
optional arguments: | ||
-h, --help show this help message and exit | ||
-v, --verbose verbose output | ||
--user COPR_PROJECT_USER | ||
Copr user to use instead of the default value | ||
|
||
advanced arguments: | ||
-e EXTRA_VARS, --extra-vars EXTRA_VARS | ||
set additional variables as key=value or YAML/JSON, if | ||
filename prepend with @ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters