Example #1
0
    def share_ip(self, server, ipgroup=None, address=None, configure=True):
        """
        Share an IP address from the given IP group onto a server.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param ipgroup: The :class:`IPGroup` that the given address belongs to.
                        DEPRICATED in X7
        :param address: The IP address to share.
        :param configure: If ``True``, the server will be automatically
                         configured to use this IP. I don't know why you'd
                         want this to be ``False``.
        """
        # to make ipgroup optional without making address optional or changing the
        # order of the parameters in the function signature
        if address == None:
            raise TypeError("Address is required")

        if 'IPGROUPS' in API_OPTIONS[self.api.config.cloud_api]:
            if ipgroup == None:
                raise TypeError("IPGroup is required")
            server = base.getid(server)
            ipgroup = base.getid(ipgroup)
            body = {'shareIp': {'sharedIpGroupId': ipgroup, 'configureServer': configure}}
            self._update("/servers/%s/ips/public/%s" % (server, address), body)
        else:
            #TODO: Jwilcox(2011-04-18) share ip without ipgroup x7 1.1 api
            pass
Example #2
0
    def share_ip(self, server, ipgroup=None, address=None, configure=True):
        """
        Share an IP address from the given IP group onto a server.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param ipgroup: The :class:`IPGroup` that the given address belongs to.
                        DEPRICATED in X7
        :param address: The IP address to share.
        :param configure: If ``True``, the server will be automatically
                         configured to use this IP. I don't know why you'd
                         want this to be ``False``.
        """
        # to make ipgroup optional without making address optional or changing the
        # order of the parameters in the function signature
        if address == None:
            raise TypeError("Address is required")

        if 'IPGROUPS' in API_OPTIONS[self.api.config.cloud_api]:
            if ipgroup == None:
                raise TypeError("IPGroup is required")
            server = base.getid(server)
            ipgroup = base.getid(ipgroup)
            body = {
                'shareIp': {
                    'sharedIpGroupId': ipgroup,
                    'configureServer': configure
                }
            }
            self._update("/servers/%s/ips/public/%s" % (server, address), body)
        else:
            #TODO: Jwilcox(2011-04-18) share ip without ipgroup x7 1.1 api
            pass
Example #3
0
    def create(self, name, image, flavor, ipgroup=None, meta=None, files=None):
        """
        Create (boot) a new server.

        :param name: Something to name the server.
        :param image: The :class:`Image` to boot with.
        :param flavor: The :class:`Flavor` to boot onto.
        :param ipgroup: An initial :class:`IPGroup` for this server.
        :param meta: A dict of arbitrary key/value metadata to store for this
                     server. A maximum of five entries is allowed, and both
                     keys and values must be 255 characters or less.
        :param files: A dict of files to overrwrite on the server upon boot.
                      Keys are file names (i.e. ``/etc/passwd``) and values
                      are the file contents (either as a string or as a
                      file-like object). A maximum of five entries is allowed,
                      and each file must be 10k or less.

        There's a bunch more info about how a server boots in Rackspace's
        official API docs, page 23.
        """
        body = {
            "server": {
                "name": name,
                "imageId": base.getid(image),
                "flavorId": base.getid(flavor),
            }
        }
        if ipgroup:
            body["server"]["sharedIpGroupId"] = base.getid(ipgroup)
        if meta:
            body["server"]["metadata"] = meta

        # Files are a slight bit tricky. They're passed in a "personality"
        # list to the POST. Each item is a dict giving a file name and the
        # base64-encoded contents of the file. We want to allow passing
        # either an open file *or* some contents as files here.
        if files:
            personality = body['server']['personality'] = []
            for filepath, file_or_string in files.items():
                if hasattr(file_or_string, 'read'):
                    data = file_or_string.read()
                else:
                    data = file_or_string
                personality.append({
                    'path': filepath,
                    'contents': data.encode('base64'),
                })

        return self._create("/servers", body, "server")
Example #4
0
 def delete(self, group):
     """
     Delete a group.
             
     :param group: The :class:`IPGroup` (or its ID) to delete.
     """
     self._delete("/shared_ip_groups/%s" % base.getid(group))
Example #5
0
 def delete(self, group):
     """
     Delete a group.
             
     :param group: The :class:`IPGroup` (or its ID) to delete.
     """
     self._delete("/shared_ip_groups/%s" % base.getid(group))
