Beispiel #1
0
    def execute(self):
        templates = self.args['<templates>']
        try:
            if not login_lib.check_env():
                print('you are not authorized.')
            else:
                login_lib.load_env_file()
                libs_dir = os.path.dirname(os.path.realpath(__file__))
                # os.chdir("{}/templates/{}".format(libs_dir,templates))
                template_file = "{}/templates/{}/index.yaml".format(
                    libs_dir, templates)
                template_env = "{}/templates/{}/env.yaml".format(
                    libs_dir, templates)
                heat_url = 'https://heat.wjv-1.neo.id:8004/v1/%s' % os.environ.get(
                    "OS_PROJECT_ID")

                # template = open(templates_index)
                env = open(template_env)
                files, template = template_utils.process_template_path(
                    template_file)

                heat = heat_client.Client('1',
                                          endpoint=heat_url,
                                          token=os.environ.get("OS_TOKEN"))

                heat.stacks.create(stack_name=templates,
                                   template=template,
                                   environment=env.read(),
                                   files=files)
        except Exception as e:
            print(e)
        else:
            pass
        finally:
            pass
Beispiel #2
0
 def execute(self):
     if self.args['ls']:
         if not login_lib.check_env():
             print('you are not authorized.')
         else:
             login_lib.load_env_file()
             heat_url = 'https://heat.wjv-1.neo.id:8004/v1/%s' % os.environ.get(
                 "OS_PROJECT_ID")
             heat = Client('1', endpoint=heat_url,
                           token=os.environ.get("OS_TOKEN"))
             instances = [instance for instance in heat.stacks.list()]
             for instance in instances:
                 print(" -> ({}) {}".format(instance.id, instance.name))
                 print(instance.to_dict())
             if len(instances) == 0:
                 print("There is no virtual machine;")
     if self.args['rm']:
         if not login_lib.check_env():
             print('you are not authorized.')
         else:
             try:
                 if self.args['<id_instance>'] == '-h':
                     subprocess.check_output(['neo vm', '--help'])
                 else:
                     login_lib.load_env_file()
                     heat_url = 'https://heat.wjv-1.neo.id:8004/v1/%s' % os.environ.get(
                         "OS_PROJECT_ID")
                     heat = Client('1', endpoint=heat_url,
                                   token=os.environ.get("OS_TOKEN"))
                     stack_id = self.args['<id_instance>']
                     heat.stacks.delete(stack_id)
             except Exception as e:
                 print(e)
             else:
                 pass
             finally:
                 pass
Beispiel #3
0
 def test_check_env(self, fs):
     home = os.path.expanduser("~")
     fs.create_file(f"{home}/.neo.env")
     assert login.check_env()
Beispiel #4
0
 def test_check_env(self, fs):
     home = os.path.expanduser("~")
     fs.create_file(os.path.join(home, ".neo", "config.toml"))
     assert login.check_env()
Beispiel #5
0
 def test_env_file(self):
     assert login.check_env() == True