コード例 #1
0
ファイル: servers.py プロジェクト: tpot/dwarf
    def reboot(self, server_id, hard=False):
        """
        Reboot a server
        """
        LOG.info('reboot(server_id=%s, hard=%s)', server_id, hard)

        server = DB.servers.show(id=server_id)

        _delete_ec2metadata_route(server['ip'], CONF.ec2_metadata_port)
        VIRT.delete_server(server)
        VIRT.boot_server(server)
        _add_ec2metadata_route(server['ip'], CONF.ec2_metadata_port)
コード例 #2
0
ファイル: servers.py プロジェクト: tpot/dwarf
    def boot(self, server):
        """
        Boot a new server
        """
        LOG.info('boot(server=%s)', server)

        name = server['name']
        image_id = server['imageRef']
        flavor_id = server['flavorRef']
        key_name = server.get('key_name', None)

        # Sanity checks, will throw exceptions if they fail
        IMAGES.exists(image_id)
        FLAVORS.exists(flavor_id)
        if key_name is not None:
            KEYPAIRS.exists(key_name)

        # Create a new server in the database
        server = DB.servers.create(name=name, image_id=image_id,
                                   flavor_id=flavor_id, key_name=key_name,
                                   status='BUILDING')
        server_id = server['id']

        # Generate some more server properties and update the database
        mac_address = _generate_mac()
        server = DB.servers.update(id=server_id, mac_address=mac_address)

        # Extend the server details
        server = self._extend(server)

        # Create the server directory
        basepath = os.path.join(CONF.instances_dir, server_id)
        os.makedirs(basepath)

        # Create the server disk images
        _create_disks(server)

        # Finally boot the server
        VIRT.boot_server(server)

        # Update the status of the server
        server = DB.servers.update(id=server_id, status='NETWORKING')

        # Start a task to wait for the server to get its DHCP IP address
        task.start(server_id, 2, 60/2, [True], self._wait_for_ip, server)

        return utils.sanitize(server, SERVERS_DETAIL)
コード例 #3
0
ファイル: servers.py プロジェクト: tpot/dwarf
    def delete(self, server_id):
        """
        Delete a server
        """
        LOG.info('delete(server_id=%s)', server_id)

        server = DB.servers.show(id=server_id)

        # Stop all running tasks associated with this server
        task.stop(server_id)

        # Delete the iptables route for the Ec2 metadata service
        _delete_ec2metadata_route(server['ip'], CONF.ec2_metadata_port)

        # Kill the running server
        VIRT.delete_server(server)

        # Purge all server files
        basepath = os.path.join(CONF.instances_dir, server_id)
        if os.path.exists(basepath):
            shutil.rmtree(basepath)

        # Delete the database entry
        DB.servers.delete(id=server['id'])