Example #6
0
    def create(self, name, image, flavor, ipgroup=None, meta=None, files=None):
        """
        Create (boot) a new server.

        :param name: Something to name the server.
        :param image: The :class:`Image` to boot with.
        :param flavor: The :class:`Flavor` to boot onto.
        :param ipgroup: An initial :class:`IPGroup` for this server.
        :param meta: A dict of arbitrary key/value metadata to store for this
                     server. A maximum of five entries is allowed, and both
                     keys and values must be 255 characters or less.
        :param files: A dict of files to overrwrite on the server upon boot.
                      Keys are file names (i.e. ``/etc/passwd``) and values
                      are the file contents (either as a string or as a
                      file-like object). A maximum of five entries is allowed,
                      and each file must be 10k or less.

        There's a bunch more info about how a server boots in Rackspace's
        official API docs, page 23.
        """
        body = {"server": {
            "name": name,
            "imageId": base.getid(image),
            "flavorId": base.getid(flavor),
        }}
        if ipgroup:
            body["server"]["sharedIpGroupId"] = base.getid(ipgroup)
        if meta:
            body["server"]["metadata"] = meta

        # Files are a slight bit tricky. They're passed in a "personality"
        # list to the POST. Each item is a dict giving a file name and the
        # base64-encoded contents of the file. We want to allow passing
        # either an open file *or* some contents as files here.
        if files:
            personality = body['server']['personality'] = []
            for filepath, file_or_string in files.items():
                if hasattr(file_or_string, 'read'):
                    data = file_or_string.read()
                else:
                    data = file_or_string
                personality.append({
                    'path': filepath,
                    'contents': data.encode('base64'),
                })

        return self._create("/servers", body, "server")
Example #7
0
    def get(self, server):
        """
        Get a server.

        :param server: ID of the :class:`Server` to get.
        :rtype: :class:`Server`
        """
        return self._get("/servers/%s" % base.getid(server), "server")
Example #8
0
 def delete(self, server):
     """
     Remove the scheduled backup for `server`.
     
     :arg server: The server (or its ID).
     """
     s = base.getid(server)
     self._delete('/servers/%s/backup_schedule' % s)
Example #9
0
 def get(self, group):
     """
     Get an IP group.
     
     :param group: ID of the image to get.
     :rtype: :class:`IPGroup`
     """
     return self._get("/shared_ip_groups/%s" % base.getid(group), "sharedIpGroup")
Example #10
0
 def get(self, image):
     """
     Get an image.
     
     :param image: The ID of the image to get.
     :rtype: :class:`Image`
     """
     return self._get("/images/%s" % base.getid(image), "image")
Example #11
0
 def delete(self, server):
     """
     Remove the scheduled backup for `server`.
     
     :arg server: The server (or its ID).
     """
     s = base.getid(server)
     self._delete('/servers/%s/backup_schedule' % s)
Example #12
0
 def get(self, image):
     """
     Get an image.
     
     :param image: The ID of the image to get.
     :rtype: :class:`Image`
     """
     return self._get("/images/%s" % base.getid(image), "image")
Example #13
0
 def get(self, flavor):
     """
     Get a specific flavor.
     
     :param flavor: The ID of the :class:`Flavor` to get.
     :rtype: :class:`Flavor`
     """
     return self._get("/flavors/%s" % base.getid(flavor), "flavor")
Example #14
0
 def get(self, flavor):
     """
     Get a specific flavor.
     
     :param flavor: The ID of the :class:`Flavor` to get.
     :rtype: :class:`Flavor`
     """
     return self._get("/flavors/%s" % base.getid(flavor), "flavor")
Example #15
0
    def rebuild(self, server, image):
        """
        Rebuild -- shut down and then re-image -- a server.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param image: the :class:`Image` (or its ID) to re-image with.
        """
        self._action('rebuild', server, {'imageId': base.getid(image)})
Example #16
0
    def rebuild(self, server, image):
        """
        Rebuild -- shut down and then re-image -- a server.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param image: the :class:`Image` (or its ID) to re-image with.
        """
        self._action('rebuild', server, {'imageId': base.getid(image)})
