Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/quipucords/quipucords int…
Browse files Browse the repository at this point in the history
…o issues/438
  • Loading branch information
abaiken committed Jan 17, 2018
2 parents 4b7e89c + a43c8eb commit 0e4931b
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 15 deletions.
8 changes: 4 additions & 4 deletions docs/source/man.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ Creating and Editing Sources

To create a source, supply one or more host names or IP addresses to connect to with the ``--hosts`` option and the credentials needed to access those systems with the ``--cred`` option. The ``qpc source`` command allows multiple entries for each of these options. Therefore, a single source can access a collection of servers and subnets as needed to create an accurate and complete scan.

**qpc source add --name=** *name* **--type=** *(network | vcenter)* **--hosts** *ip_address* **--cred** *credential* **[--port=** *port* **]**
**qpc source add --name=** *name* **--type=** *(network | vcenter | satellite)* **--hosts** *ip_address* **--cred** *credential* **[--port=** *port* **]**

``--name=name``

Required. Sets the name of the new source. For the value, use a descriptive name that is meaningful to your organization, such as ``APSubnet`` or ``Lab3``.

``--type=type``

Required. Sets the type of source. Must be ``network`` or ``vcenter``.
Required. Sets the type of source. Must be ``network``, ``vcenter``, or ``satellite``.

``--hosts ip_address``

Expand Down Expand Up @@ -257,11 +257,11 @@ Listing and Showing Sources

The ``qpc source list`` command returns the details for all configured sources. The output of this command includes the host names, IP addresses, or IP ranges, the credentials, and the ports that are configured for each source.

**qpc source list **--type=** *(network | vcenter)* **
**qpc source list **--type=** *(network | vcenter | satellite)* **

``--type=type``

Optional. Filter list results by source type. Must be ``network`` or ``vcenter``.
Optional. Filter list results by source type. Must be ``network``, ``vcenter``, or ``satellite``.


The ``qpc source show`` command is the same as the ``qpc source list`` command, except that it returns details for a single specified source.
Expand Down
10 changes: 9 additions & 1 deletion docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ paths:
enum:
- network
- vcenter
- satellite
responses:
200:
description: "Credential retrieved"
Expand Down Expand Up @@ -288,6 +289,7 @@ paths:
enum:
- network
- vcenter
- satellite
responses:
200:
description: "Sources retrieved"
Expand Down Expand Up @@ -622,6 +624,7 @@ definitions:
enum:
- network
- vcenter
- satellite
facts:
type: "array"
items:
Expand All @@ -645,6 +648,7 @@ definitions:
enum:
- network
- vcenter
- satellite
username:
type: "string"
description: "The connection username for the credential"
Expand Down Expand Up @@ -675,6 +679,7 @@ definitions:
enum:
- network
- vcenter
- satellite
CredentialOut:
allOf:
- $ref: "#/definitions/Credential"
Expand Down Expand Up @@ -705,6 +710,7 @@ definitions:
enum:
- network
- vcenter
- satellite
description: "The source type"
bios_uuid:
type: "string"
Expand Down Expand Up @@ -808,11 +814,12 @@ definitions:
enum:
- network
- vcenter
- satellite
hosts:
type: "array"
items:
type: "string"
description: "The host(s) to scan.Can be an IP or hostname for vcenter; or ips, hostnames or IP ranges for network."
description: "The host(s) to scan.Can be an IP or hostname for vcenter/satellite; or ips, hostnames or IP ranges for network."
port:
type: "integer"
format: "int32"
Expand All @@ -836,6 +843,7 @@ definitions:
enum:
- network
- vcenter
- satellite
SourceIn:
allOf:
- $ref: "#/definitions/Source"
Expand Down
1 change: 1 addition & 0 deletions qpc/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
SOURCE_CREDS_HELP = 'credentials to associate with source'
SOURCE_PORT_HELP = 'port for connection; network default=22, '\
'vcenter default=443'
SOURCE_SAT_VER_HELP = 'specify the version of Satellite (i.e. "6.2")'
SOURCE_ADD_CREDS_NOT_FOUND = 'An error occurred while processing the ' \
'"--cred" input values. References for the'\
' following credential could not' \
Expand Down
1 change: 1 addition & 0 deletions qpc/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

NETWORK_SOURCE_TYPE = 'network'
VCENTER_SOURCE_TYPE = 'vcenter'
SATELLITE_SOURCE_TYPE = 'satellite'

SOURCE_URI = '/api/v1/sources/'
8 changes: 7 additions & 1 deletion qpc/source/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def __init__(self, subparsers):
required=True)
self.parser.add_argument('--type', dest='type',
choices=[source.NETWORK_SOURCE_TYPE,
source.VCENTER_SOURCE_TYPE],
source.VCENTER_SOURCE_TYPE,
source.SATELLITE_SOURCE_TYPE],
metavar='TYPE',
help=_(messages.SOURCE_TYPE_HELP),
required=True)
Expand All @@ -63,6 +64,11 @@ def __init__(self, subparsers):
metavar='PORT', type=validate_port,
help=_(messages.SOURCE_PORT_HELP),
required=False)
self.parser.add_argument('--satellite_version',
dest='satellite_version',
metavar='SAT_VER',
help=_(messages.SOURCE_SAT_VER_HELP),
required=False)

def _validate_args(self):
CliCommand._validate_args(self)
Expand Down
5 changes: 5 additions & 0 deletions qpc/source/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def __init__(self, subparsers):
self.parser.add_argument('--port', dest='port',
metavar='PORT', type=validate_port,
help=_(messages.SOURCE_PORT_HELP))
self.parser.add_argument('--satellite_version',
dest='satellite_version',
metavar='SAT_VER',
help=_(messages.SOURCE_SAT_VER_HELP),
required=False)

