Puppet脚本可以判断它是否作为常规配置运行的一部分被调用,即Puppet代理定期应用配置(即puppet agent
),或者是因为一次性操作(例如{{1 },puppet agent -t
)?
答案 0 :(得分:0)
我在实践中还没有尝试过这个,但以下内容可能会有前进的方向:
command line上的设置(例如--test
)也可用作Puppet master variables(例如$settings::test
)。
Puppet主变量$servername
标识puppet agent
次运行的Puppet主变量,undef
puppet apply
运行$onetime = $settings::test or $settings::onetime or ($servername == undef)
。
因此,整体解决方案的配方可能如下所示:
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.calculator);
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
editText3.setText(prefs.getString("autoSave", ""));
editText4.setText(prefs.getString("autoSave1", ""));
editText6.setText(prefs.getString("autoSave2", ""));
editText8.setText(prefs.getString("autoSave3", ""));
editText3.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textViewResult.setText(addNumbers());
}
public void afterTextChanged(Editable s)
{
prefs.edit().putString("autoSave", s.toString()).commit();
}
});
editText4.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textViewResult.setText(addNumbers());
}
public void afterTextChanged(Editable s)
{
prefs.edit().putString("autoSave1", s.toString()).commit();
}
});
editText6.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textViewResult.setText(addNumbers());
}
public void afterTextChanged(Editable s)
{
prefs.edit().putString("autoSave2", s.toString()).commit();
}
});
editText8.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textViewResult.setText(addNumbers());
}
public void afterTextChanged(Editable s)
{
prefs.edit().putString("autoSave3", s.toString()).commit();
}
});
}
private String addNumbers() {
int number1;
int number2;
int number3;
int number4;
if (editText3.getText().toString() != "" && editText3.getText().length() > 0) {
number1 = Integer.parseInt(editText3.getText().toString());
} else {
number1 = 0;
}
if (editText4.getText().toString() != "" && editText4.getText().length() > 0) {
number2 = Integer.parseInt(editText4.getText().toString());
} else {
number2 = 0;
}
if (editText6.getText().toString() != "" && editText6.getText().length() > 0) {
number3 = Integer.parseInt(editText6.getText().toString());
} else {
number3 = 0;
}
if (editText8.getText().toString() != "" && editText8.getText().length() > 0) {
number4 = Integer.parseInt(editText8.getText().toString());
} else {
number4 = 0;
}
int sum = (number1 * 2) + (number2 * 4) + (number3 * 2) + (number4 * 2);
if (sum > 6) sum = 6;
return sum + "";
} }