def modify(self, name=None, data=None, ttl=None): """Modify this Record's properties. :param name: Modify the Record's name. :type ttl: str :param data: Modify the Record's data. :type data: str :param ttl: Modify the Record's time-to-live (TTL). :type ttl: int :returns: A list of Records. :rtype: A list of :class:`Record` .. versionadded:: 0.1 """ assert 'id' in self assert 'domain_id' in self data = {} if name is not None: data['name'] = name if data is not None: data['data'] = data if ttl is not None: data['ttl'] = int(ttl) data = json.dumps(data) url = '/'.join([get_url('clouddns'), 'domains', str(self['domain_id']), 'records', str(self['id'])]) handle_request('put', url, data) if name is not None: self['name'] = name if data is not None: self['data'] = data if ttl is not None: self['ttl'] = int(ttl) return self
def resize(self, flavor=None, size=None): """Resize the memory and/or volume of the instance. This operation changes the memory and/or volume size of the instance, assuming a valid Flavor is provided. Restarts MySQL in the process. :param flavor: New Flavor (memory size) ofr the Instance. :type flavor: :class:`Flavor` :param size: New volume size Iin GBs) for Instance, 1 to 25. :type size: int .. versionadded:: 0.2 """ assert 'id' in self, "Missing Instance ID" if isinstance(flavor, Flavor): flavor = flavor.ref data = {'resize': {}} if flavor is not None: data['resize']['flavorRef'] = flavor if size is not None: data['resize']['volume'] = {'size': int(size)} data = json.dumps(data) url = '/'.join([get_url('clouddatabases'), 'instances', str(self['id']), 'action']) handle_request('post', url, data)
def modify(self, ttl=None, email_address=None, comment=None): """Modify this Domain's properties. :param ttl: Time-To-Live (TTL0 in seconds :type ttl: int :param email_address: E-mail address associated with Domain :type email_address: str :param comment: A comment or note about this Domain :type comment: str :returns: A :class:`Domain` .. versionadded:: 0.1 """ assert 'id' in self data = {} if ttl is not None: data['ttl'] = int(ttl) if email_address is not None: data['emailAddress'] = email_address if comment is not None: data['comment'] = comment data = json.dumps(data) url = '/'.join([get_url('clouddns'), 'domains', str(self['id'])]) handle_request('put', url, data) if ttl is not None: self['ttl'] = int(ttl) if email_address is not None: self['email_address'] = email_address if comment is not None: self['comment'] = comment return self
def volume_detach(self, volumeId): """Detach the volume specified by volume_id from this NextGenServer. """ assert 'id' in self url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id']), 'os-volume_attachments', str(volumeId)]) handle_request('delete', url)
def delete(self): """Delete this Shared IP Group. .. versionadded:: 0.1 """ assert 'id' in self url = '/'.join([get_url('cloudservers'), 'shared_ip_groups', str(self['id'])]) handle_request('delete', url)
def unshare_ip(self, address): """Unshare this Server's IP .. versionadded:: 0.1 """ assert 'id' in self url = '/'.join([get_url('cloudservers'), 'servers', str(self['id']), 'ips', 'public', address]) handle_request('delete', url)
def revert_resize(self): """Revert an unsuccessful resize operation .. versionadded:: 0.3 """ assert 'id' in self data = json.dumps({'revertResize': None}) url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id']), 'action']) handle_request('post', url, data)
def confirm_resize(self): """Confirm a successful resize operation .. versionadded:: 0.1 """ assert 'id' in self data = json.dumps({'confirmResize': None}) url = '/'.join([get_url('cloudservers'), 'servers', str(self['id']), 'action']) handle_request('post', url, data)
def remove_record(self, record): """Remove a Record from this Domain. :param record: A Record or ``id`` for the Record to remove. :type record: int or :class:`REcord` .. versionadded:: 0.1 """ assert 'id' in self record = record.id if isinstance(record, Record) else int(record) url = '/'.join([get_url('clouddns'), 'domains', str(self['id']), 'records', str(record)]) handle_request('delete', url)
def backup_schedule(self): """Disable a backup schedule for this Server >>> server = vaporize.servers.Server.get(...) >>> del server.backup_schedule .. versionadded:: 0.1 """ assert 'id' in self url = '/'.join([get_url('cloudservers'), 'servers', str(self['id']), 'backup_schedule']) handle_request('delete', url) del self['backup_schedule']
def rebuild(self, name, image, flavor, adminpass, accessIPv4=None, accessIPv6=None, metadata={}, files={}, diskConfig='AUTO'): """Rebuild this NextGenServer using a specified NextGenImage :param image: The NextGenImage or ``id`` :type image: int or :class:`NextGenImage` :param flavor: The NextGenFlavor or ``id`` :type image: int or :class:`NextGenFlavor` :param adminpass: Admin Password. :param accessIPv4: IPv4 access address :type type: str :param accessIPv6: IPv6 access address :type type: str :param metadata: key/value pairs :type type: dict :param files: path,contents dict :type type: dict :param diskConfig: OS-DCF:diskConfig AUTO or MANUAL :type type: str .. versionadded:: 0.3 """ assert 'id' in self, "id is missing" assert 'name' in self or len(name) > 0, "name is missing" assert len(adminpass) >= 8, "Admin password must be >= 8 chars long" assert diskConfig in ['AUTO', 'MANUAL'], ("diskConfig must be" "'AUTO' or 'MANUAL'") if name: self['name'] = name if isinstance(image, NextGenImage): image = image.id if isinstance(flavor, NextGenFlavor): flavor = flavor.id data = {'rebuild':{ 'name': str(self['name']), 'imageRef': str(image), 'flavorRef': str(flavor), 'adminPass': str(adminpass), 'OS-DCF:diskConfig': str(diskConfig) }} if accessIPv4 is not None: data['rebuild']['accessIPv4'] = str(accessIPv4) if accessIPv6 is not None: data['rebuild']['accessIPv6'] = str(accessIPv6) if isinstance(files, dict): for path, contents in list(files.items()): data['rebuild']['personality'].append({'path': path, 'contents': contents}) data = json.dumps(data) url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id']), 'action']) handle_request('post', url, data)
def reboot(self, type='SOFT'): """Perform a soft/hard reboot on this NextGenServer. :param type: A reboot type (``SOFT`` or ``HARD``). :type type: str .. versionadded:: 0.3 """ assert 'id' in self, "Missing NextGenServer ID" assert type in ['SOFT', 'HARD'], "Reboot type must be 'SOFT' or 'HARD'" data = json.dumps({'reboot': {'type': type}}) url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id']), 'action']) handle_request('post', url, data)
def restart(self): """Restart the database service on the instance. The restart operation will restart only the MySQL Instance. Restarting MySQL will erase any dynamic configuration settings that you have made within MySQL. .. versionadded:: 0.2 """ assert 'id' in self data = json.dumps({'restart': {}}) url = '/'.join([get_url('clouddatabases'), 'instances', str(self['id']), 'action']) handle_request('post', url, dataa)
def change_admin_pass(self, password): """Change admin password. :param password: Admin Password. :type type: str """ assert len(password) >= 8, "Admin password must be >= 8 chars long" assert 'id' in self url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id']), 'action']) data = json.dumps({ "changePassword": { "adminPass" : str(password)}}) handle_request('post', url, data)
def delete(self): """Delete this NextGenServer. .. warning:: There is no confirmation step for this operation. When you delete a server it is permanent. If in doubt, create a backup image (:func:`vaporize.images.create`) first before deleting. .. versionadded:: 0.1 """ assert 'id' in self url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id'])]) handle_request('delete', url)
def update_server(self, name=None, accessIPv4=None, accessIPv6=None): """Update this NextGenServer's name or ip addresses. :param name: Change the NextGenServer's name :type name: str :param accessIPv4: IPv4 access address :type name: str :param accessIPv6: IPv6 access address :type name: str :returns: A modified CloudNextGenServers NextGenServer. :rtype: :class:`NextGenServer` .. versionadded:: 0.3 """ assert 'id' in self data = {'server': {}} if name is not None: data['server']['name'] = name if addressIPv4 is not None: data['server']['addressIPv4'] = addressIPv4 if addressIPv6 is not None: data['server']['addressIPv6'] = addressIPv6 data = json.dumps(data) url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id'])]) response = handle_request('put', url, data=data) if response: if name is not None: self['name'] = name return self
def rebuild(self, image): """Rebuild this Server using a specified Image :param image: The Image or ``id`` :type image: int or :class:`Image` .. versionadded:: 0.1 """ assert 'id' in self if isinstance(image, Image): image = image.id image = int(image) data = json.dumps({'rebuild': {'imageId': int(image)}}) url = '/'.join([get_url('cloudservers'), 'servers', str(self['id']), 'action']) handle_request('post', url, data)
def create(cls, size, name=None, description=None, snapshot=None, volume_type=None): """Create a CloudBlockStorage Volume. :param size: Volume size in GB (min. 100GB max. 1TB). :type size: int :param name: Name of Volume. :type name: str :param description: Description of Volume. :type description: str :param snapshot: Snapshot_ID or :class:`Snapshot` of the volume restore. :type snapshot: int or :class:`Snapshot` :param volume_type: Volume Type, either ``SATA`` or ``SSD``. :type volume_type: str or :class:`VolumeType` """ assert 100 <= int(size) <= 1000 data = {'volume': {'size': int(size)}} if name: data['volume']['display_name'] = str(display_name) if description: data['volume']['display_descrition'] = str(description) if snapshot: if isinstance(snapshot, Snapshot): snapshot = snapshot.id data['volume']['snapshot_id'] = int(snapshot) if volume_type: if isinstance(volume_type, VolumeType): volume_type = volume_type.name data['volume']['volume_type'] = str(volume_type) data = json.dumps(data) url = '/'.join([get_url('cloudblockstorage'), 'volumes']) return handle_request('post', url, data, cls, 'volume')
def add_records(self, *records): """Add Records to a Domain. >>> domain = vaporize.domains.create(...) >>> record1 = vaporize.domains.Record.create(....) >>> record2 = vaporize.domains.Record.create(...) >>> domain.add_recrods(record1, record2) :param records: Records you wish to add to this Domain. :type records: :class:`Record` :returns: A list of Records :rtype: :class:`Record` .. versionadded:: 0.1 """ assert 'id' in self data = {'records': []} for record in records: if isinstance(record, Record): data['records'].append({ 'name': record.name, 'type': record.type, 'data': record.data, 'ttl': record.ttl, 'priority': record.priority, 'comment': record.comment }) data = json.dumps(data) url = '/'.join([get_url('clouddns'), 'domains', str(self['id']), 'records']) self['records'] = handle_request('post', url, data, Record, 'records', domain_id=self['id']) return self['records']
def create(cls, name, image, flavor, metadata=None, files=None): """Create a CloudServers Server :param name: A Server's name :type name: str :param image: An Image or ``id`` :type image: int or :class:`Image` :param flavor: A Flavor or ``id`` :type flavor: int or :class:`Flavor` :param metadata: Optional meta data to include with Server :type metadata: dict :param files: A list of files to load on Server :type files: dict :returns: A shiny new CloudServers Server. :rtype: :class:`Server` .. versionadded:: 0.1 """ if isinstance(image, Image): image = image.id image = int(image) if isinstance(flavor, Flavor): flavor = flavor.id flavor = int(flavor) data = {'server': {'name': name, 'imageId': image, 'flavorId': flavor, 'metadata': metadata or {}, 'personality': []}} if isinstance(files, dict): for path, contents in list(files.items()): data['personality'].append({'path': path, 'contents': contents}) data = json.dumps(data) url = '/'.join([get_url('cloudservers'), 'servers']) return handle_request('post', url, data, cls, 'server')
def delete(self, subdomains=False): """Delete this Record. .. warning:: There is no confirmation step to this operation. Deleting this record is permanent. If in doubt you can export a copy of the DNS zone (:func:`vaporize.domains.Domain.export_zone`) before deleting. .. versionadded:: 0.1 """ assert 'id' in self assert 'domain_id' in self url = '/'.join([get_url('clouddns'), 'domains', str(self['domain_id']), 'records', str(self['id'])]) handle_request('delete', url)
def resize(self, flavor): """Resize this Server to a specific Flavor size :param flavor: The Flavor or ``id`` :type flavor: int or :class:`Flavor` .. versionadded:: 0.1 """ assert 'id' in self if isinstance(flavor, Flavor): flavor = flavor.id flavor = int(flavor) data = json.dumps({'resize': {'flavorId': flavor}}) url = '/'.join([get_url('cloudservers'), 'servers', str(self['id']), 'action']) handle_request('post', url, data)
def list(cls): """Returns a list of Volumes. """ url = [get_url('cloudblockstorage'), 'volumes'] url = '/'.join(url) return handle_request('get', url, wrapper=cls, container='volumes')
def create(cls, volume, force=False, name=None, description=None): """Create a CloudBlockStorage Snapshot. :param volume: Volume_ID or :class:`Volume` to snapshot. :type volume: int or :class:`Volume` :param force: Force volume snapshot. :type force: bool :param name: Display name of volume. :type name: str :param description: Display description of volume. :type description: str """ assert volume if isinstance(volume, Volume): volume = volume.id data = {'snapshot': {'volume_id': str(volume)}} if force: data['snapshot']['force'] = bool(force) if name: data['snapshot']['display_name'] = str(name) if description: data['snapshot']['display_descrition'] = str(description) data = json.dumps(data) url = '/'.join([get_url('cloudblockstorage'), 'snapshots']) return handle_request('post', url, data, cls, 'snapshot')
def create(cls, size, display_description='', display_name='', snapshot_id='', volume_type=''): """Returns info about :param volume_type_id. :param size: volume size in GB (min. 100GB max. 1TB). :type : str :param display_description: display description. :type : str :param display_name: display name. :type : str :param snapshot_id: snapshot_id of the volume to be restored. :type : str :param volume_type: volume type. :type : str """ assert 100 <= int(size) <= 1000 data = { 'volume': { 'size': int(size)}} if display_description: data['volume']['display_descrition'] = str(display_description) if display_name: data['volume']['display_name'] = str(display_name) if snapshot_id: data['volume']['snapshot_id'] = str(snapshot_id) if volume_type: data['volume']['volume_type'] = str(volume_type) data = json.dumps(data) url = '/'.join([get_url('cloudblockstorage'), 'volumes']) return handle_request('post', url, data, cls, 'volume')
def modify(self, name=None, password=None): """Modify this Server's name or root password. :param name: Change the Server's name :type name: str :param password: Change the Server's root password :type password: str :returns: A modified CloudServers Server. :rtype: :class:`Server` .. versionadded:: 0.1 """ assert 'id' in self data = {'server': {}} if name is not None: data['server']['name'] = name if password is not None: data['server']['adminPass'] = password data = json.dumps(data) url = '/'.join([get_url('cloudservers'), 'servers', str(self['id'])]) response = handle_request('put', url, data=data) if response: if name is not None: self['name'] = name return self
def delete(self): """Delete this NextGenImage. .. note:: You can only delete NextGenImages you create. .. warning:: There is not confirmation step for this operation. Deleting an image is permanent. .. versionadded:: 0.3 """ assert 'id' in self url = '/'.join([get_url('cloudserversopenstack'), 'images', str(self['id'])]) handle_request('delete', url)
def delete(self): """Delete this CloudDatabases Instance. This operation deletes the specified database instance, including any associated data. .. warning:: There is not confirmation step for this operation. Deleting an image is permanent. .. versionadded:: 0.2 """ assert 'id' in self, "Missing Instance ID" url = '/'.join([get_url('clouddatabases'), 'instances', str(self['id'])]) handle_request('delete', url)
def list(cls): """Returns a list of Snapshots. :returns: A list of :class:`Snapshot` """ url = [get_url('cloudblockstorage'), 'snapshots'] url = '/'.join(url) return handle_request('get', url, wrapper=cls, container='snapshots')
def ips(self): """Returns a list of ip addresses attached to the NextGenServer instance. """ assert 'id' in self url = '/'.join([get_url('cloudserversopenstack'), 'servers', str(self['id']), 'ips']) return handle_request('get', url, container='addresses')