GithubHelp home page GithubHelp logo

david-caro / python-foreman Goto Github PK

View Code? Open in Web Editor NEW
57.0 13.0 37.0 625 KB

Small low level python wrapper around Foreman API

License: GNU General Public License v2.0

Python 96.01% Shell 3.99%

python-foreman's Introduction

NOTE: this library is not being maintained anymore, if anyone is willing to continue please open an issue/discussion.

python-foreman

Latest Version in PyPI Travis build status Downloads Supported Python versions Project Licens

Simple library to acces the Foreman API, the full documentation can be found here:

http://python-foreman.readthedocs.org

Installation

Execute as root:

$ python setup.py sdist
$ pip install ./dist/python-foreman-\*.tar.gz

Plugins

The plugins should be a simple module file with the a dictionary named DEFS with the definitions of the new methods as in the definitions.py file

python-foreman's People

Contributors

damoxc avatar david-caro avatar ekohl avatar jcmcken avatar jvdiago avatar lukas-bednar avatar machalekj avatar ntr0 avatar pief avatar rbaier avatar tsujamin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-foreman's Issues

Review version detection

there is another issue
version detection fails

using with foreman 1.3 and foreman.client
when im creating the api object without version spec, getting this exception:
ForemanVersionException: Unable to get version

when version specified like this:
f = Foreman('https://x', auth=('x', 'x'), version='1.3') it works as excepted.

Regards,
Eldad

I thought that was solved, make sure ๐Ÿ˜ถ

Failed to install package, any help?

Failed to install package on windows system
Traceback (most recent call last):
File "C:\python-foreman-master\python-foreman-master
setup.py", line 35, in
'Programming Language :: Python :: 3.4',
File "C:\ProgramData\Anaconda2\lib\site-packages\setuptools_init_.py", line
140, in setup
return distutils.core.setup(**attrs)
File "C:\ProgramData\Anaconda2\lib\distutils\core.py", line 111, in setup
setup_distribution = dist = klass(attrs)
File "C:\ProgramData\Anaconda2\lib\site-packages\setuptools\dist.py", line 370
, in init
k: v for k, v in attrs.items()
File "C:\ProgramData\Anaconda2\lib\distutils\dist.py", line 287, in init
self.finalize_options()
File "C:\ProgramData\Anaconda2\lib\site-packages\setuptools\dist.py", line 529
, in finalize_options
ep.load()(self, ep.name, value)
File "build\bdist.win-amd64\egg\autosemver_init
.py", line 176, in distutil
s
File "build\bdist.win-amd64\egg\autosemver_init_.py", line 125, in distutil
s_autosemver_case
File "build\bdist.win-amd64\egg\autosemver\packaging.py", line 86, in get_curr
ent_version
RuntimeError: Failed to get package version

No support for pagination

Unfortunately client has no support for pagination.
Eg. if I call following against Foreman with more than 50 hosts:

hosts = provider.foreman.index_hosts()

The result looks like:

(Pdb) hosts.keys()
[u'sort', u'search', u'results', u'per_page', u'total', u'subtotal', u'page']
(Pdb) hosts['results'] = {}
(Pdb) print simplejson.dumps(hosts, indent=4, separators=(',', ': '))
{
    "sort": {
        "by": null,
        "order": null
    },
    "search": null,
    "results": {},
    "per_page": 50,
    "total": 583,
    "subtotal": 583,
    "page": 1
}

I believe this is a bug because it makes listing all hosts/users/whatever impossible and user has to handle pages on his own.

Problem creating hostgroup parameter

hi,

i am using foreman 1.23, and i am getting an exception when trying to create a hostgroup parameter.

example:

import foreman.client

client = foreman.client.Foreman('https://foreman.example.com', ('username', 'password'), api_version=2)

client.hostgroups.parameters_create(hostgroup_id=2742, parameter={'name': 'blarg', 'parameter_type': 'string', 'value': 'blub'})

exception:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<string>", line 23, in parameters_create
  File "/Users/sschultchen/PycharmProjects/idms_gammel/venv/lib/python3.7/site-packages/foreman/client.py", line 929, in do_post
    return self._process_request_result(res)
  File "/Users/sschultchen/PycharmProjects/idms_gammel/venv/lib/python3.7/site-packages/foreman/client.py", line 897, in _process_request_result
    'Something went wrong:%s' % res_to_str(res)
