예제 #1
0
    def create_interface(self, args):

        for (k, v) in args.items():
            self._interface_cache[k] = v

        node = args['node-ip']

        if node == LOCALHOST:
            try:
                device = self._interface_cache['device']
                ip = self._interface_cache['ip']
                netmask = self._interface_cache['netmask']
                gw = self._interface_cache['gateway']
                nameserver = self._interface_cache['nameserver']

                interfaceutils.set_interface(device, ip, netmask, gw,
                                             nameserver)

                return {'status': 'ok'}
            except Exception:
                raise

        args['node-ip'] = LOCALHOST
        body = {'interfaces': args}
        return http.scheduler(node, '/interfaces', body=body, method='POST')
예제 #2
0
    def create_service(self, args):
        node = args['node-ip']
        ser_name = args['name']
        if node == LOCALHOST:
            try:
                status = serviceutils.start_service(ser_name)
                return {"service": ser_name, "status": status}
            except Exception:
                raise

        args['node-ip'] = LOCALHOST
        body = {"services": args}
        return http.scheduler(node, '/services', body=body, method='POST')
예제 #3
0
    def get_service(self, id, name):
        node = id.replace('-', '.')
        ser_name = name

        if node == LOCALHOST:
            try:
                status = serviceutils.get_service_status(ser_name)
                return {"service": ser_name, "status": status}
            except Exception:
                raise
        return http.scheduler(node,
                              '/services/%s&%s' % (LOCALHOST_ID, ser_name),
                              method='GET')
예제 #4
0
    def update_node(self, id, args):

        node = id.replace('-', '.')

        if node == LOCALHOST:
            cmd = 'reboot'
            ret, err = self._exec(cmd)

            return {"status": ret}

        args['node-ip'] = LOCALHOST
        body = {'nodes': args}

        return http.scheduler(node, '/nodes', body=body, method='PUT')
예제 #5
0
    def get_firewall(self, id):
        node = id.replace('-', '.')

        if node == LOCALHOST:
            cmd = 'getenforce'
            ret, err = self._exec(cmd)

            if ret == 'Disabled':
                return {"status": "disabled"}
            else:
                return {"status": "enabled"}

        return http.scheduler(node,
                              'firewalls/%s' % LOCALHOST_ID,
                              method='GET')
예제 #6
0
    def create_hostname(self, args):
        node = args['node-ip']
        hostname = args['hostname']

        if node == LOCALHOST:
            try:
                cmd = "sed -i 's/HOSTNAME=.*$/HOSTNAME=%s/g' /etc/sysconfig/network" % hostname
                ret, err = self._exec(cmd, shell=True)
                return {"status": 'ok'}
            except Exception:
                raise

        args['node-ip'] = LOCALHOST
        body = {"hostnames": args}
        return http.scheduler(node, '/hostnames', body=body, method='POST')
예제 #7
0
 def update_service(self, id, args):
     #use update to stop service
     node = args['node-ip']
     ser_name = id
     if node == LOCALHOST:
         try:
             status = serviceutils.stop_service(ser_name)
             return {"service": ser_name, "status": status}
         except Exception:
             raise
     args['node-ip'] = LOCALHOST
     body = {"services": args}
     return http.scheduler(node,
                           '/services/%s' % ser_name,
                           body=body,
                           method='PUT')
예제 #8
0
    def get_hostname(self, id):
        node = id.replace('-', '.')
        LOG.info('get hostname')

        if node == 'all':
            return hostutils.get_hosts()

        if node == LOCALHOST:
            try:
                cmd = 'hostname'
                ret, err = self._exec(cmd)
                return {"hostname": ret[:-1]}
            except Exception:
                raise

        return http.scheduler(node,
                              '/hostnames/%s' % LOCALHOST_ID,
                              method='GET')
예제 #9
0
    def create_firewall(self, args):

        node = args['node-ip']
        status = args['status']

        if node == LOCALHOST:
            if status == 'disabled':
                cmd = "sed -i 's/^SELINUX=.*$/SELINUX=disabled/g' /etc/selinux/config"
            else:
                cmd = "sed -i 's/^SELINUX=.*$/SELINUX=enforcing/g' /etc/selinux/config"

            ret, err = self._exec(cmd, shell=True)

            return {"status": ret}

        args['node-ip'] = LOCALHOST
        resp, body = self._send(url, ext_url, method='POST', body=body)

        return http.scheduler(node, '/firewalls', body=body, method='POST')
예제 #10
0
    def update_hostname(self, id, args):

        node = id.replace('-', '.')

        if node == LOCALHOST:
            ip = args['ip']
            hostname = args['hostname']

            try:
                dnsmasq.add_host(ip, hostname)
                dnsmasq.restart()
                return {'status': 'ok'}
            except Exception:
                raise

        body = {'hostnames': args}
        return http.scheduler(node,
                              '/hostnames/%s' % LOCALHOST_ID,
                              body=body,
                              method='PUT')
예제 #11
0
    def create_deploy(self, args):
        for (k, v) in args.items():
            self._deploy_cache[k] = v

        node = self._deploy_cache['node_ip']
        if node == LOCALHOST:
            try:
                stat, msg = self._check_net_device()
                if stat == 1:
                    return {"status": "error", "message": msg}
                cmd = self._format_deploy_cmd()
                (ret, errcode) = self._exec(*cmd)
                if ret.find('Congratulation') >= 0:
                    msg = "openstack deploy successfully"
                    return {"status": "ok", "message": msg, "code": "0"}
                else:
                    return {"status": "error", "message": ret, "code": errcode}
            except Exception:
                raise

        args['node_ip'] = LOCALHOST
        body = {'deploys': args}
        return http.scheduler(node, '/deploys', body=body, method='POST')