Example #17
0
    def get(self, server):
        """
        Get a server.

        :param server: ID of the :class:`Server` to get.
        :rtype: :class:`Server`
        """
        return self._get("/servers/%s" % base.getid(server), "server")
Example #18
0
 def get(self, group):
     """
     Get an IP group.
     
     :param group: ID of the image to get.
     :rtype: :class:`IPGroup`
     """
     return self._get("/shared_ip_groups/%s" % base.getid(group),
                      "sharedIpGroup")
Example #19
0
    def unshare_ip(self, server, address):
        """
        Stop sharing the given address.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param address: The IP address to stop sharing.
        """
        server = base.getid(server)
        self._delete("/servers/%s/ips/public/%s" % (server, address))
Example #20
0
    def unshare_ip(self, server, address):
        """
        Stop sharing the given address.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param address: The IP address to stop sharing.
        """
        server = base.getid(server)
        self._delete("/servers/%s/ips/public/%s" % (server, address))
Example #21
0
 def delete(self, image):
     """
     Delete an image.
     
     It should go without saying that you can't delete an image 
     that you didn't create.
     
     :param image: The :class:`Image` (or its ID) to delete.
     """
     self._delete("/images/%s" % base.getid(image))
Example #22
0
 def create(self, name, server):
     """
     Create a new image by snapshotting a running :class:`Server`
     
     :param name: An (arbitrary) name for the new image.
     :param server: The :class:`Server` (or its ID) to make a snapshot of.
     :rtype: :class:`Image`
     """
     data = {"image": {"serverId": base.getid(server), "name": name}}
     return self._create("/images", data, "image")
Example #23
0
 def create(self, name, server):
     """
     Create a new image by snapshotting a running :class:`Server`
     
     :param name: An (arbitrary) name for the new image.
     :param server: The :class:`Server` (or its ID) to make a snapshot of.
     :rtype: :class:`Image`
     """
     data = {"image": {"serverId": base.getid(server), "name": name}}
     return self._create("/images", data, "image")
Example #24
0
 def delete(self, image):
     """
     Delete an image.
     
     It should go without saying that you can't delete an image 
     that you didn't create.
     
     :param image: The :class:`Image` (or its ID) to delete.
     """
     self._delete("/images/%s" % base.getid(image))
Example #25
0
 def get(self, server):
     """
     Get the current backup schedule for a server.
     
     :arg server: The server (or its ID).
     :rtype: :class:`BackupSchedule`
     """
     s = base.getid(server)
     schedule = self._get('/servers/%s/backup_schedule' % s, 'backupSchedule')
     schedule.server = server
     return schedule
Example #26
0
 def create(self, name, server=None):
     """
     Create a new :class:`IPGroup`
     
     :param name: An (arbitrary) name for the new image.
     :param server: A :class:`Server` (or its ID) to make a member of this group.
     :rtype: :class:`IPGroup`
     """
     data = {"sharedIpGroup": {"name": name}}
     if server:
         data['sharedIpGroup']['server'] = base.getid(server)
     return self._create('/shared_ip_groups', data, "sharedIpGroup")
Example #27
0
 def create(self, name, server=None):
     """
     Create a new :class:`IPGroup`
     
     :param name: An (arbitrary) name for the new image.
     :param server: A :class:`Server` (or its ID) to make a member of this group.
     :rtype: :class:`IPGroup`
     """
     data = {"sharedIpGroup": {"name": name}}
     if server:
         data['sharedIpGroup']['server'] = base.getid(server)
     return self._create('/shared_ip_groups', data, "sharedIpGroup")
Example #28
0
 def get(self, server):
     """
     Get the current backup schedule for a server.
     
     :arg server: The server (or its ID).
     :rtype: :class:`BackupSchedule`
     """
     s = base.getid(server)
     schedule = self._get('/servers/%s/backup_schedule' % s,
                          'backupSchedule')
     schedule.server = server
     return schedule
Example #29
0
    def resize(self, server, flavor):
        """
        Resize a server's resources.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param flavor: the :class:`Flavor` (or its ID) to resize to.

        Until a resize event is confirmed with :meth:`confirm_resize`, the old
        server will be kept around and you'll be able to roll back to the old
        flavor quickly with :meth:`revert_resize`. All resizes are
        automatically confirmed after 24 hours.
        """
        self._action('resize', server, {'flavorId': base.getid(flavor)})
