예제 #1
0
 def _get_element(self, name, value):
     if value is None:
         xml_elem = Element(name)
         xml_elem.add_attr("xsi:nil", "true")
         return xml_elem
     else:
         return Element(name, value)
예제 #2
0
 def auth(self, user, password, tenant):
     passwordCreds = Element("passwordCredentials", username=user, password=password)
     auth = Element("auth", tenantName=tenant)
     auth.append(passwordCreds)
     headers = {"Content-Type": "application/xml"}
     resp, body = self.post(self.auth_url, headers=headers, body=str(Document(auth)))
     return resp, body
예제 #3
0
 def set_image_metadata_item(self, image_id, key, meta):
     """Sets the value for a specific image metadata key."""
     for k, v in meta.items():
         post_body = Element("meta", key=key)
         post_body.append(Text(v))
     resp, body = self.put("images/%s/metadata/%s" % (str(image_id), key), str(Document(post_body)), self.headers)
     body = xml_to_json(etree.fromstring(body))
     return resp, body
예제 #4
0
 def create_network(self, name):
     uri = '%s/networks' % (self.uri_prefix)
     post_body = Element("network")
     p2 = Element("name", name)
     post_body.append(p2)
     resp, body = self.post(uri, str(Document(post_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #5
0
 def set_server_metadata_item(self, server_id, key, meta):
     doc = Document()
     for k, v in meta.items():
         meta_element = Element("meta", key=k)
         meta_element.append(Text(v))
         doc.append(meta_element)
     resp, body = self.put("servers/%s/metadata/%s" % (str(server_id), key), str(doc), self.headers)
     return resp, xml_to_json(etree.fromstring(body))
예제 #6
0
 def set_flavor_extra_spec(self, flavor_id, specs):
     """Sets extra Specs to the mentioned flavor."""
     extra_specs = Element("extra_specs")
     for key in specs.keys():
         extra_specs.add_attr(key, specs[key])
     resp, body = self.post("flavors/%s/flavor-extra-specs" % flavor_id, str(Document(extra_specs)), self.headers)
     body = xml_to_json(etree.fromstring(body))
     return resp, body
예제 #7
0
 def update_member(self, admin_state_up, member_id):
     uri = '%s/lb/members/%s' % (self.uri_prefix, str(member_id))
     put_body = Element("member")
     p2 = Element("admin_state_up", admin_state_up)
     put_body.append(p2)
     resp, body = self.put(uri, str(Document(put_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #8
0
 def update_port(self, port_id, name):
     uri = '%s/ports/%s' % (self.uri_prefix, str(port_id))
     port = Element("port")
     p2 = Element("name", name)
     port.append(p2)
     resp, body = self.put(uri, str(Document(port)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #9
0
 def update_network(self, net_id, name):
     uri = '%s/networks/%s' % (self.uri_prefix, str(net_id))
     network = Element("network")
     p2 = Element("name", name)
     network.append(p2)
     resp, body = self.put(uri, str(Document(network)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #10
0
 def update_router(self, router_id, **kwargs):
     uri = '%s/routers/%s' % (self.uri_prefix, router_id)
     router = Element("router")
     for element, content in kwargs.iteritems():
         router.append(Element(element, content))
     resp, body = self.put(uri, str(Document(router)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #11
0
 def update_pool(self, pool_id, new_name):
     uri = '%s/lb/pools/%s' % (self.uri_prefix, str(pool_id))
     put_body = Element("pool")
     p2 = Element("name", new_name)
     put_body.append(p2)
     resp, body = self.put(uri, str(Document(put_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #12
0
 def create_security_group(self, name):
     uri = '%s/security-groups' % (self.uri_prefix)
     post_body = Element("security_group")
     p2 = Element("name", name)
     post_body.append(p2)
     resp, body = self.post(uri, str(Document(post_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #13
0
 def update_health_monitor(self, admin_state_up, uuid):
     uri = '%s/lb/health_monitors/%s' % (self.uri_prefix, str(uuid))
     put_body = Element("health_monitor")
     p2 = Element("admin_state_up", admin_state_up)
     put_body.append(p2)
     resp, body = self.put(uri, str(Document(put_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #14
0
 def update_vip(self, vip_id, new_name):
     uri = '%s/lb/vips/%s' % (self.uri_prefix, str(vip_id))
     put_body = Element("vip")
     p2 = Element("name", new_name)
     put_body.append(p2)
     resp, body = self.put(uri, str(Document(put_body)), self.headers)
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #15
0
 def create_router(self, name, **kwargs):
     uri = '%s/routers' % (self.uri_prefix)
     router = Element("router")
     router.append(Element("name", name))
     deep_dict_to_xml(router, kwargs)
     resp, body = self.post(uri, str(Document(router)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #16
0
 def update_subnet(self, subnet_id, name):
     uri = '%s/subnets/%s' % (self.uri_prefix, str(subnet_id))
     subnet = Element("subnet")
     p2 = Element("name", name)
     subnet.append(p2)
     resp, body = self.put(uri, str(Document(subnet)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #17
0
 def disassociate_floating_ip_from_server(self, floating_ip, server_id):
     """Disassociate the provided floating IP from a specific server."""
     url = "servers/%s/action" % str(server_id)
     doc = Document()
     server = Element("removeFloatingIp")
     doc.append(server)
     server.add_attr("address", floating_ip)
     resp, body = self.post(url, str(doc), self.headers)
     return resp, body
예제 #18
0
 def update_snapshot_metadata_item(self, snapshot_id, id, meta_item):
     """Update metadata item for the snapshot."""
     for k, v in meta_item.items():
         put_body = Element('meta', key=k)
         put_body.append(Text(v))
     url = "snapshots/%s/metadata/%s" % (str(snapshot_id), str(id))
     resp, body = self.put(url, str(Document(put_body)), self.headers)
     body = xml_to_json(etree.fromstring(body))
     return resp, body
예제 #19
0
 def update_volume_metadata_item(self, volume_id, id, meta_item):
     """Update metadata item for the volume."""
     for k, v in meta_item.items():
         put_body = Element('meta', key=k)
         put_body.append(Text(v))
     url = "volumes/%s/metadata/%s" % (str(volume_id), str(id))
     resp, body = self.put(url, str(Document(put_body)))
     body = xml_to_json(etree.fromstring(body))
     return resp, body
예제 #20
0
 def auth(self, user, password, tenant):
     passwordCreds = Element("passwordCredentials",
                             username=user,
                             password=password)
     auth = Element("auth", tenantName=tenant)
     auth.append(passwordCreds)
     resp, body = self.post(self.auth_url, headers=self.headers,
                            body=str(Document(auth)))
     return resp, body['access']
예제 #21
0
 def serialize(self, body):
     #TODO(enikanorov): implement better json to xml conversion
     # expecting the dict with single key
     root = body.keys()[0]
     post_body = Element(root)
     for name, attr in body[root].items():
         elt = Element(name, attr)
         post_body.append(elt)
     return str(Document(post_body))
예제 #22
0
 def add_flavor_access(self, flavor_id, tenant_id):
     """Add flavor access for the specified tenant."""
     doc = Document()
     server = Element("add_tenant_access")
     doc.append(server)
     server.add_attr("tenant_id", tenant_id)
     resp, body = self.post("flavors/%s/action" % str(flavor_id), str(doc), self.headers)
     body = self._parse_array_access(etree.fromstring(body))
     return resp, body
예제 #23
0
 def update_agent(self, agent_id, agent_info):
     uri = '%s/agents/%s' % (self.uri_prefix, agent_id)
     agent = Element('agent')
     for (key, value) in agent_info.items():
         p = Element(key, value)
         agent.append(p)
     resp, body = self.put(uri, str(Document(agent)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #24
0
 def associate_floating_ip_to_server(self, floating_ip, server_id):
     """Associate the provided floating IP to a specific server."""
     url = "servers/%s/action" % str(server_id)
     doc = Document()
     server = Element("addFloatingIp")
     doc.append(server)
     server.add_attr("address", floating_ip)
     resp, body = self.post(url, str(doc))
     return resp, body
예제 #25
0
 def remove_flavor_access(self, flavor_id, tenant_id):
     """Remove flavor access from the specified tenant."""
     doc = Document()
     server = Element("removeTenantAccess")
     doc.append(server)
     server.add_attr("tenant", tenant_id)
     resp, body = self.post('flavors/%s/action' % str(flavor_id), str(doc))
     body = self._parse_array_access(etree.fromstring(body))
     return resp, body
예제 #26
0
    def create_user(self, name, password, tenant_id, email, **kwargs):
        """Create a user."""
        create_user = Element("user", xmlns=XMLNS, name=name, password=password, tenantId=tenant_id, email=email)
        if "enabled" in kwargs:
            create_user.add_attr("enabled", str(kwargs["enabled"]).lower())

        resp, body = self.post("users", str(Document(create_user)), self.headers)
        body = self._parse_body(etree.fromstring(body))
        return resp, body
예제 #27
0
 def create_floating_ip(self, ext_network_id, **kwargs):
     uri = '%s/floatingips' % (self.uri_prefix)
     floatingip = Element('floatingip')
     floatingip.append(Element("floating_network_id", ext_network_id))
     for element, content in kwargs.iteritems():
         floatingip.append(Element(element, content))
     resp, body = self.post(uri, str(Document(floatingip)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #28
0
 def associate_health_monitor_with_pool(self, health_monitor_id,
                                        pool_id):
     uri = '%s/lb/pools/%s/health_monitors' % (self.uri_prefix,
                                               pool_id)
     post_body = Element("health_monitor")
     p1 = Element("id", health_monitor_id,)
     post_body.append(p1)
     resp, body = self.post(uri, str(Document(post_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #29
0
 def create_volume_transfer(self, vol_id, name=None):
     """Create a volume transfer."""
     post_body = Element("transfer",
                         volume_id=vol_id)
     if name:
         post_body.add_attr('name', name)
     resp, body = self.post('os-volume-transfer',
                            str(Document(post_body)))
     volume = xml_to_json(etree.fromstring(body))
     return resp, volume
예제 #30
0
    def rebuild(self, server_id, image_ref, **kwargs):
        kwargs['imageRef'] = image_ref
        if 'disk_config' in kwargs:
            kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
            del kwargs['disk_config']
            kwargs['xmlns:OS-DCF'] = "http://docs.openstack.org/"\
                                     "compute/ext/disk_config/api/v1.1"
            kwargs['xmlns:atom'] = "http://www.w3.org/2005/Atom"
        if 'xmlns' not in kwargs:
            kwargs['xmlns'] = XMLNS_11

        attrs = kwargs.copy()
        if 'metadata' in attrs:
            del attrs['metadata']
        rebuild = Element("rebuild",
                          **attrs)

        if 'metadata' in kwargs:
            metadata = Element("metadata")
            rebuild.append(metadata)
            for k, v in kwargs['metadata'].items():
                meta = Element("meta", key=k)
                meta.append(Text(v))
                metadata.append(meta)

        resp, body = self.post('servers/%s/action' % server_id,
                               str(Document(rebuild)))
        server = self._parse_server(etree.fromstring(body))
        return resp, server
예제 #31
0
 def remove_security_group(self, server_id, security_group_name):
     secgrp = Element('removeSecurityGroup', name=security_group_name)
     return self.post('servers/%s/action' % server_id,
                      str(Document(secgrp)), self.headers)
예제 #32
0
 def create_flavor(self, name, ram, vcpus, disk, flavor_id, **kwargs):
     """Creates a new flavor or instance type."""
     flavor = Element("flavor",
                      xmlns=XMLNS_11,
                      ram=ram,
                      vcpus=vcpus,
                      disk=disk,
                      id=flavor_id,
                      name=name)
     if kwargs.get('rxtx'):
         flavor.add_attr('rxtx_factor', kwargs.get('rxtx'))
     if kwargs.get('swap'):
         flavor.add_attr('swap', kwargs.get('swap'))
     if kwargs.get('ephemeral'):
         flavor.add_attr('OS-FLV-EXT-DATA:ephemeral',
                         kwargs.get('ephemeral'))
     if kwargs.get('is_public'):
         flavor.add_attr('os-flavor-access:is_public',
                         kwargs.get('is_public'))
     flavor.add_attr('xmlns:OS-FLV-EXT-DATA', XMLNS_OS_FLV_EXT_DATA)
     flavor.add_attr('xmlns:os-flavor-access', XMLNS_OS_FLV_ACCESS)
     resp, body = self.post('flavors', str(Document(flavor)), self.headers)
     body = xml_to_json(etree.fromstring(body))
     flavor = self._format_flavor(body)
     return resp, flavor
예제 #33
0
    def create_security_group_rule(self, parent_group_id, ip_proto, from_port,
                                   to_port, **kwargs):
        """
        Creating a new security group rules.
        parent_group_id :ID of Security group
        ip_protocol : ip_proto (icmp, tcp, udp).
        from_port: Port at start of range.
        to_port  : Port at end of range.
        Following optional keyword arguments are accepted:
        cidr     : CIDR for address range.
        group_id : ID of the Source group
        """
        group_rule = Element("security_group_rule")
        parent_group = Element("parent_group_id")
        parent_group.append(Text(content=parent_group_id))
        ip_protocol = Element("ip_protocol")
        ip_protocol.append(Text(content=ip_proto))
        from_port_num = Element("from_port")
        from_port_num.append(Text(content=str(from_port)))
        to_port_num = Element("to_port")
        to_port_num.append(Text(content=str(to_port)))

        cidr = kwargs.get('cidr')
        if cidr is not None:
            cidr_num = Element("cidr")
            cidr_num.append(Text(content=cidr))

        group_id = kwargs.get('group_id')
        if group_id is not None:
            group_id_num = Element("group_id")
            group_id_num.append(Text(content=group_id))

        group_rule.append(parent_group)
        group_rule.append(ip_protocol)
        group_rule.append(from_port_num)
        group_rule.append(to_port_num)

        url = 'os-security-group-rules'
        resp, body = self.post(url, str(Document(group_rule)), self.headers)
        body = self._parse_body(etree.fromstring(body))
        return resp, body
예제 #34
0
 def create_role(self, name):
     """Create a Role."""
     post_body = Element("role", xmlns=XMLNS, name=name)
     resp, body = self.post('roles', str(Document(post_body)), self.headers)
     body = self._parse_body(etree.fromstring(body))
     return resp, body
예제 #35
0
 def set_metadata(self, aggregate_id, meta):
     """Replaces the aggregate's existing metadata with new metadata."""
     post_body = Element("set_metadata")
     metadata = Element("metadata")
     post_body.append(metadata)
     for k, v in meta.items():
         meta = Element(k)
         meta.append(Text(v))
         metadata.append(meta)
     resp, body = self.post('os-aggregates/%s/action' % aggregate_id,
                            str(Document(post_body)), self.headers)
     aggregate = self._format_aggregate(etree.fromstring(body))
     return resp, aggregate
예제 #36
0
    def rebuild(self, server_id, image_ref, name=None, meta=None,
                personality=None, adminPass=None, disk_config=None):
        rebuild = Element("rebuild",
                          xmlns=XMLNS_11,
                          imageRef=image_ref)

        if name:
            rebuild.add_attr("name", name)
        if adminPass:
            rebuild.add_attr("adminPass", adminPass)
        if meta:
            metadata = Element("metadata")
            rebuild.append(metadata)
            for k, v in meta.items():
                meta = Element("meta", key=k)
                meta.append(Text(v))
                metadata.append(meta)

        resp, body = self.post('servers/%s/action' % server_id,
                               str(Document(rebuild)), self.headers)
        server = self._parse_server(etree.fromstring(body))
        return resp, server
예제 #37
0
 def change_password(self, server_id, password):
     cpw = Element("changePassword",
                   xmlns=XMLNS_11,
                   adminPass=password)
     return self.post("servers/%s/action" % server_id,
                      str(Document(cpw)), self.headers)
예제 #38
0
    def create_keypair(self, name, pub_key=None):
        doc = Document()

        keypair_element = Element("keypair")

        if pub_key:
            public_key_element = Element("public_key")
            public_key_text = Text(pub_key)
            public_key_element.append(public_key_text)
            keypair_element.append(public_key_element)

        name_element = Element("name")
        name_text = Text(name)
        name_element.append(name_text)
        keypair_element.append(name_element)

        doc.append(keypair_element)

        resp, body = self.post("os-keypairs",
                               headers=self.headers, body=str(doc))
        body = xml_to_json(etree.fromstring(body))
        return resp, body
예제 #39
0
    def create_server(self, name, image_ref, flavor_ref, **kwargs):
        """
        Creates an instance of a server.
        name (Required): The name of the server.
        image_ref (Required): Reference to the image used to build the server.
        flavor_ref (Required): The flavor used to build the server.
        Following optional keyword arguments are accepted:
        adminPass: Sets the initial root password.
        key_name: Key name of keypair that was created earlier.
        meta: A dictionary of values to be used as metadata.
        personality: A list of dictionaries for files to be injected into
        the server.
        security_groups: A list of security group dicts.
        networks: A list of network dicts with UUID and fixed_ip.
        user_data: User data for instance.
        availability_zone: Availability zone in which to launch instance.
        accessIPv4: The IPv4 access address for the server.
        accessIPv6: The IPv6 access address for the server.
        min_count: Count of minimum number of instances to launch.
        max_count: Count of maximum number of instances to launch.
        disk_config: Determines if user or admin controls disk configuration.
        """
        server = Element("server",
                         xmlns=XMLNS_11,
                         imageRef=image_ref,
                         flavorRef=flavor_ref,
                         name=name)

        for attr in ["adminPass", "accessIPv4", "accessIPv6", "key_name",
                     "user_data", "availability_zone", "min_count",
                     "max_count", "return_reservation_id"]:
            if attr in kwargs:
                server.add_attr(attr, kwargs[attr])

        if 'disk_config' in kwargs:
            server.add_attr('xmlns:OS-DCF', "http://docs.openstack.org/"
                            "compute/ext/disk_config/api/v1.1")
            server.add_attr('OS-DCF:diskConfig', kwargs['disk_config'])

        if 'security_groups' in kwargs:
            secgroups = Element("security_groups")
            server.append(secgroups)
            for secgroup in kwargs['security_groups']:
                s = Element("security_group", name=secgroup['name'])
                secgroups.append(s)

        if 'networks' in kwargs:
            networks = Element("networks")
            server.append(networks)
            for network in kwargs['networks']:
                s = Element("network", uuid=network['uuid'],
                            fixed_ip=network['fixed_ip'])
                networks.append(s)

        if 'meta' in kwargs:
            metadata = Element("metadata")
            server.append(metadata)
            for k, v in kwargs['meta'].items():
                meta = Element("meta", key=k)
                meta.append(Text(v))
                metadata.append(meta)

        if 'personality' in kwargs:
            personality = Element('personality')
            server.append(personality)
            for k in kwargs['personality']:
                temp = Element('file', path=k['path'])
                temp.append(Text(k['contents']))
                personality.append(temp)

        resp, body = self.post('servers', str(Document(server)))
        server = self._parse_server(etree.fromstring(body))
        return resp, server
예제 #40
0
 def attach_volume(self, server_id, volume_id, device='/dev/vdz'):
     post_body = Element("volumeAttachment", volumeId=volume_id,
                         device=device)
     resp, body = self.post('servers/%s/os-volume_attachments' % server_id,
                            str(Document(post_body)))
     return resp, body
예제 #41
0
    def rebuild(self, server_id, image_ref, **kwargs):
        kwargs['imageRef'] = image_ref
        if 'disk_config' in kwargs:
            kwargs['OS-DCF:diskConfig'] = kwargs['disk_config']
            del kwargs['disk_config']
            kwargs['xmlns:OS-DCF'] = "http://docs.openstack.org/"\
                                     "compute/ext/disk_config/api/v1.1"
            kwargs['xmlns:atom'] = "http://www.w3.org/2005/Atom"
        if 'xmlns' not in kwargs:
            kwargs['xmlns'] = XMLNS_11

        attrs = kwargs.copy()
        if 'metadata' in attrs:
            del attrs['metadata']
        rebuild = Element("rebuild",
                          **attrs)

        if 'metadata' in kwargs:
            metadata = Element("metadata")
            rebuild.append(metadata)
            for k, v in kwargs['metadata'].items():
                meta = Element("meta", key=k)
                meta.append(Text(v))
                metadata.append(meta)

        resp, body = self.post('servers/%s/action' % server_id,
                               str(Document(rebuild)))
        server = self._parse_server(etree.fromstring(body))
        return resp, server
예제 #42
0
 def update_floating_ip(self, floating_ip_id, **kwargs):
     uri = '%s/floatingips/%s' % (self.uri_prefix, floating_ip_id)
     floatingip = Element('floatingip')
     floatingip.add_attr('xmlns:xsi',
                         'http://www.w3.org/2001/XMLSchema-instance')
     for element, content in kwargs.iteritems():
         if content is None:
             xml_elem = Element(element)
             xml_elem.add_attr("xsi:nil", "true")
             floatingip.append(xml_elem)
         else:
             floatingip.append(Element(element, content))
     resp, body = self.put(uri, str(Document(floatingip)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #43
0
    def create_volume(self, size, **kwargs):
        """Creates a new Volume.

        :param size: Size of volume in GB. (Required)
        :param display_name: Optional Volume Name.
        :param metadata: An optional dictionary of values for metadata.
        :param volume_type: Optional Name of volume_type for the volume
        :param snapshot_id: When specified the volume is created from
                            this snapshot
        :param imageRef: When specified the volume is created from this
                         image
        """
        # NOTE(afazekas): it should use a volume namespace
        volume = Element("volume", xmlns=XMLNS_11, size=size)

        if 'metadata' in kwargs:
            _metadata = Element('metadata')
            volume.append(_metadata)
            for key, value in kwargs['metadata'].items():
                meta = Element('meta')
                meta.add_attr('key', key)
                meta.append(Text(value))
                _metadata.append(meta)
            attr_to_add = kwargs.copy()
            del attr_to_add['metadata']
        else:
            attr_to_add = kwargs

        for key, value in attr_to_add.items():
            volume.add_attr(key, value)

        resp, body = self.post('volumes', str(Document(volume)), self.headers)
        body = xml_to_json(etree.fromstring(body))
        return resp, body
예제 #44
0
 def create_policy(self, blob, type):
     """Creates a Policy."""
     create_policy = Element("policy", xmlns=XMLNS, blob=blob, type=type)
     resp, body = self.post('policies', str(Document(create_policy)))
     body = self._parse_body(etree.fromstring(body))
     return resp, body
예제 #45
0
 def revert_resize(self, server_id):
     revert = Element('revertResize')
     return self.post('servers/%s/action' % server_id,
                      str(Document(revert)), self.headers)
예제 #46
0
    def update_server(self, server_id, name=None, meta=None, accessIPv4=None,
                      accessIPv6=None, disk_config=None):
        doc = Document()
        server = Element("server")
        doc.append(server)

        if name is not None:
            server.add_attr("name", name)
        if accessIPv4 is not None:
            server.add_attr("accessIPv4", accessIPv4)
        if accessIPv6 is not None:
            server.add_attr("accessIPv6", accessIPv6)
        if disk_config is not None:
            server.add_attr('xmlns:OS-DCF', "http://docs.openstack.org/"
                            "compute/ext/disk_config/api/v1.1")
            server.add_attr("OS-DCF:diskConfig", disk_config)
        if meta is not None:
            metadata = Element("metadata")
            server.append(metadata)
            for k, v in meta:
                meta = Element("meta", key=k)
                meta.append(Text(v))
                metadata.append(meta)

        resp, body = self.put('servers/%s' % str(server_id), str(doc))
        return resp, xml_to_json(etree.fromstring(body))
예제 #47
0
 def confirm_resize(self, server_id):
     conf = Element('confirmResize')
     return self.post('servers/%s/action' % server_id,
                      str(Document(conf)), self.headers)
예제 #48
0
    def update_quota_set(self, tenant_id, force=None,
                         injected_file_content_bytes=None,
                         metadata_items=None, ram=None, floating_ips=None,
                         fixed_ips=None, key_pairs=None, instances=None,
                         security_group_rules=None, injected_files=None,
                         cores=None, injected_file_path_bytes=None,
                         security_groups=None):
        """
        Updates the tenant's quota limits for one or more resources
        """
        post_body = Element("quota_set",
                            xmlns=XMLNS_11)

        if force is not None:
            post_body.add_attr('force', force)

        if injected_file_content_bytes is not None:
            post_body.add_attr('injected_file_content_bytes',
                               injected_file_content_bytes)

        if metadata_items is not None:
            post_body.add_attr('metadata_items', metadata_items)

        if ram is not None:
            post_body.add_attr('ram', ram)

        if floating_ips is not None:
            post_body.add_attr('floating_ips', floating_ips)

        if fixed_ips is not None:
            post_body.add_attr('fixed_ips', fixed_ips)

        if key_pairs is not None:
            post_body.add_attr('key_pairs', key_pairs)

        if instances is not None:
            post_body.add_attr('instances', instances)

        if security_group_rules is not None:
            post_body.add_attr('security_group_rules', security_group_rules)

        if injected_files is not None:
            post_body.add_attr('injected_files', injected_files)

        if cores is not None:
            post_body.add_attr('cores', cores)

        if injected_file_path_bytes is not None:
            post_body.add_attr('injected_file_path_bytes',
                               injected_file_path_bytes)

        if security_groups is not None:
            post_body.add_attr('security_groups', security_groups)

        resp, body = self.put('os-quota-sets/%s' % str(tenant_id),
                              str(Document(post_body)))
        body = xml_to_json(etree.fromstring(body))
        body = self._format_quota(body)
        return resp, body
예제 #49
0
 def reboot(self, server_id, reboot_type):
     reboot = Element("reboot",
                      xmlns=XMLNS_11,
                      type=reboot_type)
     return self.post("servers/%s/action" % server_id,
                      str(Document(reboot)), self.headers)
예제 #50
0
    def update_server(self,
                      server_id,
                      name=None,
                      meta=None,
                      accessIPv4=None,
                      accessIPv6=None):
        doc = Document()
        server = Element("server")
        doc.append(server)

        if name is not None:
            server.add_attr("name", name)
        if accessIPv4 is not None:
            server.add_attr("accessIPv4", accessIPv4)
        if accessIPv6 is not None:
            server.add_attr("accessIPv6", accessIPv6)
        if meta is not None:
            metadata = Element("metadata")
            server.append(metadata)
            for k, v in meta:
                meta = Element("meta", key=k)
                meta.append(Text(v))
                metadata.append(meta)

        resp, body = self.put('servers/%s' % str(server_id), str(doc),
                              self.headers)
        return resp, xml_to_json(etree.fromstring(body))
예제 #51
0
    def auth(self, user_id, password):
        user = Element('user', id=user_id, password=password)
        password = Element('password')
        password.append(user)

        method = Element('method')
        method.append(Text('password'))
        methods = Element('methods')
        methods.append(method)
        identity = Element('identity')
        identity.append(methods)
        identity.append(password)
        auth = Element('auth')
        auth.append(identity)
        headers = {'Content-Type': 'application/xml'}
        resp, body = self.post("auth/tokens",
                               headers=headers,
                               body=str(Document(auth)))
        return resp, body
예제 #52
0
    def create_image(self, server_id, name, meta=None):
        """Creates an image of the original server."""
        post_body = Element('createImage', name=name)

        if meta:
            metadata = Element('metadata')
            post_body.append(metadata)
            for k, v in meta.items():
                data = Element('meta', key=k)
                data.append(Text(v))
                metadata.append(data)
        resp, body = self.post('servers/%s/action' % str(server_id),
                               str(Document(post_body)))
        return resp, body
 def update_security_group(self,
                           security_group_id,
                           name=None,
                           description=None):
     """
     Update a security group.
     security_group_id: a security_group to update
     name: new name of security group
     description: new description of security group
     """
     security_group = Element("security_group")
     if name:
         sg_name = Element("name")
         sg_name.append(Text(content=name))
         security_group.append(sg_name)
     if description:
         des = Element("description")
         des.append(Text(content=description))
         security_group.append(des)
     resp, body = self.put('os-security-groups/%s' % str(security_group_id),
                           str(Document(security_group)), self.headers)
     body = self._parse_body(etree.fromstring(body))
     return resp, body
예제 #54
0
 def create_vip(self, name, protocol, protocol_port, subnet_id, pool_id):
     uri = '%s/lb/vips' % (self.uri_prefix)
     post_body = Element("vip")
     p1 = Element("name", name)
     p2 = Element("protocol", protocol)
     p3 = Element("protocol_port", protocol_port)
     p4 = Element("subnet_id", subnet_id)
     p5 = Element("pool_id", pool_id)
     post_body.append(p1)
     post_body.append(p2)
     post_body.append(p3)
     post_body.append(p4)
     post_body.append(p5)
     resp, body = self.post(uri, str(Document(post_body)))
     body = _root_tag_fetcher_and_xml_to_json_parse(body)
     return resp, body
예제 #55
0
    def update_endpoint(self,
                        endpoint_id,
                        service_id=None,
                        interface=None,
                        url=None,
                        region=None,
                        enabled=None):
        """Updates an endpoint with given parameters."""
        doc = Document()
        endpoint = Element("endpoint")
        doc.append(endpoint)

        if service_id:
            endpoint.add_attr("service_id", service_id)
        if interface:
            endpoint.add_attr("interface", interface)
        if url:
            endpoint.add_attr("url", url)
        if region:
            endpoint.add_attr("region", region)
        if enabled is not None:
            endpoint.add_attr("enabled", enabled)
        resp, body = self.patch('endpoints/%s' % str(endpoint_id), str(doc),
                                self.headers)
        body = self._parse_body(etree.fromstring(body))
        return resp, body
    def create_volume(self, size, display_name=None, metadata=None):
        """Creates a new Volume.

        :param size: Size of volume in GB. (Required)
        :param display_name: Optional Volume Name.
        :param metadata: An optional dictionary of values for metadata.
        """
        volume = Element("volume",
                         xmlns=XMLNS_11,
                         size=size)
        if display_name:
            volume.add_attr('display_name', display_name)

        if metadata:
            _metadata = Element('metadata')
            volume.append(_metadata)
            for key, value in metadata.items():
                meta = Element('meta')
                meta.add_attr('key', key)
                meta.append(Text(value))
                _metadata.append(meta)

        resp, body = self.post('os-volumes', str(Document(volume)),
                               self.headers)
        body = xml_to_json(etree.fromstring(body))
        return resp, body
예제 #57
0
 def _get_element(self, name, value):
     if value is None:
         xml_elem = Element(name)
         xml_elem.add_attr("xsi:nil", "true")
         return xml_elem
     elif isinstance(value, dict):
         dict_element = Element(name)
         for key, value in value.iteritems():
             elem = self._get_element(key, value)
             dict_element.append(elem)
         return dict_element
     elif isinstance(value, list):
         list_element = Element(name)
         for element in value:
             elem = self._get_element(name[:-1], element)
             list_element.append(elem)
         return list_element
     else:
         return Element(name, value)
예제 #58
0
    def create_volume_type(self, name, **kwargs):
        """
        Creates a new Volume_type.
        name(Required): Name of volume_type.
        Following optional keyword arguments are accepted:
        extra_specs: A dictionary of values to be used as extra_specs.
        """
        vol_type = Element("volume_type", xmlns=XMLNS_11)
        if name:
            vol_type.add_attr('name', name)

        extra_specs = kwargs.get('extra_specs')
        if extra_specs:
            _extra_specs = Element('extra_specs')
            vol_type.append(_extra_specs)
            for key, value in extra_specs.items():
                spec = Element('extra_spec')
                spec.add_attr('key', key)
                spec.append(Text(value))
                _extra_specs.append(spec)

        resp, body = self.post('types', str(Document(vol_type)),
                               self.headers)
        body = xml_to_json(etree.fromstring(body))
        return resp, body
예제 #59
0
 def create_interface(self,
                      server,
                      port_id=None,
                      network_id=None,
                      fixed_ip=None):
     doc = Document()
     iface = Element('interfaceAttachment')
     if port_id:
         _port_id = Element('port_id')
         _port_id.append(Text(port_id))
         iface.append(_port_id)
     if network_id:
         _network_id = Element('net_id')
         _network_id.append(Text(network_id))
         iface.append(_network_id)
     if fixed_ip:
         _fixed_ips = Element('fixed_ips')
         _fixed_ip = Element('fixed_ip')
         _ip_address = Element('ip_address')
         _ip_address.append(Text(fixed_ip))
         _fixed_ip.append(_ip_address)
         _fixed_ips.append(_fixed_ip)
         iface.append(_fixed_ips)
     doc.append(iface)
     resp, body = self.post('servers/%s/os-interface' % server,
                            headers=self.headers,
                            body=str(doc))
     body = self._process_xml_interface(etree.fromstring(body))
     return resp, body
예제 #60
0
    def create_volume_type_extra_specs(self, vol_type_id, extra_spec):
        """
        Creates a new Volume_type extra spec.
        vol_type_id: Id of volume_type.
        extra_specs: A dictionary of values to be used as extra_specs.
        """
        url = "types/%s/extra_specs" % str(vol_type_id)
        extra_specs = Element("extra_specs", xmlns=XMLNS_11)
        if extra_spec:
            if isinstance(extra_spec, list):
                extra_specs.append(extra_spec)
            else:
                for key, value in extra_spec.items():
                    spec = Element('extra_spec')
                    spec.add_attr('key', key)
                    spec.append(Text(value))
                    extra_specs.append(spec)
        else:
            extra_specs = None

        resp, body = self.post(url, str(Document(extra_specs)),
                               self.headers)
        body = xml_to_json(etree.fromstring(body))
        return resp, body