

def create_node(self, **kwargs):
    '\n        Create a new OpenNebula node.\n\n        @inherits: :class:`NodeDriver.create_node`\n\n        :keyword networks: List of virtual networks to which this node should\n                           connect. (optional)\n        :type    networks: :class:`OpenNebulaNetwork` or\n            ``list`` of :class:`OpenNebulaNetwork`\n        '
    compute = ET.Element('COMPUTE')
    name = ET.SubElement(compute, 'NAME')
    name.text = kwargs['name']
    instance_type = ET.SubElement(compute, 'INSTANCE_TYPE')
    instance_type.text = kwargs['size'].name
    storage = ET.SubElement(compute, 'STORAGE')
    ET.SubElement(storage, 'DISK', {
        'image': ('%s' % str(kwargs['image'].id)),
    })
    if ('networks' in kwargs):
        if (not isinstance(kwargs['networks'], list)):
            kwargs['networks'] = [kwargs['networks']]
        networkGroup = ET.SubElement(compute, 'NETWORK')
        for network in kwargs['networks']:
            if network.address:
                ET.SubElement(networkGroup, 'NIC', {
                    'network': ('%s' % str(network.id)),
                    'ip': network.address,
                })
            else:
                ET.SubElement(networkGroup, 'NIC', {
                    'network': ('%s' % str(network.id)),
                })
    xml = ET.tostring(compute)
    node = self.connection.request('/compute', method='POST', data=xml).object
    return self._to_node(node)

dataset/ETHPy150Open apache/libcloud/libcloud/compute/drivers/opennebula.py OpenNebulaNodeDriver.create_node/original