Пример #1
0
    def create_resource(self, name, **kwargs):
        if self.is_live and self._need_creation:
            self.client = self.create_mgmt_client(ResourceManagementClient)
            parameters = {"location": self.location}
            expiry = datetime.datetime.utcnow() + self.delete_after_tag_timedelta
            parameters["tags"] = {"DeleteAfter": expiry.replace(microsecond=0).isoformat()}

            parameters["tags"]["BuildId"] = os.environ.get("BUILD_BUILDID", "local")
            parameters["tags"]["BuildJob"] = os.environ.get("AGENT_JOBNAME", "local")
            parameters["tags"]["BuildNumber"] = os.environ.get("BUILD_BUILDNUMBER", "local")
            parameters["tags"]["BuildReason"] = os.environ.get("BUILD_REASON", "local")
            try:
                logging.info(
                    "Attempting to create a Resource Group with name {} and parameters {}".format(name, parameters)
                )
                # Prefixing all RGs created here with 'rgpy-' for tracing purposes
                name = u"rgpy-" + name
                if len(name) > 90:
                    name = name[:90]
                self.resource = self.client.resource_groups.create_or_update(name, parameters)
            except Exception as ex:
                if "ReservedResourceName" in str(ex):
                    raise ReservedResourceNameError(name)
                raise
        else:
            self.resource = self.resource or FakeResource(
                name=name,
                id="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/" + name,
            )
        if name != self.moniker:
            self.test_class_instance.scrubber.register_name_pair(name, self.moniker)
        return {
            self.parameter_name: self.resource,
            self.parameter_name_for_location: self.location,
        }
 def create_resource(self, name, **kwargs):
     if self.is_live and self._need_creation:
         self.client = self.create_mgmt_client(ResourceManagementClient)
         try:
             self.resource = self.client.resource_groups.create_or_update(
                 name, {'location': self.location}
             )
         except Exception as ex:
             if "ReservedResourceName" in str(ex):
                 raise ReservedResourceNameError(name)
             raise
     else:
         self.resource = self.resource or FakeResource(
             name=name,
             id="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/"+name
         )
     if name != self.moniker:
         self.test_class_instance.scrubber.register_name_pair(
             name,
             self.moniker
         )
     return {
         self.parameter_name: self.resource,
         self.parameter_name_for_location: self.location,
     }
 def create_resource(self, name, **kwargs):
     if self.is_live and self._need_creation:
         self.client = self.create_mgmt_client(ResourceManagementClient)
         parameters = {"location": self.location}
         if self.delete_after_tag_timedelta:
             expiry = datetime.datetime.utcnow(
             ) + self.delete_after_tag_timedelta
             parameters["tags"] = {
                 "DeleteAfter": expiry.replace(microsecond=0).isoformat()
             }
         try:
             self.resource = self.client.resource_groups.create_or_update(
                 name, parameters)
         except Exception as ex:
             if "ReservedResourceName" in str(ex):
                 raise ReservedResourceNameError(name)
             raise
     else:
         self.resource = self.resource or FakeResource(
             name=name,
             id=
             "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/"
             + name,
         )
     if name != self.moniker:
         self.test_class_instance.scrubber.register_name_pair(
             name, self.moniker)
     return {
         self.parameter_name: self.resource,
         self.parameter_name_for_location: self.location,
     }