def __init__(self, manageiq_aws_access_key, manageiq_aws_secret_key, manageiq_home_directory, manageiq_endpoint='https://127.0.0.1:8443/', manageiq_username='******', manageiq_password='******', manageiq_region='us-east-2', manageiq_provider_name='API_call', manageiq_ports=None, manageiq_docker_image='manageiq/manageiq:gaprindashvili-3'): if manageiq_ports is None: manageiq_ports = {'443/tcp': 8443} self.manageiq_home_directory = manageiq_home_directory self.manageiq_aws_access_key = manageiq_aws_access_key self.manageiq_aws_secret_key = manageiq_aws_secret_key self.manageiq_endpoint = manageiq_endpoint self.manageiq_username = manageiq_username self.manageiq_password = manageiq_password self.manageiq_region = manageiq_region self.manageiq_provider_name = manageiq_provider_name self.manageiq_ports = manageiq_ports self.manageiq_docker_image = manageiq_docker_image try: self.client = MiqApi(self.manageiq_endpoint + 'api', dict(user=self.manageiq_username, password=self.manageiq_password), verify_ssl=False) except ConnectionError: self.client = None self.provider = None
def __init__(self, module, url, user, password, miq_verify_ssl, ca_bundle_path): self.module = module self.api_url = url + '/api' self.user = user self.password = password self.client = MiqApi(self.api_url, (self.user, self.password), verify_ssl=miq_verify_ssl, ca_bundle_path=ca_bundle_path) self.changed = False
def _gen_automation_requests(output): api = MiqApi(entry_point, auth, verify_ssl=False) requests_data = _automation_requests_data( 'nonexistent_vm', requests_collection=True, approve=False) api.collections.requests.action.create(*requests_data[:2]) result = (api.response.status_code, api.response.json()) output.put(result)
def get_miq_client(): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) url = os.environ.get('MIQURL') or 'https://192.168.188.175:32640/api' username = os.environ.get('MIQUSERNAME') or 'admin' password = os.environ.get('MIQPASSWORD') or 'smartvm' token = os.environ.get('MIQTOKEN') if token: print("\nAuthenticating with the API token") client = MiqApi(url, dict(token=token), verify_ssl=False) else: print("\nAuthenticating with the user credentials: " + username + " / " + password) client = MiqApi(url, dict(user=username, password=password), verify_ssl=False) return client
def test_api_version(self): with HTTMock(api_mock): api_default = MiqApi('http://example.com/api', ('admin', 'admin'), verify_ssl=False) api_version = api_default.api_version('2.4.0') assert api_default._entry_point == 'http://example.com/api' assert api_version._entry_point == 'http://example.com/api/v2.4.0' assert api_default._auth == api_version._auth assert api_default.logger is api_version.logger assert api_default._verify_ssl == api_version._verify_ssl assert api_default._ca_bundle_path == api_version._ca_bundle_path
def run(self, **kwargs): kwargs_dict = dict(kwargs) server = self._get_arg("server", kwargs_dict) username = self._get_arg("username", kwargs_dict) password = self._get_arg("password", kwargs_dict) operation = self._get_arg("operation", kwargs_dict) client = MiqApi("https://" + server + "/api", (username, password), verify_ssl=False) # call the operation by name operation_func = getattr(self, operation) return operation_func(client, kwargs_dict)
help= "URL of the target appliance, default pulled from local environment conf" ) parser.add_argument('--logfile', metavar='FILE', default=os.path.join(log_path.strpath, 'cfme.log'), help="path to cfme log file, default: %(default)s") args = parser.parse_args() appliance_url = args.url or get_or_create_current_appliance().url # we are really not interested in any warnings and "warnings.simplefilter('ignore')" # doesn't work when it's redefined later in the REST API client warnings.showwarning = lambda *args, **kwargs: None api = MiqApi('{}/api'.format(appliance_url.rstrip('/')), (conf.credentials['default']['username'], conf.credentials['default']['password']), verify_ssl=False) print(f"Appliance URL: {appliance_url}") store = {} get_collections_info(api, store) if os.path.isfile(args.logfile): get_coverage(args.logfile, store) print_info(store)
import os from manageiq_client.api import ManageIQClient as MiqApi url = os.environ.get('MIQURL') or 'http://localhost:3000/api' username = os.environ.get('MIQUSERNAME') or 'admin' password = os.environ.get('MIQPASSWORD') or 'smartvm' client = MiqApi(url, (username, password)) print("\nManageIQ version: {0}".format(client.version)) print("\nVirtual Machines Collection\n") for vm in client.collections.vms.all: print(vm.name)
import os from manageiq_client.api import ManageIQClient as MiqApi url = os.environ.get('MIQURL') or 'http://localhost:3000/api' username = os.environ.get('MIQUSERNAME') or 'admin' password = os.environ.get('MIQPASSWORD') or 'smartvm' token = os.environ.get('MIQTOKEN') client = None if token: print("\nAuthenticating with the API token") client = MiqApi(url, dict(token=token)) else: print("\nAuthenticating with the user credentials: "+username+" / "+password) client = MiqApi(url, dict(user=username, password=password)) print("\nManageIQ version: {0}".format(client.version)) print("\nVirtual Machines Collection\n") for vm in client.collections.vms.all: print(vm.name)
def api(): with HTTMock(api_mock): api = MiqApi('http://example.com/api', ('admin', 'admin'), verify_ssl=False) return api
def test_valid_login_credentials(self, load): MiqApi('http://example.com', {'user': '******', 'password': '******'})
def test_invalid_token_key(self): with pytest.raises(ValueError): MiqApi('http://example.com', {'Token': '123234'}) MiqApi('http://example.com', {'Broken': '123234'}) MiqApi('http://example.com', ['123234']) MiqApi('http://example.com', ('123234', ))
def test_token_passed_in_dict(self, load): MiqApi('http://example.com', {'token': '123234'})
def test_no_user_or_password_dict(self): with pytest.raises(ValueError): MiqApi('http://example.com', {'user': '******'}) MiqApi('http://example.com', {'password': '******'})
def test_no_user_password_dict_list_or_tuple(self): with pytest.raises(ValueError): MiqApi('http://example.com', {}) MiqApi('http://example.com', []) MiqApi('http://example.com', ())
def user_api(self, appliance, user_auth): entry_point = appliance.rest_api._entry_point return MiqApi(entry_point, user_auth, verify_ssl=False)
def test_token_passed_in_dict(self): MiqApi('http://www.test.com', {'token': '123234'})
def test_valid_login_credentials(self): MiqApi('http://www.test.com', {'user': '******', 'password': '******'})
from time import sleep # the next line assumes you're running this on the CFME appliance itself. # If not, you need to add the parameter ssl_verify=False to the client # MiqApi() initialization because CFME appliances use self-signed certs # by default. url = os.environ.get('MIQURL') or 'http://localhost:3000/api' username = os.environ.get('MIQUSERNAME') or 'admin' password = os.environ.get('MIQPASSWORD') or 'smartvm' token = os.environ.get('MIQTOKEN') # CF API Authentication (client initialization) client = None if token: print("\nAuthenticating with the API token") client = MiqApi(url, dict(token=token), verify_ssl=False) else: print("\nAuthenticating with the user credentials") client = MiqApi(url, dict(user=username, password=password), verify_ssl=False) payload = { 'action_method': 'POST', 'uri_parts': { 'namespace': 'AutomationManagement/AnsibleTower/Operations/StateMachines', 'class': 'Job', # 'instance': 'default', 'instance': 'autobranch', # This instance is a custom Automate instance (i.e. won't work with out-of-the-box CloudForms) 'message': 'create' }, 'parameters': { 'job_template_name': 'i-was-here',