foreman.client.ForemanException: Something went wrong:
####################################
url = https://foreman.svc.sdcid.net/api/hostgroups/2742/parameters
headers = {'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json; version=2', 'Connection': 'keep-alive', 'Content-type': 'application/json', 'Cookie': '_session_id=9f620c1d4cfd942b8148cca4656bead1; request_method=POST', 'Content-Length': '99', 'Authorization': '*****'}
-------- data sent -----------------
{"hostgroup_id": 2742, "parameter": {"name": "blarg", "parameter_type": "string", "value": "blub"}}
------------------------------------
@@@@@ response @@@@@@@@@@@@@@@@
headers = {'Date': 'Mon, 07 Oct 2019 08:46:17 GMT', 'Server': 'Apache/2.4.6 (CentOS)', 'Foreman_version': '1.23.0', 'Foreman_api_version': '2', 'Foreman_current_organization': '; ANY', 'Foreman_current_location': '; ANY', 'Apipie-Checksum': '4be770720e89ae2ed776a93d3ff914dbb24942ec', 'Cache-Control': 'no-cache', 'X-Request-Id': '[SNIP]', 'X-Runtime': '0.044100', 'Strict-Transport-Security': 'max-age=631139040; includeSubdomains', 'X-Frame-Options': 'sameorigin', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'Content-Security-Policy': "default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data: *.gravatar.com; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'", 'X-Powered-By': 'Phusion Passenger 4.0.53', 'Set-Cookie': '_session_id=9f620c1d4cfd942b8148cca4656bead1; path=/; expires=Tue, 08 Oct 2019 08:46:17 -0000; HttpOnly; secure; SameSite=Lax', 'Status': '500 Internal Server Error', 'Connection': 'close', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json; charset=utf-8'}
code = 500
reason = Internal Server Error
--------- data received ------------
{
  "error": {"message":"Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs."}
}
------------------------------------
####################################

and this is what i get in the foreman production.log

019-10-07T10:49:56 [I|app|65a6a8ac] Started POST "/api/hostgroups/2742/parameters" for 10.201.201.82 at 2019-10-07 10:49:56 +0200
2019-10-07T10:49:56 [I|app|65a6a8ac] Processing by Api::V2::ParametersController#create as JSON
2019-10-07T10:49:56 [I|app|65a6a8ac]   Parameters: {"hostgroup_id"=>"2742", "parameter"=>{"name"=>"blarg", "parameter_type"=>"string", "value"=>"[FILTERED]"}, "apiv"=>"v2"}
2019-10-07T10:49:56 [W|app|65a6a8ac] Action failed
 | ActiveModel::UnknownAttributeError: unknown attribute 'organization_id' for GroupParameter.
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:53:in `_assign_attribute'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:44:in `block in _assign_attributes'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:43:in `each'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:43:in `_assign_attributes'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/attribute_assignment.rb:23:in `_assign_attributes'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activemodel-5.2.1/lib/active_model/attribute_assignment.rb:35:in `assign_attributes'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/core.rb:314:in `initialize'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/inheritance.rb:66:in `new'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/inheritance.rb:66:in `new'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/reflection.rb:154:in `build_association'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/association.rb:276:in `build_record'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_association.rb:106:in `build'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/associations/collection_proxy.rb:319:in `build'
 | /usr/share/foreman/app/controllers/api/v2/parameters_controller.rb:86:in `create'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:194:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:109:in `block in run_callbacks'
 | /usr/share/foreman/app/controllers/api/v2/base_controller.rb:163:in `disable_json_root'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
 | /usr/share/foreman/app/controllers/concerns/foreman/controller/timezone.rb:10:in `set_timezone'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
 | /usr/share/foreman/app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
 | /usr/share/foreman/app/controllers/concerns/foreman/controller/topbar_sweeper.rb:12:in `set_topbar_sweeper_controller'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/sweeper.rb:14:in `around'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.7.1/lib/audited/sweeper.rb:14:in `around'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:118:in `block in run_callbacks'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:136:in `run_callbacks'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:41:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/rescue.rb:22:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in `block in instrument'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in `instrument'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activerecord-5.2.1/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:134:in `process'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionview-5.2.1/lib/action_view/rendering.rb:32:in `process'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal.rb:191:in `dispatch'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_controller/metal.rb:252:in `dispatch'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:34:in `serve'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/mapper.rb:48:in `serve'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:52:in `block in serve'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:35:in `each'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/journey/router.rb:35:in `serve'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/routing/route_set.rb:840:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/lib/apipie/static_dispatcher.rb:65:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/lib/apipie/extractor/recorder.rb:137:in `call'
 | /usr/share/foreman/lib/foreman/middleware/telemetry.rb:10:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/apipie-rails-0.5.14/lib/apipie/middleware/checksum_in_headers.rb:27:in `call'
 | /usr/share/foreman/lib/foreman/middleware/catch_json_parse_errors.rb:9:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/tempfile_reaper.rb:15:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/etag.rb:25:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/conditional_get.rb:38:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
 | /usr/share/foreman/lib/foreman/middleware/logging_context_session.rb:22:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:232:in `context'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:226:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/cookies.rb:670:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/rack/logger.rb:38:in `call_app'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/rack/logger.rb:28:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:13:in `call'
 | /usr/share/foreman/lib/foreman/middleware/logging_context_request.rb:11:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/runtime.rb:22:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/activesupport-5.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/actionpack-5.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/sendfile.rb:111:in `call'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/secure_headers-6.0.0/lib/secure_headers/middleware.rb:13:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/engine.rb:524:in `call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/railtie.rb:190:in `public_send'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/railties-5.2.1/lib/rails/railtie.rb:190:in `method_missing'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/urlmap.rb:68:in `block in call'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `each'
 | /opt/theforeman/tfm-ror52/root/usr/share/gems/gems/rack-2.0.6/lib/rack/urlmap.rb:53:in `call'
 | /usr/share/passenger/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
 | /usr/share/passenger/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
 | /usr/share/passenger/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
 | /usr/share/passenger/phusion_passenger/request_handler.rb:455:in `block (3 levels) in start_threads'
 | /opt/theforeman/tfm/root/usr/share/gems/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'

this is working when using the WebUI, but i noticed that the webui is using a different API endpoint to add the parameter.

from the foreman production.log:

2019-10-07T10:57:06 [I|app|a6a9d48f] Started PATCH "/hostgroups/2742-default-pcs_mgmttt" for 10.201.201.82 at 2019-10-07 10:57:06 +0200
2019-10-07T10:57:06 [I|app|a6a9d48f] Processing by HostgroupsController#update as */*
2019-10-07T10:57:06 [I|app|a6a9d48f]   Parameters: {"utf8"=>"โœ“", "authenticity_token"=>"[SNIP]", "hostgroup"=>{"parent_id"=>"6", "name"=>"pcs_mgmttt", "description"=>"", "environment_id"=>"", "compute_resource_id"=>"", "compute_profile_id"=>"", "domain_id"=>"", "subnet_id"=>"", "realm_id"=>"", "architecture_id"=>"", "operatingsystem_id"=>"", "medium_id"=>"", "ptable_id"=>"", "pxe_loader"=>"", "group_parameters_attributes"=>{"1570438619896"=>{"name"=>"blarg", "parameter_type"=>"string", "value"=>"[FILTERED]", "hidden_value"=>"[FILTERED]", "_destroy"=>"false"}}, "location_ids"=>["9", "12", "13", "10", "14", ""], "organization_ids"=>["20", ""], "id"=>"2742"}, "id"=>"2742-default-pcs_mgmttt"}
2019-10-07T10:57:07 [I|aud|a6a9d48f] Hostgroup (2742) update event on description ,
2019-10-07T10:57:07 [I|aud|a6a9d48f] Hostgroup (2742) update event on pxe_loader ,
2019-10-07T10:57:07 [I|aud|a6a9d48f] Hostgroup (2742) update event on location_ids , 9, 12, 13, 10, 14
2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on name blarg
2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on value blub
2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on reference_id 2742
2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on hidden_value false
2019-10-07T10:57:07 [I|aud|a6a9d48f] Parameter (4056) create event on key_type string

Unable to list environments

Hi,
I am using python-foreman version 0.2.2 against Foreman 1.7.2-v2.json

Default environments.index() is mapped to index_puppetclasses instead to /environments/
and actually makes it impossible to list all environments.

See attached bpython output.

c.environments.index(
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚ c.environments.index: (self, puppetclass_id, search=None, order=None, page=None, per_page=None)
โ”‚
โ”‚ index index_hosts index_puppetclasses โ”‚
โ”‚ index_smart_class_parameters โ”‚
โ”‚ List environments of Puppet class โ”‚
โ”‚ :param puppetclass_id: ID of Puppet class; Must be String (OPTIONAL)
โ”‚ :param search: filter results; Must be String (OPTIONAL)
โ”‚ :param order: sort results; Must be String (OPTIONAL)
โ”‚ :param page: paginate results; Must be String (OPTIONAL) โ”‚ :param per_page: number of entries per request; Must be String (OPTIONAL) โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Failed to install python-foreman release 0.3.1

Moving to 0.3.1 broken my installation process.
I am using python-foreman as a requirement in my project.
When release 0.3.1 introduced my project installation suddenly start to break.

Downloading python-foreman-0.3.1.linux-x86_64.tar.gz (159kB): 159kB downloaded
Running setup.py (path:/tmp/pip-build-2K5JAs/python-foreman/setup.py) egg_info for package python-foreman
Traceback (most recent call last):
File "", line 17, in
IOError: [Errno 2] No such file or directory: '/tmp/pip-build-2K5JAs/python-foreman/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

IOError: [Errno 2] No such file or directory: '/tmp/pip-build-2K5JAs/python-foreman/setup.py'

Adding parameter to a host results in error

This is a followup here to the Foreman bug I filed. Filing here because I'm not sure if the issue I'm seeing is a Foreman or foreman-python bug.

http://projects.theforeman.org/issues/10421

Trying to add a parameter to a host fails due to a an error thrown in Foreman

foreman_client.update_hosts({'parameters' : [{'name':'k2', 'value':'v2'}]}, 'i-036c522c.example.com')

ForemanException: Something went wrong:
####################################
url = http://foreman.example.com/api/hosts/i-036c522c.example.com
headers = {'Content-Length': '90', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json; version=2', 'User-Agent': 'python-requests/2.7.0 CPython/2.7.6 Darwin/14.3.0', 'Connection': 'keep-alive', 'Cookie': '_session_id=1e5590f95e7ad51c9fc58f4ebf39d279', 'Content-type': 'application/json', 'Authorization': '*****'}
-------- data sent -----------------
{"host": {"parameters": [{"name": "k2", "value": "v2"}]}, "id": "i-036c522c.example.com"}
------------------------------------
@@@@@ response @@@@@@@@@@@@@@@@
headers = {'status': '500 Internal Server Error', 'x-request-id': '3a96d989227057cc80cdb1424c256047', 'x-powered-by': 'Phusion Passenger 4.0.10', 'transfer-encoding': 'chunked', 'foreman_version': '1.7.4', 'connection': 'close', 'server': 'Apache/2.2.22 (Debian)', 'x-runtime': '0.052732', 'x-ua-compatible': 'IE=Edge,chrome=1', 'cache-control': 'no-cache', 'date': 'Fri, 08 May 2015 12:48:41 GMT', 'apipie-checksum': '812463b3f4cade98d0325612a8c8c2cd', 'content-type': 'application/json; charset=utf-8', 'x-rack-cache': 'invalidate, pass', 'foreman_api_version': '2'}
code = 500
reason = Internal Server Error
--------- data received ------------
{
  "error": {"message":"undefined method `id' for nil:NilClass"}
}

------------------------------------
####################################

This has to do with the formation of the request sent to Foreman. As noted in the Foreman bug report posting to /api/hosts/:id fails while posting to /api/hosts/:id/parameters works

fail: http://foreman.example.com/api/hosts/i-036c522c.example.com
sccess: http://foreman.example.com/api/hosts/i-036c522c.example.com/parameters

Foreman.puppetclasses.show() returns inconsistent types

Tracked down an inconsistency while troubleshooting an error in my app. After getting the data back from Foreman I was expecting to interact with a dictionary but was unexpectedly interacting with a list.

In [112]: type(foreman_client.puppetclasses.show('apache'))
Out[112]: dict

In [113]: type(foreman_client.puppetclasses.show('apache1'))
Out[113]: list

managing host interfaces

I can't tell if it's missing functionality or just missing docs; but I can't figure out how to manage host interfaces using python-foreman.

Hostgroups Index

When trying to use the index method for the hostgroups:

TypeError: index() takes at least 2 arguments (1 given)

If an argument is given (ie 'someargument') the following url gets queried:

 /api/puppetclasses/someargument/hostgroups

This is using Foreman 1.7.3 and use_cache=False upon object creation.

use a specific logger

I have constatly a warning message:

Thereis a conflit trying to redefine method"

I do not use concerned functionality and i would like just to disable this message. This would be easy if python-foreman uses a specific "foreman" logger (logger = logging.getLogger(__name__)) and not a general 'root' (logging). So that user can specify the level of verbosity and supress warning on his own risk.

ex:

logging.warning(

Support for timeouts

Now you don't pass any timeouts to 'requests' methods, so it is set to None, which means either "no timeout" or "default (very high) timeout". Please either pass explicitly reasonable timeouts or (preferably) let user set it.

Instantiating foreman.client.Foreman object throws exception with python-foreman 0.3

python-foreman: 0.3
Foreman: 1.7.4

The following works in 0.2.2 but broke after creating new virtualenv with 0.3

In [1]: from foreman.client import Foreman

In [2]: foreman_client = Foreman('http://foreman.example.com', ('user', 'password'), api_version=2)
/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-2-6d24fd5ae9c0> in <module>()
----> 1 foreman_client = Foreman('http://foreman.jana.io', ('tom', 'Camel1Merit!F'), api_version=2)

/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/foreman/client.pyc in __init__(self, url, auth, version, api_version, use_cache, strict_cache, timeout, timeout_post, timeout_delete, timeout_put, verify)
    573             self.version = self.get_foreman_version()
    574
--> 575         self._generate_api_defs(use_cache, strict_cache)
    576         # Instantiate plugins
    577         self.plugins = self._plugins_resources(self)

/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/foreman/client.pyc in _generate_api_defs(self, use_cache, strict_cache)
    743             definitions file as valid
    744         """
--> 745         data = self._get_defs(use_cache, strict_cache=strict_cache)
    746
    747         resource_defs = {}

/Users/tom/.virtualenvs/central-booking/lib/python2.7/site-packages/foreman/client.pyc in _get_defs(self, use_cache, strict_cache)
    728             except ForemanVersionException as exc:
    729                 logging.debug(exc)
--> 730         if not data:
    731             logging.debug("Checking remote server for definitions")
    732             data = self._get_remote_defs()

UnboundLocalError: local variable 'data' referenced before assignment

Missing tags?

I can't find 0.4.1, 0.4.5, 0.4.11, 0.4.12 tags. Have they by chance not been pushed up to github?

problem modifying interfaces

Hello,

I am trying to modify an interface on an existing host but am not having any luck. This is a physical server that has 4 interfaces, plus an IPMI interface. I want to modify only one of the interfaces. I have tried using the hosts.update routine like this:

In [324]: f.hosts.update('341423',
     ...:     {'interface_attributes': [{
     ...:         '1': {'identifier': 'enp3s0f1',
     ...:              'ip': '172.28.5.28',
     ...:              'subnet_id': '13',
     ...:              'primary': 'true',
     ...:              'managed': 'true'
     ...:             }
     ...:            }]
     ...:     }
     ...: )

The only thing that happens is that I get back a hash of the host attributes but the interface doesn't get updated. There is no error. I have also tried the same thing with hosts.interfaces_host_id_updateinterfaces and have not been able to get that function to work correctly at all. Can you give me any pointers on the best way to go about modifying an interface?

Odd `id` argument in the `hosts.reports_last` method

There is a method of foreman.client.Foreman(): hosts.reports_last.

The help function output for it states, that the method takes 2 arguments: host_id and id, that are both required:

Help on method reports_last in module aiccliforeman.foreman_api.foreman.client:

reports_last(self, host_id, id) method of aiccliforeman.foreman_api.foreman.client.Hosts instance
    Show the last report for a host

    :param host_id: <no description>;  (REQUIRED)
    :param id: <no description>; Must be an identifier, string from 1 to 128 characters containing only alphanumeric characters, space, underscore(_), hypen(-) with no leading or trailing space. (REQUIRED)

Indicating different values in this argument lead to the same results. And also official Foreman API documentation states, that this method takes only 1 parameter - host_id: https://theforeman.org/api/1.8/apidoc/v2/reports/last.html. But I can see similar description in that doc and this method here for 'id' parameter. In this case I assume it could incorrectly generated.

Foreman version: 1.11.4
python-foreman: 0.4.19

Creating interfaces

How would I create interfaces for hosts with the API via /api/hosts/:host_id/interfaces? I've tried several things but every object that is requires an ID of an object declarated before its own I can't get to work. Is this possible?

python-foreman 0.4.12 broken pip package

this release doesn't contain python modules

python-foreman-0.4.12/
python-foreman-0.4.12/AUTHORS
python-foreman-0.4.12/LICENSE
python-foreman-0.4.12/python_foreman.egg-info/
python-foreman-0.4.12/python_foreman.egg-info/SOURCES.txt
python-foreman-0.4.12/python_foreman.egg-info/top_level.txt
python-foreman-0.4.12/python_foreman.egg-info/PKG-INFO
python-foreman-0.4.12/python_foreman.egg-info/dependency_links.txt
python-foreman-0.4.12/python_foreman.egg-info/requires.txt
python-foreman-0.4.12/setup.py
python-foreman-0.4.12/CHANGELOG
python-foreman-0.4.12/PKG-INFO
python-foreman-0.4.12/MANIFEST.in
python-foreman-0.4.12/README.rst
python-foreman-0.4.12/foreman/
python-foreman-0.4.12/foreman/definitions/
python-foreman-0.4.12/foreman/definitions/1.5.0-v1.json
python-foreman-0.4.12/foreman/definitions/1.7.2-v2.json
python-foreman-0.4.12/foreman/definitions/1.6.3-v1.json
python-foreman-0.4.12/foreman/definitions/1.4.2-v2.json
python-foreman-0.4.12/foreman/definitions/1.9.2-v2.json
python-foreman-0.4.12/foreman/definitions/1.7.1-v2.json
python-foreman-0.4.12/foreman/definitions/1.4.2-v1.json
python-foreman-0.4.12/foreman/definitions/1.7.1-v1.json
python-foreman-0.4.12/foreman/definitions/1.5.0-v2.json
python-foreman-0.4.12/foreman/definitions/1.6.3-v2.json
python-foreman-0.4.12/foreman/definitions/1.7.2-v1.json
python-foreman-0.4.12/setup.cfg

Unable to run against Foreman 1.9

When attempting to use against a Foreman 1.9 installation, I'm getting the following error when trying to use f.index_hosts().

There is a conflict trying to redefine method (available_storage_domains):
apipie_resource: compute_resources
new_api: <resource:compute_resources, name:available_storage_domains>
new_url: /api/compute_resources/:id/available_storage_domains
old_api: <resource:compute_resources, name:available_storage_domains>
old_url: /api/compute_resources/:id/available_storage_domains

I'm guessing it's due to there being no definitions in foreman/definitions for Foreman versions > 1.7.2...

If they're easily obtainable then I'll grab them and add them in?

Cheers
Gav

Foreman upgrade to 1.19 Issue

After upgrating to foreman 1.19 , host creation doesnt work.

There is no error on client side.

Server logs:

2018-09-04T14:03:01 [I|app|] Started POST "/api/hosts" for IP_address at 2018-09-04 14:03:01 +0100
2018-09-04T14:03:01 [I|app|a93f4] Processing by Api::V2::HostsController#create as JSON
2018-09-04T14:03:01 [I|app|a93f4]   Parameters: {"host"=>{"name"=>"test-vm", "hostgroup_id"=>8}, "apiv"=>"v2"}
2018-09-04T14:03:01 [I|app|a93f4] Redirected to https:/formean-url/api/hosts
2018-09-04T14:03:01 [I|app|a93f4] Filter chain halted as #<Proc:0x000000000a500460@/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/actionpack-5.1.6/lib/action_controller/metal/force_ssl.rb:65> rendered or redirected
2018-09-04T14:03:01 [I|app|a93f4] Completed 301 Moved Permanently in 1ms (ActiveRecord: 0.0ms)
2018-09-04T14:03:01 [I|app|] Started GET "/api/hosts" for 172.22.69.245 at 2018-09-04 14:03:01 +0100
2018-09-04T14:03:01 [I|app|ee986] Processing by Api::V2::HostsController#index as JSON

Python Version 2.7

Code ( it was working before foreman upgrade )

#!/usr/bin/env python2.7

import sys
import json
import urllib3
from foreman.client import Foreman
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)


# prepare the info
password = sys.argv[1]
user_foreman = sys.argv[2]
vmname = sys.argv[3]
host_group = int(sys.argv[4])
mac = sys.argv[5]



# get the foreman connection
try:
  f = Foreman('http://foreman-host', (user_foreman, password),api_version=2,verify=False)
  info = {}
  info["name"] = vmname
  info["mac"] = mac
  info["domain_id"] = 1
  info["hostgroup_id"] = host_group
  info["build"] = 1
  f.create_hosts(host=info)
except Exception as e:
  print("\n .... cloud not register the VM  ..." , e)

Using api_version=2 fails

#!/usr/bin/env python
from getpass import getpass
from foreman.client import Foreman, ForemanException
FOREMAN_URL = "https://foreman.example.com"
FOREMAN_USER = "foreman_api"
foreman_api = Foreman(url=FOREMAN_URL, auth=(FOREMAN_USER, getpass()), api_version=2)
/usr/lib/python2.7/site-packages/urllib3/connectionpool.py:769: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    foreman_api = Foreman(url=FOREMAN_URL, auth=(FOREMAN_USER, getpass()), api_version=2)
  File "/root/python-foreman-0.4.14/foreman/client.py", line 608, in __init__
    self._generate_api_defs(use_cache, strict_cache)
  File "/root/python-foreman-0.4.14/foreman/client.py", line 815, in _generate_api_defs
    res_dct,
  File "/root/python-foreman-0.4.14/foreman/client.py", line 399, in parse_resource_definition
    new_dict[api.name] = api.generate_func()
  File "/root/python-foreman-0.4.14/foreman/client.py", line 277, in generate_func
    six.exec_(code)
  File "/usr/lib/python2.7/site-packages/six.py", line 672, in exec_
    exec("""exec _code_ in _globs_, _locs_""")
  File "<string>", line 1, in <module>
  File "<string>", line 1
    def import(self, template, overwrite=None):

foreman-python 0.4.14
requests 2.6.0
six 1.9.0

This does not happen when api_version=1, it manages to fetch the json file for both v1 and v2, though the v2 version is very big, about 1.5MB.

Doesn't work with python 2.7

python setup.py sdist
Traceback (most recent call last):
  File "setup.py", line 35, in <module>
    'Programming Language :: Python :: 3.4',
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/setuptools/__init__.py", line 162, in setup
    return distutils.core.setup(**attrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 111, in setup
    _setup_distribution = dist = klass(attrs)
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/setuptools/dist.py", line 448, in __init__
    k: v for k, v in attrs.items()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 287, in __init__
    self.finalize_options()
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/setuptools/dist.py", line 740, in finalize_options
    ep(self)
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/setuptools/dist.py", line 747, in _finalize_setup_keywords
    ep.load()(self, ep.name, value)
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Users/collinleishman/Downloads/python-foreman-0.4.19/env/lib/python2.7/site-packages/autosemver/__init__.py", line 52
    def main(args: Optional[List[str]] = None) -> None:
                 ^
SyntaxError: invalid syntax

In setup.py, this should be the fix:
setup_requires=['autosemver==0.5.5'],

Make API definition cache dir configurable

I'll provide a PR if you'll accept it. I have a use-case where I'm utilizing python-foreman in an Apache app, and in RHEL-based distros of httpd the apache user's home dir is not writable (so the cache dir creation fails). If I could point to an alternate directory, it would make my life a bit easier

Proxy support

It would be nice if the library supported http proxies. Currently there is an outstanding issue with requests.Session that breaks this because it fails to use the proxy on a redirect using HTTPS. However this should be fixed in the next release.

I have done this locally by adding a proxies argument to the Foreman constructor and then setting the underlying requests.Session.proxies to it.

-mike

SSL Verification errors

Hi,

I've recently started looking at using python-foreman and encountered an issue where I can't use this module due to changes upstream in python and ssl verification has been switched to enabled by default and causes the following error to occur:

Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/foreman/init.py", line 49, in init
self.domains = Domains(self.api)
File "/usr/lib/python2.7/site-packages/foreman/objects.py", line 59, in init
dict.init(self, self.load())
File "/usr/lib/python2.7/site-packages/foreman/objects.py", line 151, in load
limit=self.searchLimit)}
File "/usr/lib/python2.7/site-packages/foreman/api.py", line 56, in _log
ret = function(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/foreman/api.py", line 99, in list
headers=self.headers)
File "/usr/lib/python2.7/site-packages/requests/api.py", line 68, in get
return request('get', url, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 464, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 602, in send
history = [resp for resp in gen] if allow_redirects else []
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 195, in resolve_redirects
allow_redirects=False,
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)

Investigating this I found the problem from Redhat (https://access.redhat.com/articles/2039753) which explains the problem and some solutions which partially work based on my installation of Foreman v1.15.6.

You can set to disable verification but this has the problem where is switches to using non ssl (port 80) which we don't use. The other options don't appear to work where we use environment variables to disable.

The only success I have had is to modify the module and point specifically at a working ca-bundle (on the foreman server) or disable the verification but I then need to add code to api.py to suppress warning messages that verification is disabled. So I think it would be better to add support to the module itself where the default is system default or true and allow us to override what verify should be set to?

In api.py I made the following change to make it work:

e.g. append verify to the requests calls:
self.resp = requests.get(url=self.url, auth=self.auth,
headers=self.headers, verify='/etc/ssl/certs/ca-bundle.trust.crt')

"Accept: application/json; version=2" triggers 500 Internal Server Error in Foreman when using URL without "/api/"

I noticed that python-foreman's usage of application/json; version=2 has an influence on Foreman's behavior when using URLs such as https://127.0.0.1/ without the /api/ part:

# curl -k --header "Accept: application/json" https://127.0.0.1/
{"error":"Authentication error"}
# curl -k --header "Accept: application/json; version=2" https://127.0.0.1/
<html><body>You are being <a href="https://127.0.0.1/users/login">redirected</a>.</body>
# curl -k --header "Accept: application/json; version=2" https://127.0.0.1/users/login
<!DOCTYPE html>
<html>
<head>
  <title>We're sorry, but something went wrong (500)</title>
[...]

This does not happen when one uses newer, "correct" URLs such as "https://127.0.0.1/api/":

#  curl -k --header "Accept: application/json" https://127.0.0.1/api/
{"message":"Unable to authenticate user "}
# curl -k --header "Accept: application/json; version=2" https://127.0.0.1/api/
{
  "error": {"message":"Unable to authenticate user "}
}

While this is, of course, Foreman's behavior and not python-foreman's behavior, python-foreman could (eg. via a regular expression) make sure that the supplied URL contains the /api/ part.

At the very least the documentation should be updated because the current (outdated, but still online) documentation at http://david-caro.github.io/python-foreman/basic.html#connect still refers to using an URL without the /api/ part, thus possibly irritating new python-foreman users.

'Foreman' object has no attribute 'lifecycle_environments'

I'm trying to manage lifecycle environments from katello plugins and I'm not sure what's going wrong.. The 'lifecycle_environments' is present in the definitions retrieved from the running foreman instance but there is no attribute for it:

>>> from foreman.client import Foreman
>>> fm = Foreman('https://foreman.com', ('admin','password'), api_version=2, use_cache=False, strict_cache=True)
>>> defs = fm._get_remote_defs()
>>> print defs["docs"]["resources"]["lifecycle_environments"]
{u'api_url': u'/api', u'deprecated': False, u'metadata': None, u'full_description': u'\n<p># Description</p>\n\n<p>An environment is a basic organization structure that groups hosts,\nproducts, repositories, etc.
.....

>>> fm.lifecycle_environments
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Foreman' object has no attribute 'lifecycle_environments'

problem with updating puppetclasses for a host

Hi,
I'm trying to add a puppetclass to the puppetclasses of a host, but can't seem to find out how.

First attempt was something like:

pc = f.show_puppetclasses(p_id)
host = f.show_hosts(id)
host['puppetclasses'].append(pc)
f.update_hosts(id=host['id'], host=host)

but that does nothing and even returns an empty resultset

then

ppn = { 'puppetclass_id': 4212 }
f.update_hosts(id=host['id'], host=ppn)

this takes much longer and returns the host resultset, but the class is not added.

Maybe you have a hint?

Thanks,
Sven

Write tests

At least any tests we can improve over time

Add Katello support

We are running a Python script in Jenkins to provision our hosts through Foreman using your python-foreman.
Now that we've moved some of our hosts to Satellite 6, it would be nicer to run REST requests that communicate with the Katello[*] through python-foreman instead of using requests API.

[*] we want to install the operating system from a given content view.

Problem to connect with foreman version > 2

When I try to connect with the Foreman version superior of 2. I get a error:

There is a conflict trying to redefine method (remove_content): apipie_resource: repositories new_api: <resource:repositories, name:remove_content> new_url: /katello/api/repositories/:id/remove_docker_manifests old_api: <resource:repositories, name:remove_content> old_url: /katello/api/repositories/:id/remove_packages

If I specify a version less then 2 its works.

Maybe the problem is related in functions:
parse_version or get_foreman_version

/api/template/import breaks python-foreman

MethodApiDescription.generate_func tries to generate a method "import" which leads to a syntax error. This could be fixed by renaming the function to "import_" in "MethodApiDescription._get_name" method.

ForemanVersionException: No suitable cache found for version=1.5.0 api_version=2.

Trying out the latest python-foreman from github (0.2) against Foreman 1.5.0, interactively inside of ipython and python 2.7:

In [1]: from getpass import getpass

In [2]: from foreman.client import Foreman

In [3]: f = Foreman('https://foreman.example.com/', ('username', getpass()))

Password:

ForemanVersionException Traceback (most recent call last)
in ()
----> 1 f = Foreman('https://foreman.example.com/', ('username', getpass()))

/Library/Python/2.7/site-packages/foreman/client.pyc in init(self, url, auth, version, api_version, use_cache)
315 if version is None:
316 version = self.get_foreman_version()
--> 317 self._generate_api_defs(version, api_version, use_cache)
318
319 # Instantiate plugins

/Library/Python/2.7/site-packages/foreman/client.pyc in _generate_api_defs(self, version, api_version, use_cache)
368 def _generate_api_defs(self, version, api_version, use_cache=True):
369 if use_cache:
--> 370 data = self._get_local_defs(version, api_version)
371 else:
372 res = self.session.get(

/Library/Python/2.7/site-packages/foreman/client.pyc in _get_local_defs(self, version, api_version)
364 "No suitable cache found for version=%s api_version=%s."
365 "\nAvailable: %s"
--> 366 % (version, api_version, '\n\t' + '\n\t'.join(files)))
367
368 def _generate_api_defs(self, version, api_version, use_cache=True):

ForemanVersionException: No suitable cache found for version=1.5.0 api_version=2.
Available:

`update_hosts` method works from the 2nd time

So here are 2 methods of foreman.client.Foreman(), that work incorrect for me:
update_hosts
hosts.update

It take 2 arguments: host and id. So I'm trying to invoke any of those methods from my code with these 2 args:
self.foreman_client.hosts.update(host=host_update_dict, id=1)

And here is the result from the first call:

(server side log)

2017-06-16T00:53:31 [app] [I] Started PUT "/api/hosts/1" for <foreman_ip> at 2017-06-16 00:53:31 +0000
2017-06-16T00:53:31 [app] [I] Processing by Api::V2::HostsController#update as JSON
2017-06-16T00:53:31 [app] [I]   Parameters: {"apiv"=>"v2", "id"=>"1", :host=>{}}

The host argument was sent empty for some reason.

And if I add the same LOC right after the first one, it works:

(my code)
self.foreman_client.hosts.update(host=host_update_dict, id=1)
self.foreman_client.hosts.update(host=host_update_dict, id=1)

(server side log)

2017-06-16T00:55:25 [app] [I] Started PUT "/api/hosts/1" for <foreman_ip> at 2017-06-16 00:55:25 +0000
2017-06-16T00:55:25 [app] [I] Processing by Api::V2::HostsController#update as JSON
2017-06-16T00:55:25 [app] [I]   Parameters: {"apiv"=>"v2", "id"=>"1", :host=>{}}
....................
2017-06-16T00:55:26 [app] [I] Started PUT "/api/hosts/1" for <foreman_ip> at 2017-06-16 00:55:26 +0000
2017-06-16T00:55:26 [app] [I] Processing by Api::V2::HostsController#update as JSON
2017-06-16T00:55:26 [app] [I]   Parameters: {"host"=>{"host_parameters_attributes"=>[{"id"=>1, "value"=>"[FILTERED]", "name"=>"option"}]}, "id"=>"1", "apiv"=>"v2"}

And every next the same request will work as well.

Foreman version: 1.14.3
python-foreman: 0.4.19

So in this case, am I doing something wrong or is it a bug?

Host creation error with 'host_parameters_attributes'

When i try to create host with below parameters, i get the unknown attribute error. I am trying to add custom host parameter attribute 'vm id'.

url = http://foremanstage1.ops.expertcity.com/api/hosts
headers = {'Content-Length': '292', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json; version=2', 'User-Agent': 'python-requests/2.5.1 CPython/2.7.5 Linux/2.6.32-504.el6.x86_64', 'Connection': 'keep-alive', 'Cookie': '_session_id=BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJWUxNDIxZWU2MGY4OTEzYTcyNGQ3OGYzYWMxMjVhMzdmBjsAVEkiEW9yaWdpbmFsX3VyaQY7AEYiFC91c2Vycy9leHRsb2dpbkkiC2xvY2FsZQY7AEZJIgdlbgY7AEY%3D--4399c6ed29c3995c918d9e26ee7b57ff0a8e8d22', 'Content-type': 'application/json', 'Authorization': '*****'}
-------- data sent -----------------
{"host": {"operatingsystem_id": 14, "environment_id": 4, "name": "amithf", "medium_id": 3, "subnet_id": 1, "ip": "10.229.70.187", "hostgroup_id": 96, "mac": "06:44:4e:00:06:88", "architecture_id": 1, "host_parameters_attributes": [{"vm_id": "QAI:105546"}], "domain_id": 2688, "ptable_id": 1}}

@@@@@ response @@@@@@@@@@@@@@@@
headers = {'status': '500 Internal Server Error', 'x-request-id': '4d66013ad42c13d198002c2f39dced39', 'x-powered-by': 'Phusion Passenger 4.0.18', 'transfer-encoding': 'chunked', 'set-cookie': '_session_id=BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJWUxNDIxZWU2MGY4OTEzYTcyNGQ3OGYzYWMxMjVhMzdmBjsAVEkiEW9yaWdpbmFsX3VyaQY7AEYiFC91c2Vycy9leHRsb2dpbkkiC2xvY2FsZQY7AEZJIgdlbgY7AEY%3D--4399c6ed29c3995c918d9e26ee7b57ff0a8e8d22; path=/; HttpOnly', 'foreman_version': '1.7.1', 'connection': 'close', 'server': 'Apache/2.2.15 (Red Hat)', 'x-runtime': '0.045447', 'x-ua-compatible': 'IE=Edge', 'cache-control': 'no-cache', 'date': 'Mon, 23 Mar 2015 21:04:17 GMT', 'apipie-checksum': '332cb2f58cb5663ef03d7f6512e4af2c', 'content-type': 'application/json; charset=utf-8', 'foreman_api_version': '2'}
code = 500
reason = Internal Server Error
--------- data received ------------
{
"error": {"message":"unknown attribute: vm_id"}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.