def take_action(self, parsed_args): compute_client = self.app.client_manager.compute server = utils.find_resource( compute_client.servers, parsed_args.server, ) if parsed_args.property: compute_client.servers.delete_meta( server, parsed_args.property, ) if parsed_args.description: if compute_client.api_version < api_versions.APIVersion("2.19"): msg = _("Description is not supported for " "--os-compute-api-version less than 2.19") raise exceptions.CommandError(msg) compute_client.servers.update( server, description="", ) if parsed_args.tag: if compute_client.api_version < api_versions.APIVersion("2.26"): msg = _("Modifying tags is not supported for " "--os-compute-api-version less than 2.26") raise exceptions.CommandError(msg) sdk.load(self.app.client_manager.sdk_connection) client = self.app.client_manager.sdk_connection.compute server = client.get_server(server.id) for tag in parsed_args.tag: server.remove_tag(client, tag)
def openstack_cloud_from_module(self, min_version='0.6.9'): if self.otce_min_version: min_version = self.otce_min_version if not HAS_LIBRARIES: self.fail_json( msg='openstacksdk and otcextensions are required for this self' ) if min_version: min_version = max(StrictVersion('0.6.9'), StrictVersion(min_version)) else: min_version = StrictVersion('0.6.9') if StrictVersion(otcextensions.__version__) < min_version: self.fail_json( msg="To utilize this self, the installed version of " "the otcextensions library MUST be >={min_version}".format( min_version=min_version)) cloud_config = self.params.pop('cloud', None) try: if isinstance(cloud_config, dict): fail_message = ( "A cloud config dict was provided to the cloud parameter" " but also a value was provided for {param}. If a cloud" " config dict is provided, {param} should be" " excluded.") for param in ('auth', 'region_name', 'validate_certs', 'ca_cert', 'client_key', 'api_timeout', 'auth_type'): if self.params[param] is not None: self.fail_json(msg=fail_message.format(param=param)) # For 'interface' parameter, fail if we receive a non-default value if self.params['interface'] != 'public': self.fail_json(msg=fail_message.format(param='interface')) conn = sdk.connect(**cloud_config) otc_sdk.load(conn) return sdk, conn else: conn = sdk.connect( cloud=cloud_config, auth_type=self.params['auth_type'], auth=self.params['auth'], region_name=self.params['region_name'], verify=self.params['validate_certs'], cacert=self.params['ca_cert'], key=self.params['client_key'], api_timeout=self.params['api_timeout'], interface=self.params['interface'], ) otc_sdk.load(conn) return sdk, conn except sdk.exceptions.SDKException as e: # Probably a cloud configuration/login error self.fail_json(msg=str(e))
def take_action(self, parsed_args): compute_client = self.app.client_manager.compute server = utils.find_resource( compute_client.servers, parsed_args.server, ) if parsed_args.name: server.update(name=parsed_args.name) if parsed_args.property: compute_client.servers.set_meta( server, parsed_args.property, ) if parsed_args.state: server.reset_state(state=parsed_args.state) if parsed_args.root_password: p1 = getpass.getpass(_('New password: '******'Retype new password: ')) if p1 == p2: server.change_password(p1) else: msg = _("Passwords do not match, password unchanged") raise exceptions.CommandError(msg) if parsed_args.description: if server.api_version < api_versions.APIVersion("2.19"): msg = _("Description is not supported for " "--os-compute-api-version less than 2.19") raise exceptions.CommandError(msg) server.update(description=parsed_args.description) if parsed_args.tag: if server.api_version < api_versions.APIVersion("2.26"): msg = _("Modifying tags is not supported for " "--os-compute-api-version less than 2.26") raise exceptions.CommandError(msg) sdk.load(self.app.client_manager.sdk_connection) client = self.app.client_manager.sdk_connection.compute server = client.get_server(server.id) for tag in parsed_args.tag: server.add_tag(client, tag)
def setUp(self): super(TestCase, self).setUp() sdk.load(self.cloud) self.cloud.config.config['rdsv3_api_version'] = '3'
def setUp(self): super(TestCase, self).setUp() sdk.load(self.cloud)