Table of Contents
任何设备均可被salt托管
开发中的新特性
测试环境的准备
尝试运行!
可能的bug
聊聊Proxy Minion
Home Database Mysql Tutorial Saltstack 新特性测试之proxy minion

Saltstack 新特性测试之proxy minion

Jun 07, 2016 pm 04:37 PM
mini proxy saltstack new features characteristic

salt 目前主要的应用场景是Linux OS下,另外还有Windows Client(Win下没用过,但是看官方issue,应该……),最近关注到官方的一个小模块提到了Proxy minion,群里也多有提及,便想着看看到底是啥存在。 任何设备均可被salt托管 salt proxy minion的出现,

salt 目前主要的应用场景是Linux OS下,另外还有Windows Client(Win下没用过,但是看官方issue,应该……),最近关注到官方的一个小模块提到了Proxy minion,群里也多有提及,便想着看看到底是啥存在。

任何设备均可被salt托管

salt proxy minion的出现,使得网管设备或者哑设备(比如sms gateway)均可被salt统一管理,而实际的管理模块或通讯接口均由用户自行编写好,具体操作内容请参见salt 官网对应的 Proxy Minion 介绍

开发中的新特性

首先需要注意一点,Proxy minion是2014.1.x版本引进的新特性,并且到目前为止仍处于开发阶段,仅可用作测试用途。

测试环境的准备

本人的PC环境:

  • vbox下ubuntu 14.04 LTS Server
  • Salt master & minion 2014.1.7(配置test.ping通,不多说了)

准备好基础环境之后,需要从github下载salt官方开发人员用于测试Proxy Minion的一个小程序(Rest Server,模拟网管设备的管理接口),名字是 salt-proxy-rest。

这个程序可能依赖两个python库,bottle和requests(其实就是web server需要的组件……),安装一下即可。

使用 python rest.py 运行该程序,可以将此作为一个网管设备的Web管理接口:

alt

尝试运行!

至此,准备工作算是完成。在当前环境下,salt-master和salt-minion稳定运行,并且有一个提供REST接口的网管设备在独立工作,我们需要做的便是将其拉进Salt的阵营。

配置pillar

鄙人的minion id是docker,对应的pillar的top.sls内容配置为:

root@docker:/srv/pillar# cat top.sls
base:
  docker:
    - proxyminion
Copy after login

而proxyminion.sls内容则是对应网管设备的描述:

root@docker:/srv/pillar# cat proxyminion.sls 
proxy:
  rest_sample:
    proxytype: rest_sample
    url: http://127.0.0.1:8080/
    id: proxy_docker
Copy after login

这里需要注意的是,proxytype必须是在salt/proxy下已经预先定义好的,而其他的一些参数则是自己网管设备通信需要的一些数据,不一定相同。

定义好pillar数据之后,需要为之添加对应的proxy conn class和grains数据,这里鄙人使用官方sample,就偷个懒:

root@docker:/srv/pillar# cat /usr/lib/python2.7/dist-packages/salt/proxy/rest_sample.py
# -*- coding: utf-8 -*-
'''
This is a simple proxy-minion designed to connect to and communicate with
the bottle-based web service contained in salt/tests/rest.py.
Note this example needs the 'requests' library.
Requests is not a hard dependency for Salt
'''
……
Copy after login

放心,2014.1.7版本已经默认有这个sample代码。 接下来,直接test.ping试试吧!

root@docker:/srv/pillar# salt '*' test.ping -v
Executing job with jid 20140720110315049478
-------------------------------------------
docker:
    True
rest_sample-localhost:
    True
Copy after login

诶,等一下,为什么多出来个key?为什么还能test.ping通?没错!这个就是ProxyMinion,而salt默认已经配置了test.ping方法兼容proxy minion了,只要写好对应的ping模块,就可以使用常规的test.ping来探测!(本例的ping代码如下)

def ping(self):
    '''
    Is the REST server up?
    '''
    r = requests.get(self.url+'ping')
    try:
        if r.status_code == 200:
            return True
        else:
            return False
    except Exception:
        return False
