Esempio n. 1
0
    create_input_assignments.main()
    assignments_md = os.path.join(wp_wiki_git_repo_path, "assignments.md")
    if wp_wiki_git_manage:
        if os.path.exists(wp_wiki_git_repo_path):
            try:
                repo = Repo(wp_wiki_git_repo_path)
            except InvalidGitRepositoryError:
                repo = Repo.init(wp_wiki_git_repo_path, bare=True)

            if repo.git.diff():
                repo.index.add(assignments_md)
                repo.index.commit(
                    "%s content update" % datetime.now().strftime("%a %b %d %T %Y")
                )
                repo.remotes.origin.push()

    try:
        racks_wiki.update_wiki(
            url="http://%s/xmlrpc.php" % wp_wiki,
            username=wp_username,
            password=wp_password,
            _page_title=wp_wiki_assignments_title,
            _page_id=wp_wiki_assignments_page_id,
            _markdown=assignments_md,
        )
    except ProtocolError as ex:
        logger.error(ex.errmsg)

    regenerate_vlans_wiki()
Esempio n. 2
0
    def POST(self, **data):
        # handle force

        force = data.get('force', False) == 'True'
        if 'force' in data:
            del data['force']

        _vlan = None
        if 'vlan' in data:
            _vlan = data.pop("vlan")
        # make sure post data passed in is ready to pass to mongo engine
        result, obj_data = self.model.prep_data(data)

        # Check if there were data validation errors
        if result:
            result = ['Data validation failed: %s' % ', '.join(result)]
            cherrypy.response.status = "400 Bad Request"
        else:
            # check if object already exists
            obj_name = data['name']
            obj = self._get_obj(obj_name)
            if obj and not force:
                result.append('%s %s already exists.' %
                              (self.name.capitalize(), obj_name))
                cherrypy.response.status = "409 Conflict"
            else:
                # Create/update Operation
                try:
                    # if force and found object do an update
                    if force and obj:
                        # TODO: DEFAULTS OVERWRITE EXISTING VALUES
                        obj.update(**obj_data)
                        result.append('Updated %s %s' % (self.name, obj_name))
                    # otherwise create it
                    else:
                        self.model(**obj_data).save()
                        cherrypy.response.status = "201 Resource Created"
                        result.append('Created %s %s' % (self.name, obj_name))
                    if self.name == "cloud":

                        if _vlan:
                            update_data = {}
                            vlan_obj = model.Vlan.objects(
                                vlan_id=_vlan).first()
                            update_data["cloud"] = self.model.objects(
                                name=data["name"]).first()
                            if "owner" in data:
                                update_data["owner"] = data["owner"]
                            if "ticket" in data:
                                update_data["ticket"] = data["ticket"]
                            if vlan_obj:
                                vlan_obj.update(**update_data)
                                regenerate_vlans_wiki()
                            else:
                                result.append(
                                    "WARN: No VLAN reference for that ID")

                        history_result, history_data = model.CloudHistory.prep_data(
                            data)
                        if history_result:
                            result.append('Data validation failed: %s' %
                                          ', '.join(history_result))
                            cherrypy.response.status = "400 Bad Request"
                        else:
                            model.CloudHistory(**history_data).save()
                except Exception as e:
                    # TODO: make sure when this is thrown the output
                    #       points back to here and gives the end user
                    #       enough information to fix the issue
                    cherrypy.response.status = "500 Internal Server Error"
                    result.append('Error: %s' % e)
        return json.dumps({'result': result})