'Create the config file for haproxy.'

def create_config_file(self):

    try:
        username = pwd.getpwuid(int(self.user)).pw_name
    except (ValueError, KeyError):
        try:
            username = pwd.getpwnam(self.user).pw_name
        except KeyError:
            raise InvalidUserOrGroupException((_("Invalid    user/uid:    '%s'") % self.user))
    try:
        groupname = grp.getgrgid(int(self.group)).gr_name
    except (ValueError, KeyError):
        try:
            groupname = grp.getgrnam(self.group).gr_name
        except KeyError:
            raise InvalidUserOrGroupException((_("Invalid    group/gid:    '%s'") % self.group))
    cfg_info = {'port': self.port, 'unix_socket_path': self.unix_socket_path, 'user': username, 'group': groupname, 'pidfile': self.pidfile, 'log_level': self.log_level}
    if self.network_id:
        cfg_info['res_type'] = 'Network'
        cfg_info['res_id'] = self.network_id
    else:
        cfg_info['res_type'] = 'Router'
        cfg_info['res_id'] = self.router_id
    haproxy_cfg = (_HAPROXY_CONFIG_TEMPLATE % cfg_info)
    LOG.debug('haproxy_cfg    =    %s', haproxy_cfg)
    cfg_dir = self.get_config_path(self.state_path)
    self.cfg_path = os.path.join(cfg_dir, ('%s.conf' % cfg_info['res_id']))
    if (not os.path.exists(cfg_dir)):
        os.makedirs(cfg_dir)
    with open(self.cfg_path, 'w') as cfg_file:
        cfg_file.write(haproxy_cfg)
