openvz_conf.h 3.8 KB
Newer Older
1 2 3 4 5
/*
 * openvz_config.h: config information for OpenVZ VPSs
 *
 * Copyright (C) 2006, 2007 Binary Karma.
 * Copyright (C) 2006 Shuveb Hussain
6
 * Copyright (C) 2007 Anoop Joe Cyriac
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
22 23 24 25
 * Authors: 
 * Shuveb Hussain <shuveb@binarykarma.com>
 * Anoop Joe Cyriac <anoop@binarykarma.com>
 *
26 27 28 29 30 31 32
 */

#ifndef OPENVZ_CONF_H
#define OPENVZ_CONF_H

#include "openvz_driver.h"

33 34
enum { OPENVZ_WARN, OPENVZ_ERR };

35 36 37 38 39 40
#define OPENVZ_NAME_MAX 8
#define OPENVZ_TMPL_MAX 256
#define OPENVZ_UNAME_MAX    32
#define OPENVZ_IP_MAX   16
#define OPENVZ_HOSTNAME_MAX 256
#define OPENVZ_PROFILE_MAX  256
41 42 43 44 45
#define OPENVZ_MAX_ERROR_LEN	 1024
#define OPENVZ_MAX_XML_LEN	 4096
#define OPENVZ_MAX_QUOTA	 8
#define OPENVZ_MAX_XPathEval_LEN 256
#define OPENVZ_RSRV_VM_LIMIT 100
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

enum openvz_quota{
    VM_LEVEL = 0,
    USER_LEVEL = 1,
};

/* TODO Add more properties here */
struct vps_props {
   int kmemsize;    /* currently held */
   int kmemsize_m;  /* max held */
   int kmemsize_b;  /* barrier */
   int kmemsize_l;  /* limit */
   int kmemsize_f;  /* fail count */

};

struct openvz_fs_def {
    char tmpl[OPENVZ_TMPL_MAX];
    struct ovz_quota *quota;
};

struct ovz_ip {
    char ip[OPENVZ_IP_MAX];
    char netmask[OPENVZ_IP_MAX];
    struct ovz_ip *next;
};

struct ovz_ns {
    char ip[OPENVZ_IP_MAX];
    struct ovz_ns *next;
};

struct openvz_net_def {
    char hostname[OPENVZ_HOSTNAME_MAX];
    char def_gw[OPENVZ_IP_MAX];
    struct ovz_ip *ips;
    struct ovz_ns *ns;
};

struct openvz_vm_def {
    char name[OPENVZ_NAME_MAX];
87
    unsigned char uuid[VIR_UUID_BUFLEN];
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    char profile[OPENVZ_PROFILE_MAX];
    struct openvz_fs_def fs;
    struct openvz_net_def net;
};

struct ovz_quota {
    enum openvz_quota type;
    unsigned int size;
    char uname[OPENVZ_UNAME_MAX];
    struct ovz_quota *next;
};

struct openvz_vm {
    int vpsid;
    int status;
    struct openvz_vm_def *vmdef;
    struct openvz_vm *next;
};

107 108 109 110 111 112
static inline int
openvzIsActiveVM(struct openvz_vm *vm)
{
    return vm->vpsid != -1;
}

113
int openvz_readline(int fd, char *ptr, int maxlen);
114 115 116
struct openvz_vm *openvzFindVMByID(const struct openvz_driver *driver, int id); 
struct openvz_vm *openvzFindVMByUUID(const struct openvz_driver *driver, 
                                            const unsigned char *uuid);
117 118

struct openvz_vm *openvzFindVMByName(const struct openvz_driver *driver, const char *name);
119 120
struct openvz_vm_def *openvzParseVMDef(virConnectPtr conn, const char *xmlStr,
                                            const char *displayName);
121 122 123 124

struct openvz_vm *openvzAssignVMDef(virConnectPtr conn, struct openvz_driver *driver,
                                    struct openvz_vm_def *def);

125 126 127
struct openvz_vm *openvzGetVPSInfo(virConnectPtr conn);
void openvzGenerateUUID(unsigned char *uuid);
int openvzAssignUUIDs(void);
128 129 130 131
void openvzRemoveInactiveVM(struct openvz_driver *driver, struct openvz_vm *vm);
void openvzFreeDriver(struct openvz_driver *driver);
void openvzFreeVM(struct openvz_driver *driver, struct openvz_vm *vm, int checkCallee);
void openvzFreeVMDef(struct openvz_vm_def *def);
132
int strtoI(const char *str);
133
#endif /* OPENVZ_CONF_H */