コード例 #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 OpenStack
        :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 openstack 1.1 api
            pass
コード例 #2
0
ファイル: servers.py プロジェクト: AllStruck/secret-robot
    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 OpenStack
        :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 openstack 1.1 api
            pass
コード例 #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")
コード例 #4
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 def share_ip(self, server, ipgroup, address, 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.
     :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``.
     """
     server = base.getid(server)
     ipgroup = base.getid(ipgroup)
     body = {'shareIp': {'sharedIpGroupId': ipgroup, 'configureServer': configure}}
     self._update("/servers/%s/ips/public/%s" % (server, address), body)
コード例 #5
0
    def delete(self, load_balancer):
        """
        Delete this load balancer.

        :param server: The :class:`LoadBalancer` (or its ID) to delete.
        """
        self._delete("/loadbalancers/%s" % base.getid(load_balancer))
コード例 #6
0
    def update(self, load_balancer, name=None, algorithm=None, protocol=None, port=None):
        """
        Update the name, algorithm, protocol or port of a load balancer.

        :param load_balancer: The :class:`LoadBalancer` (or its ID) to update.
        :param name: The new name for the load balancer. The name must be 128 
                     characters or less in length, and all UTF-8 characters are valid.
        :param algorithm: Algorithm that defines how traffic should be directed 
                          between back-end nodes.
        :param protocol: Protocol of the service which is being load balanced.
        :param port: Port number for the service you are load balancing.
        """

        if name is None and algorithm is None and protocol is None and port is None:
            return

        body = {"loadBalancer": {}}
        if name:
            body["loadBalancer"]["name"] = name
        if algorithm:
            body["loadBalancer"]["algorithm"] = algorithm
        if protocol:
            body["loadBalancer"]["protocol"] = protocol
        if port:
            body["loadBalancer"]["port"] = port
        self._update("/loadbalancers/%s" % base.getid(load_balancer), body)
コード例 #7
0
    def remove(self, node):
        """
        Remove the node from the load balancer.

        :param node: The :class:`Node` (or its ID) to remove.
        """
        self._delete("/loadbalancers/%s/nodes/%s" % (self.load_balancer.id, base.getid(node)))
コード例 #8
0
    def update(self, node, condition=None, node_type=None, weight=None):
        """
        Update the condition, type or weighting of the node.

        :param node: The :class:`Node` (or its ID) to update.
        :param condition: Condition for the node, which determines its role 
                          within the load balancer. See :class:`NodeCondition` 
                          for valid values.
        :param node_type: The type of node. See :class:`NodeType` for valid values. 
        :param weight: Weight of node. If the WEIGHTED_ROUND_ROBIN load balancer 
                       algorithm mode is selected, then the user should assign 
                       the relevant weight to the node using the weight 
                       attribute for the node. Must be an integer from 1 to 100.
        """
        if condition is None and node_type is None and weight is None:
            return

        body = {"node": {}}
        if condition:
            body["node"]["condition"] = condition
        if node_type:
            body["node"]["type"] = node_type
        if weight:
            body["node"]["weight"] = weight

        self._update("/loadbalancers/%s/nodes/%s" % (self.load_balancer.id, base.getid(node)), body)
コード例 #9
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))
コード例 #10
0
ファイル: ipgroups.py プロジェクト: AllStruck/secret-robot
 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))
コード例 #11
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 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")
コード例 #12
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)
コード例 #13
0
    def get(self, load_balancer):
        """
        Get a load balancer.

        :param load_balancer: ID of the :class:`LoadBalancer` to get.
        :rtype: :class:`LoadBalancer`
        """
        return self._get("/loadbalancers/%s" % base.getid(load_balancer), "loadBalancer")
コード例 #14
0
    def get(self, node):
        """
        Get a node from the load balancer.

        :param node: ID of the :class:`Node` to get.
        :rtype: :class:`Node`
        """
        return self._get("/loadbalancers/%s/nodes/%s" % (self.load_balancer.id, base.getid(node)), "node")
コード例 #15
0
ファイル: flavors.py プロジェクト: AllStruck/secret-robot
 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")
コード例 #16
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")
コード例 #17
0
ファイル: ipgroups.py プロジェクト: AllStruck/secret-robot
 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")
コード例 #18
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 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")
コード例 #19
0
ファイル: images.py プロジェクト: AllStruck/secret-robot
 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")
コード例 #20
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")
コード例 #21
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)
コード例 #22
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)})
コード例 #23
0
ファイル: images.py プロジェクト: rlr/openstack.compute
 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")
コード例 #24
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 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)})
コード例 #25
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")
コード例 #26
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
    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))
コード例 #27
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))
コード例 #28
0
ファイル: images.py プロジェクト: rlr/openstack.compute
 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")
コード例 #29
0
ファイル: images.py プロジェクト: rlr/openstack.compute
 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))
コード例 #30
0
ファイル: images.py プロジェクト: AllStruck/secret-robot
 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))
コード例 #31
0
ファイル: images.py プロジェクト: AllStruck/secret-robot
 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")
コード例 #32
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
コード例 #33
0
ファイル: ipgroups.py プロジェクト: AllStruck/secret-robot
 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")
コード例 #34
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
コード例 #35
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")
コード例 #36
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)})
コード例 #37
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
    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)})
コード例 #38
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.client.post('/servers/%s/backup_schedule' % s, body=body)
コード例 #39
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)
コード例 #40
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 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)
コード例 #41
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.client.post('/servers/%s/backup_schedule' % s, body=body)
コード例 #42
0
 def remove(self, virtual_ip):
     self._delete("/loadbalancers/%s/virtualips/%s" % (self.load_balancer.id, base.getid(virtual_ip)))
コード例 #43
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 def delete(self, server):
     """
     Delete (i.e. shut down and delete the image) this server.
     """
     self._delete("/servers/%s" % base.getid(server))
コード例 #44
0
ファイル: servers.py プロジェクト: rlr/openstack.compute
 def _action(self, action, server, info=None):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     self.api.client.post('/servers/%s/action' % base.getid(server), body={action: info})    
コード例 #45
0
 def delete(self, server):
     """
     Delete (i.e. shut down and delete the image) this server.
     """
     self._delete("/servers/%s" % base.getid(server))
コード例 #46
0
 def _action(self, action, server, info=None):
     """
     Perform a server "action" -- reboot/rebuild/resize/etc.
     """
     self.api.client.post('/servers/%s/action' % base.getid(server),
                          body={action: info})