Copy after login

rest_sample还提供很多function,比如鄙人测试的一个service_status,修改对应的模块代码即可使之兼容proxy minion(代码路径为/usr/lib/python2.7/dist-packages/salt/modules/service.py):

def status(name, sig=None):
    '''
    Return the status for a service, 
    returns the PID or an empty string if the
    service is running or not, pass a signature
    to use to find the service via ps
    CLI Example:
    .. code-block:: bash
    salt '*' service.status  [service signature]
    '''
    #wjx add, denote it to work!!
    #if 'proxyobject' in __opts__:
    #    return __opts['proxyobject'].service_status(sig if sig else name)
    return __salt__['status.pid'](sig if sig else name)
Copy after login

那么这时候再看看当前proxy minion管理的服务状态咋样了:

root@docker:/srv/pillar# salt '*' service.status apache
rest_sample-localhost:
    ----------
    comment:
        stopped
    ret:
        True
docker:
    False
Copy after login

完全和普通minion兼容!!rest_sample本身还配置了grain数据,代码位于/usr/lib/python2.7/dist-packages/salt/grains/rest_sample.py,直接敲命令看看:

root@docker:/srv/pillar# salt 'rest_sample-localhost' grains.items
rest_sample-localhost:
    housecat: Are you kidding?
    kernel: 0.0000001
    location: In this darn virtual machine.  Let me out!
    os: RestExampleOS
    os_family: proxy
Copy after login

Awesome!!这样一来,一个基本的salt proxy minion就算是配置完成,Proxy Minion 的类定义代码位于/usr/lib/python2.7/dist-packages/salt/minion.py,有兴趣可以看看。

可能的bug

鄙人在本机测试时,Minion Docker在尝试fork出一个ProxyMinion过程中间报错,说_running参数没有配置,在添加代码后通过(即位于minion.py代码里)

class ProxyMinion(Minion):
'''
This class instantiates a 'proxy' minion--a minion that does not manipulate
the host it runs on, but instead manipulates a device that cannot run a minion.
'''
def __init__(self, opts, timeout=60, safe=True):  # pylint: disable=W0231
    '''
    Pass in the options dict
    '''
    #wjx add, maybe a bug
    self._running = None
    # Warn if ZMQ 
<h4 id="聊聊Proxy-Minion">聊聊Proxy Minion</h4>
<p>Proxy minion使得salt针对网管设备的配置管理成为可能,不过想要实现一个ProxyType的ProxyMinion的完全管理,可能需要编写很多额外的module去支持它的运行。</p>
<p>在大公司复杂的网络环境下,完全可以针对此编写对应SNMP管理模块或者针对OVS编写对应的管理模块,尔后通过salt统一托管,毕竟Salt有一套完善的配置管理体系啊!</p>
    <p class="copyright">
        原文地址:Saltstack 新特性测试之proxy minion, 感谢原作者分享。
    </p>
    
    


Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Deployment strategy of containers and microservices under Nginx Proxy Manager Deployment strategy of containers and microservices under Nginx Proxy Manager Sep 27, 2023 pm 01:06 PM

The deployment strategy of containers and microservices under NginxProxyManager requires specific code examples. Summary: With the popularity of microservice architecture, containerization technology has become an important part of modern software development. In the microservice architecture, NginxProxyManager plays a very important role, used to manage and proxy the traffic of microservices. This article will introduce how to use NginxProxyManager to deploy and manage containerized microservices, and provide relevant code examples.

How to use Nginx Proxy Manager to achieve load balancing of multiple servers How to use Nginx Proxy Manager to achieve load balancing of multiple servers Sep 27, 2023 pm 09:42 PM

How to use NginxProxyManager to achieve load balancing of multiple servers. NginxProxyManager is a proxy server management tool developed based on Nginx. It provides a simple and easy-to-use Web interface that can easily configure and manage Nginx proxy servers. In practical applications, we often need to distribute requests to multiple servers to achieve load balancing and improve system performance and availability. This article will introduce how to use NginxProx

