def _write_openstack_ip(self): """ Write Openstack nova controller ips and cinder volume ips into DB. Openstack Ips: 10.239.82.xx 10.239.82.yy Just write Ip addr here. """ ip_list = self._cluster_info['openstack_ip'] if ip_list: try: # fake one user id and project id self._context.user_id = 32 * '1' self._context.project_id = 32 * '1' node_list = appnodes.create(self._context, ip_list, allow_duplicate=True) #LOG.debug('app nodes added %s' % node_list) for node in node_list: status = 'reachable' appnodes.update(self._context, node.id, status) except Exception as e: LOG.error('Failed to add app nodes with error %s' % e) return False return True
def create(self, req, body): """create app nodes.""" LOG.debug(_('Creating new app nodes %s'), body) if not self.is_valid_body(body, 'appnodes'): raise exc.HTTPBadRequest() context = req.environ['vsm.context'] ip_list = body['appnodes'] if not isinstance(ip_list, list): expl = _('Invalid Request body: should be a list of IP address.') raise webob.exc.HTTPBadRequest(explanation=expl) node_list = appnodes.create(context, ip_list) node_view = self._view_builder.index(node_list) for node in node_list: #LOG.info('Node %s, Node id: %s, Node ip: %s' % (node, node.id, node.ip)) #ssh = utils.SSHClient(ip='10.239.131.170', user='******', key_file=r'~/.ssh/id_rsa') #ssh = utils.SSHClient(node.ip, 'root', '~/.ssh/id_rsa') #ret = ssh.check_ssh(retries=1) #status = 'reachable' if ret else 'unreachable' status = 'reachable' appnodes.update(context, node.id, status) return node_view