mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #271 from techhat/issue128
Adding set_tags, del_tags
This commit is contained in:
commit
9c8aa07285
@ -338,6 +338,25 @@ def start(name):
|
||||
log.error(exc)
|
||||
|
||||
|
||||
def set_tags(name, tags):
|
||||
'''
|
||||
Set tags for a node
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt-cloud -a set_tags mymachine tag1=somestuff tag2='Other stuff'
|
||||
'''
|
||||
conn = get_conn()
|
||||
node = get_node(conn, name)
|
||||
try:
|
||||
log.info('Setting tags for {0}'.format(name))
|
||||
data = conn.ex_create_tags(resource=node, tags=tags)
|
||||
get_tags(name)
|
||||
except Exception as exc:
|
||||
log.error('Failed to set tags for {0}'.format(name))
|
||||
log.error(exc)
|
||||
|
||||
|
||||
def get_tags(name):
|
||||
'''
|
||||
Retrieve tags for a node
|
||||
@ -345,10 +364,35 @@ def get_tags(name):
|
||||
conn = get_conn()
|
||||
node = get_node(conn, name)
|
||||
try:
|
||||
data = conn.ex_describe_tags(resource=node)
|
||||
log.info('Retrieving tags from {0}'.format(name))
|
||||
log.debug(data)
|
||||
data = conn.ex_describe_tags(resource=node)
|
||||
log.info(data)
|
||||
except Exception as exc:
|
||||
log.error('Failed to retrieve tags from {0}'.format(name))
|
||||
log.error(exc)
|
||||
|
||||
|
||||
def del_tags(name, kwargs):
|
||||
'''
|
||||
Delete tags for a node
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt-cloud -a del_tags mymachine tag1,tag2,tag3
|
||||
'''
|
||||
conn = get_conn()
|
||||
node = get_node(conn, name)
|
||||
current_tags = conn.ex_describe_tags(resource=node)
|
||||
|
||||
tags = {}
|
||||
for tag in kwargs['tags'].split(','):
|
||||
tags[tag] = current_tags[tag]
|
||||
|
||||
try:
|
||||
data = conn.ex_delete_tags(resource=node, tags=tags)
|
||||
log.info('Deleting tags from {0}'.format(name))
|
||||
get_tags(name)
|
||||
except Exception as exc:
|
||||
log.error('Failed to delete tags from {0}'.format(name))
|
||||
log.error(exc)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user