How To Programmatically Add Label to a Server

Overview

This article talks about labeling a server in Cloudbolt via Python Plug-in. The backend model for label is called CloudBoltTag.


Considerations

The example provided in this KBA can be configured as a server action or as a build item in a blueprint to programatically tag a server.


Procedure

def run(job, *args, **kwargs): 
  my_label = '{{my_server_label}}' 
  server = kwargs.get('server')
  label,_= CloudBoltTag.objects.get_or_create(name=my_label) 
  server.tags.add(label) 
  if server.tags.last().name == label.name: 
    return "SUCCESS", "server is labeled", "" 
  else: 
    return "FAILURE", "server is not labeled", ""



Additional information

https://docs.cloudbolt.io/articles/#!cloudbolt-latest-docs/resources-for-writing-plug-ins

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.