Nginx Proxy Manager Tutorial: Quick Start Guide Nginx Proxy Manager Tutorial: Quick Start Guide Sep 27, 2023 pm 05:39 PM

NginxProxyManager Tutorial: Quick Start Guide, Specific Code Examples Needed Introduction: With the development of network technology, proxy servers have become a part of our daily use of the Internet. NginxProxyManager is a proxy server management platform based on Nginx, which can help us quickly establish and manage proxy servers. This article will introduce you to the quick start guide of NginxProxyManager, as well as some specific code examples. one

Pocket386 ultra-portable laptop quietly released with Win95 compatibility and uncommon processor Pocket386 ultra-portable laptop quietly released with Win95 compatibility and uncommon processor Jun 24, 2024 am 06:46 AM

The key specs of the new laptop are likely to remind some of their school days. It has 8 MB of memory and a 7-inch IPS display that supports 640 x 480 (4:3) and 800 x 480 modes; lots of retro ports and a 386 SX-compatible Ali M6117 processor running

Master the key concepts of Spring MVC: Understand these important features Master the key concepts of Spring MVC: Understand these important features Dec 29, 2023 am 09:14 AM

Understand the key features of SpringMVC: To master these important concepts, specific code examples are required. SpringMVC is a Java-based web application development framework that helps developers build flexible and scalable structures through the Model-View-Controller (MVC) architectural pattern. web application. Understanding and mastering the key features of SpringMVC will enable us to develop and manage our web applications more efficiently. This article will introduce some important concepts of SpringMVC

DIY from getting started to giving up: wireless network card saves old motherboards DIY from getting started to giving up: wireless network card saves old motherboards Mar 14, 2024 pm 04:40 PM

Many motherboards come with built-in WiFi modules, but for many players, the extra 200 yuan is not cost-effective. In addition, some old motherboards do not have WiFi. If you want to enjoy convenient wireless Internet access, you need to use one. Wireless network card. Wireless network cards are very convenient to use, but please note that not all products are suitable for you. Below we will introduce 3 different wireless network cards. 1. "Portable Peter Pan" - USB wireless network card The first thing to bear the brunt is the "little hero" around us, the USB wireless network card. This lightweight and mini device is like a magic key. Just plug it in and connect it to the USB port of your computer to instantly activate your wireless network journey. USB wireless network cards are widely used for their affordable price and ultimate convenience.

8.4 Small tablets launched starting at 1099 8.4 Small tablets launched starting at 1099 Sep 01, 2024 pm 04:04 PM

Sound | Xiaobai Meizu has previously cooperated with Polestar to create the Polestar mobile phone "Polestar Phone". Not long ago, Lynk & Co also announced that it will cooperate with Meizu to customize the "Lynk & Co mobile phone". Meizu seems to have developed a business of cooperating with car companies to manufacture mobile phones. According to the latest news, it seems that Meizu will also OEM mobile phones for Hongqi. As you can see in the picture above, Meizu has recently launched a new 5G phone model M481R on the Internet. @Perfectly arranged digital broke the news and called the model a Hongqi phone. "It seems to be a matryoshka Meizu 21Pro." As a supplement, at the fifth China FAW Technology Conference in April this year, China FAW and Yikatong Technology signed a strategic cooperation agreement on smart cockpits. The two parties will launch a comprehensive strategic cooperation in the field of smart cockpits and jointly create a highly competitive

How to use Nginx Proxy Manager to quickly cache HTML pages How to use Nginx Proxy Manager to quickly cache HTML pages Sep 28, 2023 am 10:58 AM

How to use NginxProxyManager to achieve fast caching of HTML pages Introduction: In modern network applications, fast loading of web pages is an important requirement. In order to improve user experience, we can use NginxProxyManager to quickly cache HTML pages. This article will show you how to use NginxProxyManager to achieve this goal, and provide specific code examples. Part 1: Install and configure NginxProxy

See all articles