def test_host(): """Tests for method hosts""" client = CBWApi(API_URL, API_KEY, SECRET_KEY) with vcr.use_cassette('spec/fixtures/vcr_cassettes/hosts.yaml'): response = client.hosts() for host in response: assert isinstance(host, CBWHost) is True with vcr.use_cassette('spec/fixtures/vcr_cassettes/host.yaml'): response = client.host('12') assert isinstance(response, CBWHost) is True params = {"target": "192.168.1.2", "node_id": "1"} with vcr.use_cassette('spec/fixtures/vcr_cassettes/create_host.yaml'): response = client.create_host(params) assert isinstance(response, CBWHost) is True params["target"] = "192.168.2.3" with vcr.use_cassette('spec/fixtures/vcr_cassettes/update_host.yaml'): response = client.update_host('12', params) assert isinstance(response, CBWHost) is True with vcr.use_cassette('spec/fixtures/vcr_cassettes/delete_host.yaml'): response = client.delete_host('12') assert isinstance(response, CBWHost) is True
def test_host(): """Tests for method hosts""" client = CBWApi(API_URL, API_KEY, SECRET_KEY) hosts_validate = [ "cbw_object(id=8, target='172.18.0.13', category='linux', \ hostname='bb79e64ccd6e.dev_default', cve_announcements_count=0, created_at='2019-11-14T11:58:50.000+01:00', \ updated_at='2019-12-16T16:45:42.000+01:00', node_id=1, server_id=5, status='server_update_init', \ technologies=[], security_issues=[], cve_announcements=[], scans=[])", "cbw_object(id=12, target='5.5.5.5', category='linux', hostname=None, cve_announcements_count=0, \ created_at='2019-12-17T14:28:00.000+01:00', updated_at='2019-12-17T14:28:00.000+01:00', node_id=1, \ server_id=7, status='server_update_init', technologies=[], security_issues=[], cve_announcements=[], scans=[])" ] with vcr.use_cassette('spec/fixtures/vcr_cassettes/hosts.yaml'): response = client.hosts() assert len(response) == 4, str(response[0]) == hosts_validate[0] with vcr.use_cassette('spec/fixtures/vcr_cassettes/host.yaml'): response = client.host('12') assert str(response) == hosts_validate[1] params = {"target": "192.168.1.2", "node_id": "1"} with vcr.use_cassette('spec/fixtures/vcr_cassettes/create_host.yaml'): response = client.create_host(params) assert response.target == "192.168.1.2", response.node_id == 1 params["category"] = "other" with vcr.use_cassette('spec/fixtures/vcr_cassettes/update_host.yaml'): response = client.update_host('1', params) assert response.category == "other", response.node_id == 1 with vcr.use_cassette('spec/fixtures/vcr_cassettes/delete_host.yaml'): response = client.delete_host('1') assert response.target == '10.10.1.186'
"""POST request to /api/v3/hosts to create a new host""" import os from configparser import ConfigParser from cbw_api_toolbox.cbw_api import CBWApi CONF = ConfigParser() CONF.read( os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'api.conf')) CLIENT = CBWApi(CONF.get('cyberwatch', 'url'), CONF.get('cyberwatch', 'api_key'), CONF.get('cyberwatch', 'secret_key')) PARAMS = { "target": "", #Required, IP address of the new host targeted. "node_id": "", #Required, Node ID to link the new Host to. "server_id": "", #ID of the server to link the new Host to. "hostname": "", #Hostname of the new Host. "category": "" #Category of the new Host. } CLIENT.create_host(PARAMS)