def create(self, name, flavor_id, volume=None, databases=None, users=None, restorePoint=None, availability_zone=None, datastore=None, datastore_version=None, nics=None, configuration=None, replica_of=None, slave_of=None, replica_count=None, modules=None, locality=None, region_name=None): """Create (boot) a new instance.""" body = {"instance": {"name": name, "flavorRef": flavor_id}} datastore_obj = {} if volume: body["instance"]["volume"] = volume if databases: body["instance"]["databases"] = databases if users: body["instance"]["users"] = users if restorePoint: body["instance"]["restorePoint"] = restorePoint if availability_zone: body["instance"]["availability_zone"] = availability_zone if datastore: datastore_obj["type"] = datastore if datastore_version: datastore_obj["version"] = datastore_version if datastore_obj: body["instance"]["datastore"] = datastore_obj if nics: body["instance"]["nics"] = nics if configuration: body["instance"]["configuration"] = base.getid(configuration) if replica_of or slave_of: if slave_of: warnings.warn(_LW("The 'slave_of' argument is deprecated in " "favor of 'replica_of' and will be removed " "after the Trove liberty series is end of " "life."), category=DeprecationWarning) body["instance"]["replica_of"] = base.getid(replica_of) or slave_of if replica_count: body["instance"]["replica_count"] = replica_count if modules: body["instance"]["modules"] = self._get_module_list(modules) if locality: body["instance"]["locality"] = locality if region_name: body["instance"]["region_name"] = region_name return self._create("/instances", body, "instance")
def update(self, instance, configuration=None, name=None, detach_replica_source=False, remove_configuration=False, is_public=None, allowed_cidrs=None): """Update instance. The configuration change, detach_replica and access change cannot be updated at the same time. """ body = {"instance": {}} if configuration and remove_configuration: raise Exception("Cannot attach and detach configuration " "simultaneously.") if remove_configuration: body["instance"]["configuration"] = None if configuration is not None: body["instance"]["configuration"] = base.getid(configuration) if name is not None: body["instance"]["name"] = name if detach_replica_source: body["instance"]["replica_of"] = None if is_public is not None or allowed_cidrs is not None: body["instance"]['access'] = {} if is_public is not None: body["instance"]['access']['is_public'] = is_public if allowed_cidrs is not None: body["instance"]['access']['allowed_cidrs'] = allowed_cidrs url = "/instances/%s" % base.getid(instance) resp, body = self.api.client.put(url, body=body) common.check_for_exceptions(resp, body, url)
def module_remove(self, instance, module): """Remove a module from an instance. """ url = "/instances/%s/modules/%s" % (base.getid(instance), base.getid(module)) resp, body = self.api.client.delete(url) common.check_for_exceptions(resp, body, url)
def modify(self, instance, configuration=None): body = {"instance": {}} if configuration is not None: body["instance"]["configuration"] = base.getid(configuration) url = "/instances/%s" % base.getid(instance) resp, body = self.api.client.put(url, body=body) common.check_for_exceptions(resp, body, url)
def create(self, name, flavor_id, volume=None, databases=None, users=None, restorePoint=None, availability_zone=None, datastore=None, datastore_version=None, nics=None, configuration=None, replica_of=None, replica_count=None, modules=None, locality=None, region_name=None, access=None, **kwargs): """Create (boot) a new instance.""" body = {"instance": {"name": name, "flavorRef": flavor_id}} datastore_obj = {} if volume: body["instance"]["volume"] = volume if databases: body["instance"]["databases"] = databases if users: body["instance"]["users"] = users if restorePoint: body["instance"]["restorePoint"] = restorePoint if availability_zone: body["instance"]["availability_zone"] = availability_zone if datastore: datastore_obj["type"] = datastore if datastore_version: datastore_obj["version"] = datastore_version if datastore_obj: body["instance"]["datastore"] = datastore_obj if nics: body["instance"]["nics"] = nics if configuration: body["instance"]["configuration"] = base.getid(configuration) if replica_of: body["instance"]["replica_of"] = base.getid(replica_of) if replica_count: body["instance"]["replica_count"] = replica_count if modules: body["instance"]["modules"] = self._get_module_list(modules) if locality: body["instance"]["locality"] = locality if region_name: body["instance"]["region_name"] = region_name if access: body["instance"]["access"] = access return self._create("/instances", body, "instance")
def test_getid(self): obj = "test" r = base.getid(obj) self.assertEqual(obj, r) test_id = "test_id" obj = mock.Mock() obj.id = test_id r = base.getid(obj) self.assertEqual(test_id, r)
def modify(self, instance, configuration=None): body = { "instance": { } } if configuration is not None: body["instance"]["configuration"] = base.getid(configuration) url = "/instances/%s" % base.getid(instance) resp, body = self.api.client.put(url, body=body) common.check_for_exceptions(resp, body, url)
def create(self, name, flavor_id, volume=None, databases=None, users=None, restorePoint=None, availability_zone=None, datastore=None, datastore_version=None, nics=None, configuration=None, replica_of=None, slave_of=None, replica_count=None, modules=None, locality=None): """Create (boot) a new instance.""" body = {"instance": { "name": name, "flavorRef": flavor_id }} datastore_obj = {} if volume: body["instance"]["volume"] = volume if databases: body["instance"]["databases"] = databases if users: body["instance"]["users"] = users if restorePoint: body["instance"]["restorePoint"] = restorePoint if availability_zone: body["instance"]["availability_zone"] = availability_zone if datastore: datastore_obj["type"] = datastore if datastore_version: datastore_obj["version"] = datastore_version if datastore_obj: body["instance"]["datastore"] = datastore_obj if nics: body["instance"]["nics"] = nics if configuration: body["instance"]["configuration"] = base.getid(configuration) if replica_of or slave_of: if slave_of: warnings.warn(_LW("The 'slave_of' argument is deprecated in " "favor of 'replica_of' and will be removed " "after the Trove liberty series is end of " "life."), category=DeprecationWarning) body["instance"]["replica_of"] = base.getid(replica_of) or slave_of if replica_count: body["instance"]["replica_count"] = replica_count if modules: body["instance"]["modules"] = self._get_module_list(modules) if locality: body["instance"]["locality"] = locality return self._create("/instances", body, "instance")
def schedule_create(self, instance, pattern, name, description=None, incremental=False, mistral_client=None): """Create a new schedule to backup the given instance. :param instance: instance to backup. :param: pattern: cron pattern for schedule. :param name: name for backup. :param description: (optional). :param incremental: flag for incremental backup (optional). :returns: :class:`Backups` """ if not mistral_client: mistral_client = self._get_mistral_client() inst_id = base.getid(instance) cron_name = str(uuid.uuid4()) wf_input = {"instance": inst_id, "name": name, "description": description, "incremental": incremental } cron_trigger = mistral_client.cron_triggers.create( cron_name, self.backup_create_workflow, pattern=pattern, workflow_input=wf_input) return self._build_schedule(cron_trigger, wf_input)
def get(self, configuration): """Get a specific configuration. :rtype: :class:`Configurations` """ return self._get("/configurations/%s" % base.getid(configuration), "configuration")
def create(self, name, instance, description=None, parent_id=None, backup=None, incremental=False): """Create a new backup from the given instance. :param name: name for backup. :param instance: instance to backup. :param description: (optional). :param parent_id: base for incremental backup (optional). :param incremental: flag to indicate incremental backup based on last backup :returns: :class:`Backups` """ body = { "backup": { "name": name, "incremental": int(incremental) } } if instance: body['backup']['instance'] = base.getid(instance) if backup: body["backup"]['backup'] = backup if description: body['backup']['description'] = description if parent_id: body['backup']['parent_id'] = parent_id return self._create("/backups", body, "backup")
def get(self, cluster): """Get a specific cluster. :rtype: :class:`Cluster` """ return self._get("/clusters/%s" % base.getid(cluster), "cluster")
def get(self, instance): """ Get the diagnostics of the guest on the instance. """ return self._get( "/mgmt/instances/%s/diagnostics" % base.getid(instance), "diagnostics")
def list(self, limit=None, marker=None, datastore=None): """Get a list of all modules.""" query_strings = None if datastore: query_strings = {"datastore": base.getid(datastore)} return self._paginated( "/modules", "modules", limit, marker, query_strings=query_strings)
def list(self, instance, limit=None, marker=None): """Get a list of all Users from the instance's Database. :rtype: list of :class:`User`. """ url = "/instances/%s/users" % base.getid(instance) return self._paginated(url, "users", limit, marker)
def get(self, flavor): """Get a specific flavor. :rtype: :class:`Flavor` """ return self._get("/flavors/%s" % base.getid(flavor), "flavor")
def get(self, backup): """Get a specific backup. :rtype: :class:`Backups` """ return self._get("/backups/%s" % base.getid(backup), "backup")
def schedule_create(self, instance, pattern, name, description=None, incremental=None, mistral_client=None): """Create a new schedule to backup the given instance. :param instance: instance to backup. :param: pattern: cron pattern for schedule. :param name: name for backup. :param description: (optional). :param incremental: flag for incremental backup (optional). :returns: :class:`Backups` """ if not mistral_client: mistral_client = self._get_mistral_client() inst_id = base.getid(instance) cron_name = str(uuid.uuid4()) wf_input = {"instance": inst_id, "name": name, "description": description, "incremental": incremental } cron_trigger = mistral_client.cron_triggers.create( cron_name, self.backup_create_workflow, pattern=pattern, workflow_input=wf_input) return self._build_schedule(cron_trigger, wf_input)
def backups(self, instance, limit=None, marker=None): """Get the list of backups for a specific instance. :rtype: list of :class:`Backups`. """ url = "/instances/%s/backups" % base.getid(instance) return self._paginated(url, "backups", limit, marker)
def edit(self, instance, configuration=None, name=None, detach_replica_source=False, remove_configuration=False): body = {"instance": {}} if configuration and remove_configuration: raise Exception("Cannot attach and detach configuration " "simultaneously.") if remove_configuration: body["instance"]["configuration"] = None if configuration is not None: body["instance"]["configuration"] = configuration if name is not None: body["instance"]["name"] = name if detach_replica_source: # TODO(glucas): Remove slave_of after updating trove # (see trove.instance.service.InstanceController#edit) body["instance"]["slave_of"] = None body["instance"]["replica_of"] = None url = "/instances/%s" % base.getid(instance) resp, body = self.api.client.patch(url, body=body) common.check_for_exceptions(resp, body, url)
def get(self, instance): """ Get a specific instances. :rtype: :class:`Instance` """ return self._get("/instances/%s" % base.getid(instance), "instance")
def get(self, security_group): """Get a specific security group. :rtype: :class:`SecurityGroup` """ return self._get("/security-groups/%s" % base.getid(security_group), "security_group")
def get(self, datastore): """ Get a specific datastore. :rtype: :class:`Datastore` """ return self._get("/datastores/%s" % base.getid(datastore), "datastore")
def create(self, name, instance, description=None, parent_id=None, incremental=False): """Create a new backup from the given instance. :param name: name for backup. :param instance: instance to backup. :param description: (optional). :param parent_id: base for incremental backup (optional). :param incremental: flag to indicate incremental backup based on last backup :returns: :class:`Backups` """ body = {"backup": {"name": name, "incremental": int(incremental)}} if instance: body['backup']['instance'] = base.getid(instance) if description: body['backup']['description'] = description if parent_id: body['backup']['parent_id'] = parent_id return self._create("/backups", body, "backup")
def get(self, datastore): """Get a specific datastore. :rtype: :class:`Datastore` """ return self._get("/datastores/%s" % base.getid(datastore), "datastore")
def change_passwords(self, instance, users): """Change the password for one or more users.""" instance_id = base.getid(instance) user_dict = {"users": users} url = "/instances/%s/users" % instance_id resp, body = self.api.client.put(url, body=user_dict) check_for_exceptions(resp, body)
def get(self, flavor): """ Get a specific flavor. :rtype: :class:`Flavor` """ return self._get("/flavors/%s" % base.getid(flavor), "flavor")
def root_enabled_history(self, instance): """Get root access history of one instance.""" url = "/mgmt/instances/%s/root" % base.getid(instance) resp, body = self.api.client.get(url) if not body: raise Exception("Call to " + url + " did not return a body.") return RootHistory(self, body['root_history'])
def change_passwords(self, instance, users): """Change the password for one or more users.""" instance_id = base.getid(instance) user_dict = {"users": users} url = "/instances/%s/users" % instance_id resp, body = self.api.client.put(url, body=user_dict) common.check_for_exceptions(resp, body, url)
def _log_action(self, instance, log_name, enable=None, disable=None, publish=None, discard=None): """Perform action on guest log. :param instance: The :class:`Instance` (or its ID) of the database instance to get the log for. :param log_name: The name of <log> to publish :param enable: Turn on <log> :param disable: Turn off <log> :param publish: Publish log to associated container :param discard: Delete the associated container :rtype: List of :class:`DatastoreLog`. """ body = {"name": log_name} if enable: body.update({'enable': int(enable)}) if disable: body.update({'disable': int(disable)}) if publish: body.update({'publish': int(publish)}) if discard: body.update({'discard': int(discard)}) url = "/instances/%s/log" % base.getid(instance) resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) return DatastoreLog(self, body['log'], loaded=True)
def _get_module_list(self, modules): """Build a list of module ids.""" module_list = [] for module in modules: module_info = {'id': base.getid(module)} module_list.append(module_info) return module_list
def configuration(self, instance): """Get a configuration on instances. :rtype: :class:`Instance` """ return self._get("/instances/%s/configuration" % base.getid(instance), "instance")
def backups(self, instance): """ Get the list of backups for a specific instance. :rtype: list of :class:`Backups`. """ return self._list("/instances/%s/backups" % base.getid(instance), "backups")
def upgrade(self, instance, datastore_version): """Upgrades an instance with a new datastore version.""" body = {"instance": {"datastore_version": datastore_version}} url = "/instances/%s" % base.getid(instance) resp, body = self.api.client.patch(url, body=body) common.check_for_exceptions(resp, body, url)
def get(self, volume_type): """Get a specific volume-type. :rtype: :class:`VolumeType` """ return self._get("/volume-types/%s" % base.getid(volume_type), "volume_type")
def delete(self, configuration): """Delete the specified configuration. :param configuration: The configuration id to delete """ url = "/configurations/%s" % base.getid(configuration) resp, body = self.api.client.delete(url) common.check_for_exceptions(resp, body, url)
def module_apply(self, instance, modules): """Apply modules to an instance.""" url = "/instances/%s/modules" % base.getid(instance) body = {"modules": self._get_module_list(modules)} resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) return [core_modules.Module(self, module, loaded=True) for module in body['modules']]
def instances(self, configuration, limit=None, marker=None): """Get a list of instances on a configuration. :rtype: :class:`Configurations` """ return self._paginated("/configurations/%s/instances" % base.getid(configuration), "instances", limit, marker)
def get(self, instance, username, hostname=None): """Get a single User from the instance's Database. :rtype: :class:`User`. """ user = common.quote_user_host(username, hostname) url = "/instances/%s/users/%s" % (base.getid(instance), user) return self._get(url, "user")
def _action(self, instance, body): """Perform a server "action" -- reboot/rebuild/resize/etc.""" url = "/instances/%s/action" % base.getid(instance) resp, body = self.api.client.post(url, body=body) common.check_for_exceptions(resp, body, url) if body: return self.resource_class(self, body, loaded=True) return body
def delete(self, instance): """Delete the specified instance. :param instance: A reference to the instance to delete """ url = "/instances/%s" % base.getid(instance) resp, body = self.api.client.delete(url) common.check_for_exceptions(resp, body, url)
def list(self, instance, limit=None, marker=None): """ Get a list of all Databases from the instance. :rtype: list of :class:`Database`. """ return self._list("/instances/%s/databases" % base.getid(instance), "databases", limit, marker)
def show(self, instance): """Get details of one instance. :rtype: :class:`Instance`. """ return self._get("/mgmt/instances/%s" % base.getid(instance), 'instance')