Exemplo n.º 1
0
    def plan(self):
        """ what actions are needed? """

        if self.recursive:
            raise ProviderError(self, "recursive is not implemented yet")
        if FileTests.is_file(self.name):
            raise ProviderError(
                self,
                f"destination path ({self.name}) is a file, uncertain how to proceed"
            )

        exists = FileTests.exists(self.name)

        if self.absent:
            # removal actions?
            if not exists:
                return
            elif FileTests.is_directory(self.name):
                self.needs('rmdir')
        else:
            # creation?
            if not exists:
                self.needs('mkdir')

            # metadata?
            if self.owner and (self.recursive or not exists or
                               (FileTests.owner(self.name) != self.owner)):
                self.needs('chmod')
            elif self.group and (self.recursive or not exists or
                                 (FileTests.group(self.name) != self.group)):
                self.needs('chgrp')
            elif self.mode and (self.recursive or not exists or
                                (FileTests.mode(self.name) != self.mode)):
                self.needs('chmod')
Exemplo n.º 2
0
 def on_taken_actions(self, provider, actions_taken):
     if provider.skip_plan_stage():
         return
     taken = sorted([str(x) for x in provider.actions_taken])
     planned = sorted([str(x) for x in provider.actions_planned])
     if (taken != planned):
         raise ProviderError(
             provider, "actions taken (%s) do not equal planned (%s)" %
             (taken, planned))
Exemplo n.º 3
0
 def on_taken_actions(self, provider, actions_taken):
     if provider.skip_plan_stage():
         return
     taken = sorted([str(x) for x in provider.actions_taken])
     planned = sorted([str(x) for x in provider.actions_planned])
     if (taken != planned):
         err = ProviderError(
             provider, "actions taken (%s) do not equal planned (%s)" %
             (taken, planned))
         self.record_host_failure(Context().host(), err)
         raise err
Exemplo n.º 4
0
    def plan(self):
        """ what actions are needed? """

        exists = FileTests.exists(self.name)

        if FileTests.is_directory(self.name):
            raise ProviderError(self, f"Is a directory: {self.name}")

        # removal?
        if self.absent:
            if exists:
                self.needs("rm")
            return

        # content?
        if (self.from_content or self.from_template or self.from_file
                or self.from_url):
            if self.from_template:
                if self.should_replace_using_template():
                    self.needs('copy_template')
            elif self.from_file:
                if self.should_replace_using_file():
                    self.needs('copy_file')
            elif self.from_url:
                if self.should_replace_using_url():
                    self.needs('copy_url')
            elif self.from_content:
                if self.should_replace_using_content():
                    self.needs('copy_content')

        # metadata?
        if self.owner and (not exists
                           or not (FileTests.owner(self.name) == self.owner)):
            self.needs('chown')
        if self.group and (not exists
                           or not (FileTests.group(self.name) == self.group)):
            self.needs('chgrp')
        if self.mode and (not exists
                          or not (FileTests.mode(self.name) == self.mode)):
            self.needs('chmod')
Exemplo n.º 5
0
 def error(self, msg):
     raise ProviderError(msg=msg, provider=self)