# pylint: disable=too-many-branches
def _validate_args(self):
Expand Down
3 changes: 2 additions & 1 deletion qpc/source/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def __init__(self, subparsers):
source.SOURCE_URI, [codes.ok])
self.parser.add_argument('--type', dest='type',
choices=[source.NETWORK_SOURCE_TYPE,
source.VCENTER_SOURCE_TYPE],
source.VCENTER_SOURCE_TYPE,
source.SATELLITE_SOURCE_TYPE],
metavar='TYPE',
help=_(messages.SOURCE_TYPE_FILTER_HELP),
required=False)
Expand Down
18 changes: 18 additions & 0 deletions qpc/source/tests_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,21 @@ def test_add_source_vc(self):
nac.main(args)
self.assertEqual(source_out.getvalue(),
'Source "source1" was added\n')

def test_add_source_sat(self):
"""Testing the add satellite source command successfully."""
source_out = StringIO()
get_cred_url = BASE_URL + CREDENTIAL_URI + '?name=cred1'
get_cred_data = [{'id': 1, 'name': 'cred1'}]
post_source_url = BASE_URL + SOURCE_URI
with requests_mock.Mocker() as mocker:
mocker.get(get_cred_url, status_code=200, json=get_cred_data)
mocker.post(post_source_url, status_code=201)
nac = SourceAddCommand(SUBPARSER)
args = Namespace(name='source1', cred=['cred1'],
hosts=['1.2.3.4'], type='vcenter',
satellite_version='6.2')
with redirect_stdout(source_out):
nac.main(args)
self.assertEqual(source_out.getvalue(),
'Source "source1" was added\n')
3 changes: 3 additions & 0 deletions qpc/source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@ def build_source_payload(args, add_none=True):
req_payload['credentials'] = args.credentials
elif add_none:
req_payload['credentials'] = None
if hasattr(args, 'satellite_version') and args.satellite_version:
options = {'satellite_version': args.satellite_version}
req_payload['options'] = options

return req_payload
5 changes: 4 additions & 1 deletion qpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,13 @@ def handle_error_response(response):
if isinstance(response_data, dict):
for err_key, err_cases in response_data.items():
error_context = 'Error'
if err_key != 'non_field_errors' and err_key != 'detail':
if (err_key != 'non_field_errors' and
err_key != 'detail' and err_key != 'options'):
error_context = err_key
if isinstance(err_cases, str):
log.error('%s: %s', error_context, err_cases)
elif isinstance(err_cases, dict):
log.error('%s: %s', error_context, err_cases)
else:
for err_msg in err_cases:
log.error('%s: %s', error_context, err_msg)
Expand Down
3 changes: 3 additions & 0 deletions quipucords/api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
VC_ONE_HOST = 'Source of type vcenter must have a single hosts.'
VC_ONE_CRED = 'Source of type vcenter must have a single credential.'

SAT_ONE_HOST = 'Source of type satellite must have a single hosts.'
SAT_ONE_CRED = 'Source of type satellite must have a single credential.'

# scan jobs messages
PLURAL_SCAN_JOBS_MSG = 'Scan Jobs'
SJ_REQ_SOURCES = 'Scan job must have one or more sources.'
Expand Down
2 changes: 1 addition & 1 deletion quipucords/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from api.fact.model import FactCollection
from api.fingerprint.model import SystemFingerprint
from api.credential.model import Credential
from api.source.model import HostRange, Source
from api.source.model import HostRange, Source, SourceOptions
from api.scanjob.model import ScanJob, ScanOptions
from api.connresults.model import (ConnectionResults, ConnectionResult,
SystemConnectionResult)
Expand Down
20 changes: 19 additions & 1 deletion quipucords/api/source/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@
from api.credential.model import Credential


class SourceOptions(models.Model):
"""The source options allows configuration of a sources."""

SATELLITE_VERSION_62 = '6.2'
SATELLITE_VERSION_CHOICES = ((SATELLITE_VERSION_62, SATELLITE_VERSION_62),)

satellite_version = models.CharField(
max_length=10,
choices=SATELLITE_VERSION_CHOICES,
null=False,
default=SATELLITE_VERSION_62
)


class Source(models.Model):
"""A source connects a list of credentials and a list of hosts."""

NETWORK_SOURCE_TYPE = 'network'
VCENTER_SOURCE_TYPE = 'vcenter'
SATELLITE_SOURCE_TYPE = 'satellite'
SOURCE_TYPE_CHOICES = ((NETWORK_SOURCE_TYPE, NETWORK_SOURCE_TYPE),
(VCENTER_SOURCE_TYPE, VCENTER_SOURCE_TYPE))
(VCENTER_SOURCE_TYPE, VCENTER_SOURCE_TYPE),
(SATELLITE_SOURCE_TYPE, SATELLITE_SOURCE_TYPE))

name = models.CharField(max_length=64, unique=True)
source_type = models.CharField(
Expand All @@ -32,6 +48,8 @@ class Source(models.Model):
null=False
)
port = models.IntegerField(null=True)
options = models.ForeignKey(
SourceOptions, null=True, on_delete=models.CASCADE)
credentials = models.ManyToManyField(Credential)
# Source also has the field hosts, which is created by the
# ForeignKey in HostRange below.
Expand Down

0 comments on commit 0e4931b

Please sign in to comment.