Example #30
0
    def resize(self, server, flavor):
        """
        Resize a server's resources.

        :param server: The :class:`Server` (or its ID) to share onto.
        :param flavor: the :class:`Flavor` (or its ID) to resize to.

        Until a resize event is confirmed with :meth:`confirm_resize`, the old
        server will be kept around and you'll be able to roll back to the old
        flavor quickly with :meth:`revert_resize`. All resizes are
        automatically confirmed after 24 hours.
        """
        self._action('resize', server, {'flavorId': base.getid(flavor)})
Example #31
0
 def create(self, server, enabled=True, weekly=BACKUP_WEEKLY_DISABLED, daily=BACKUP_DAILY_DISABLED):
     """
     Create or update the backup schedule for the given server.
     
     :arg server: The server (or its ID).
     :arg enabled: boolean; should this schedule be enabled?
     :arg weekly: Run a weekly backup on this day (one of the `BACKUP_WEEKLY_*` constants)
     :arg daily: Run a daily backup at this time (one of the `BACKUP_DAILY_*` constants)
     """
     s = base.getid(server)
     body = {'backupSchedule': {
         'enabled': enabled, 'weekly': weekly, 'daily': daily
     }}
     self.api.connection.post('/servers/%s/backup_schedule' % s, body=body)
Example #32
0
    def update(self, server, name=None, password=None):
        """
        Update the name or the password for a server.

        :param server: The :class:`Server` (or its ID) to update.
        :param name: Update the server's name.
        :param password: Update the root password.
        """

        if name is None and password is None:
            return
        body = {"server": {}}
        if name:
            body["server"]["name"] = name
        if password:
            body["server"]["adminPass"] = password
        self._update("/servers/%s" % base.getid(server), body)
Example #33
0
    def update(self, server, name=None, password=None):
        """
        Update the name or the password for a server.

        :param server: The :class:`Server` (or its ID) to update.
        :param name: Update the server's name.
        :param password: Update the root password.
        """

        if name is None and password is None:
            return
        body = {"server": {}}
        if name:
            body["server"]["name"] = name
        if password:
            body["server"]["adminPass"] = password
        self._update("/servers/%s" % base.getid(server), body)
Example #34
0
 def create(self,
            server,
            enabled=True,
            weekly=BACKUP_WEEKLY_DISABLED,
            daily=BACKUP_DAILY_DISABLED):
     """
     Create or update the backup schedule for the given server.
     
     :arg server: The server (or its ID).
     :arg enabled: boolean; should this schedule be enabled?
     :arg weekly: Run a weekly backup on this day (one of the `BACKUP_WEEKLY_*` constants)
     :arg daily: Run a daily backup at this time (one of the `BACKUP_DAILY_*` constants)
     """
     s = base.getid(server)
     body = {
         'backupSchedule': {
             'enabled': enabled,
             'weekly': weekly,
             'daily': daily
         }
     }
     self.api.connection.post('/servers/%s/backup_schedule' % s, body=body)
Example #35
0
 def _action(self, action, server, info=None):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     self.api.connection.post('/servers/%s/action' % base.getid(server), body={action: info})
