Skip to content

Commit

Permalink
Merge pull request #20 from digitronik/refactor
Browse files Browse the repository at this point in the history
Refactor MiqBox
  • Loading branch information
digitronik authored Aug 27, 2019
2 parents ade5cc5 + a00e10e commit b63a900
Show file tree
Hide file tree
Showing 15 changed files with 955 additions and 759 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ install:
script:
- flake8 setup.py miqbox
- black -l 99 setup.py miqbox
- reorder-python-imports setup.py miqbox/*.py
after_failure:
- git diff
deploy:
Expand Down
7 changes: 7 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Authors

- [Nikhil Dhandre](https://github.com/digitronik)
- [Yadnyawalkya Tale](https://github.com/Yadnyawalkya)
- [Ganesh Hubale](https://github.com/ganeshhubale)
- [Parthvi Vala](https://github.com/valaparthvi)
- [Md Nadeem](https://github.com/mnadeem92)
93 changes: 63 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<h1 align="center"> MiqBox</h2>
<h3 align="center">Spin ManageIQ/CFME Appliance locally with Virtualization.</h3>
<h1 align="center"> MiqBox </h1>
<h2 align="center"> Spin ManageIQ/CFME Appliance locally with Virtualization. </h2>

<p align="center">
<a href="https://pypi.org/project/miqbox"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/miqbox.svg?style=flat"></a>
<a href="https://travis-ci.org/digitronik/miqbox"><img alt="Build Status" src="https://travis-ci.org/digitronik/miqbox.svg?branch=master"></a>
<a href="https://github.com/digitronik/miqbox/blob/master/LICENSE"><img alt="License: GPLV2" src="https://img.shields.io/pypi/l/miqbox.svg?version=latest"></a>
<a href="https://pypi.org/project/miqbox/#history"><img alt="PyPI version" src="https://badge.fury.io/py/miqbox.svg"></a>
<a href="https://pepy.tech/project/miqbox"><img alt="Downloads" src="https://pepy.tech/badge/miqbox"></a>
<a href="https://pypi.org/project/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://pypi.org/project/miqbox"><img alt="Python Versions" src="https://img.shields.io/pypi/pyversions/miqbox.svg?style=flat"></a>
<a href="https://travis-ci.org/digitronik/miqbox"><img alt="Build Status" src="https://travis-ci.org/digitronik/miqbox.svg?branch=master"></a>
<a href="https://github.com/digitronik/miqbox/blob/master/LICENSE"><img alt="License: GPLV2" src="https://img.shields.io/pypi/l/miqbox.svg?version=latest"></a>
<a href="https://pypi.org/project/miqbox/#history"><img alt="PyPI version" src="https://badge.fury.io/py/miqbox.svg"></a>
<a href="https://pepy.tech/project/miqbox"><img alt="Downloads" src="https://pepy.tech/badge/miqbox"></a>
<a href="https://pypi.org/project/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</p>

## Prerequisite:
### Prerequisite

1. Virtualization:
- [Fedora](https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-virtualization/)

- [Fedora](https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-virtualization/)
```bash
sudo dnf install @virtualization
systemctl start libvirtd
systemctl enable libvirtd
```

If you want optional packages

```bash
dnf group install --with-optional virtualization
```
- [Ubuntu](https://help.ubuntu.com/community/KVM/Installation)

- [Ubuntu](https://help.ubuntu.com/community/KVM/Installation)

```bash
sudo apt-get install qemu-kvm
```
Expand All @@ -35,34 +39,45 @@
sudo dnf install libvirt-devel python-devel python3-devel
```

## Install:
### Install

- pip

```bash
pip install miqbox --user
```

- source

```bash
python setup.py install --user
```
Note: For Development install in editable mode.

## Troubleshooting:
### Troubleshooting

- [libvirt: Polkit error](https://fedoraproject.org/wiki/QA:Testcase_Virt_ACLs)

- To prevent `libvirt` from asking `root` password:

- Add `libvirt` group (It may be present by default)
```

```bash
sudo groupadd libvirt
```
- Add not root `user` as member
```

- Add not root `user` as member

```bash
sudo usermod -a -G libvirt <username>
```

- Add `Polkit` rule for `libvirt`:
```

```bash
vim /etc/polkit-1/rules.d/80-libvirt.rules
```
```

```bash
polkit.addRule(function(action, subject) {
if (action.id == "org.libvirt.unix.manage"
&& subject.local
Expand All @@ -73,25 +88,43 @@ Note: For Development install in editable mode.
});
```
## Usage:
```
### Usage
- Help available with `MiqBox`
```bash
Usage: miqbox [OPTIONS] COMMAND [ARGS]...
Command line application entry point
Spin ManageIQ/CFME Appliance locally with Virtualization.
Options:
--help Show this message and exit.

--version Show the version and exit.
--help Show this message and exit.
Commands:
config Configure miqbox
config Configure MiqBox
create Create Appliance
evmserver Restart Miq/CFME Server
images Get local or remote available image Args: local: default, will...
images Check available images
kill Kill Appliance
pull Download Image
rmi Remove local Image
rmi Remove local Images
start Start Appliance
status Appliance Status
stop Stop Appliance
```
### Contribute
- Fork the [repository](https://github.com/digitronik/miqbox.git) on GitHub
and make some changes. Make sure to add yourself to [AUTHORS](AUTHORS.md).
- Install the in development mode
```bash
pip install -r requirements-dev.txt
pip install -e .
```
- Send pull requests and bugs.
43 changes: 42 additions & 1 deletion miqbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# miqbox
import click

from miqbox.configuration import config
from miqbox.images import images
from miqbox.images import pull
from miqbox.images import rmi
from miqbox.miqbox import create
from miqbox.miqbox import evmserver
from miqbox.miqbox import kill
from miqbox.miqbox import start
from miqbox.miqbox import status
from miqbox.miqbox import stop


@click.version_option()
@click.group()
def main():
"""Spin ManageIQ/CFME Appliance locally with Virtualization."""
pass


# Image commands
main.add_command(images)
main.add_command(pull)
main.add_command(rmi)

# MiqBox command
main.add_command(status)

# Appliance operations commands
main.add_command(create)
main.add_command(start)
main.add_command(stop)
main.add_command(kill)
main.add_command(evmserver)

# Configuration command
main.add_command(config)


if __name__ == "__main__":
main()
76 changes: 0 additions & 76 deletions miqbox/ap.py

This file was deleted.

22 changes: 22 additions & 0 deletions miqbox/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import libvirt

from miqbox.configuration import Configuration


class Client(Configuration):
"""Libvirt client
Args:
url (str): driver url
"""
def __init__(self, url=None, *args, **kwargs):
super(Client, self).__init__(*args, **kwargs)
self.url = url or self.libvirt.driver

@property
def driver(self):
"""libvirt open connection"""
try:
return libvirt.open(self.url)
except libvirt.libvirtError:
print(f"Failed to open connection to {self.url}")
25 changes: 25 additions & 0 deletions miqbox/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
appliance:
password: smartvm
username: root
images: ~/.miqbox/images
libvirt:
driver: qemu:///system
storage_pool:
name: miqbox
path: /var/lib/libvirt/images/miqbox
repositories:
downstream:
url: null
versions:
- '5.7'
- '5.8'
- '5.9'
- '5.10'
- '5.11'
upstream:
url: http://releases.manageiq.org
versions:
- gaprindashvili
- hammer
- ivanchuk
- master
Loading

0 comments on commit b63a900

Please sign in to comment.