Example #36
0
    def create(self,
               name,
               image,
               flavor,
               ipgroup=None,
               meta=None,
               files=None,
               key_name=None,
               user_data=None,
               security_groups=None):
        """
        Create (boot) a new server.

        :param name: Something to name the server.
        :param image: The :class:`Image` to boot with.
        :param flavor: The :class:`Flavor` to boot onto.
        :param ipgroup: An initial :class:`IPGroup` for this server.
        :param key_name: Name of keypair that will be used for instance auth
        :param user_data: User supplied instance metadata
        :param meta: A dict of arbitrary key/value metadata to store for this
                     server. A maximum of five entries is allowed, and both
                     keys and values must be 255 characters or less.
        :param files: A dict of files to overrwrite on the server upon boot.
                      Keys are file names (i.e. ``/etc/passwd``) and values
                      are the file contents (either as a string or as a
                      file-like object). A maximum of five entries is allowed,
                      and each file must be 10k or less.

        There's a bunch more info about how a server boots in Rackspace's
        official API docs, page 23.
        """
        def get_href(link_list):
            for l in link_list:
                if l.get('type') == 'application/json':
                    return l['href']
                if l.get('rel') == 'self':
                    return l['href']
            return None

        # NOTE(vish): Split below is because compute is passing back a
        #             compute href but expects a tank href. Just passing
        #             the id (part after last /) uses the default tank.
        body = {
            "server": {
                "name": name,
                "imageRef": image['id'],
                "flavorRef": get_href(flavor.links),
            }
        }
        if ipgroup:
            body["server"]["sharedIpGroupId"] = base.getid(ipgroup)
        if meta:
            body["server"]["metadata"] = meta
        if user_data:
            body["server"]["user_data"] = base64.b64encode(user_data)
        if key_name:
            body["server"]["key_name"] = key_name
        if security_groups:
            body["server"]["security_groups"] = ','.join(security_groups)

        # Files are a slight bit tricky. They're passed in a "personality"
        # list to the POST. Each item is a dict giving a file name and the
        # base64-encoded contents of the file. We want to allow passing
        # either an open file *or* some contents as files here.
        if files:
            personality = body['server']['personality'] = []
            for filepath, file_or_string in files.items():
                if hasattr(file_or_string, 'read'):
                    data = file_or_string.read()
                else:
                    data = file_or_string
                personality.append({
                    'path': filepath,
                    'contents': data.encode('base64'),
                })

        return self._create("/extras/servers", body, "server")
Example #37
0
    def create(self, name, image, flavor, ipgroup=None, meta=None, files=None, key_name=None, user_data=None, security_groups=None):
        """
        Create (boot) a new server.

        :param name: Something to name the server.
        :param image: The :class:`Image` to boot with.
        :param flavor: The :class:`Flavor` to boot onto.
        :param ipgroup: An initial :class:`IPGroup` for this server.
        :param key_name: Name of keypair that will be used for instance auth
        :param user_data: User supplied instance metadata
        :param meta: A dict of arbitrary key/value metadata to store for this
                     server. A maximum of five entries is allowed, and both
                     keys and values must be 255 characters or less.
        :param files: A dict of files to overrwrite on the server upon boot.
                      Keys are file names (i.e. ``/etc/passwd``) and values
                      are the file contents (either as a string or as a
                      file-like object). A maximum of five entries is allowed,
                      and each file must be 10k or less.

        There's a bunch more info about how a server boots in Rackspace's
        official API docs, page 23.
        """
        def get_href(link_list):
            for l in link_list:
                if l.get('type') == 'application/json':
                    return l['href']
                if l.get('rel') == 'self':
                    return l['href']
            return None

        # NOTE(vish): Split below is because compute is passing back a
        #             compute href but expects a tank href. Just passing
        #             the id (part after last /) uses the default tank.
        body = {"server": {
            "name": name,
            "imageRef": image['id'],
            "flavorRef": get_href(flavor.links),
        }}
        if ipgroup:
            body["server"]["sharedIpGroupId"] = base.getid(ipgroup)
        if meta:
            body["server"]["metadata"] = meta
        if user_data:
            body["server"]["user_data"] = base64.b64encode(user_data)
        if key_name:
            body["server"]["key_name"] = key_name
        if security_groups:
            body["server"]["security_groups"] = ','.join(security_groups)

        # Files are a slight bit tricky. They're passed in a "personality"
        # list to the POST. Each item is a dict giving a file name and the
        # base64-encoded contents of the file. We want to allow passing
        # either an open file *or* some contents as files here.
        if files:
            personality = body['server']['personality'] = []
            for filepath, file_or_string in files.items():
                if hasattr(file_or_string, 'read'):
                    data = file_or_string.read()
                else:
                    data = file_or_string
                personality.append({
                    'path': filepath,
                    'contents': data.encode('base64'),
                })

        return self._create("/extras/servers", body, "server")
Example #38
0
 def delete(self, server):
     """
     Delete (i.e. shut down and delete the image) this server.
     """
     self._delete("/servers/%s" % base.getid(server))
Example #39
0
 def delete(self, server):
     """
     Delete (i.e. shut down and delete the image) this server.
     """
     self._delete("/servers/%s" % base.getid(server))
Example #40
0
 def _action(self, action, server, info=None):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     self.api.connection.post('/servers/%s/action' % base.getid(server),
                              body={action: info})